Skip to content

AdamRashid96/blackjack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dice

In this assignment we'll practice using OOP (Object Oriented Programming) techniques. We'll create a class to model what a single die has and does, and then we will create at least 9 instances of that class arranged in a grid shape. Note that for full credit your program must display the total of all the dice and draw the dice with dots or similar marks. Also, you must customize the title, header and footer of index.html. You may find these additional slides on OOP--Classes helpful, as well as the Nested Loops, Practice with classes and the Math.random worksheets.

Suggested steps to start the assignment

  1. Start by cloning your project.
  2. Open the pde file (located in the Dice directory of your project) and you should see the following code:
        void setup()
	{
	    noLoop();
	}
	void draw()
	{
	    //your code here
	}
	void mousePressed()
	{
	    redraw();
	}
	
	// Class Die, models one single role of a six sided die
	class Die 
	{
	    //variable declarations here
	    
	    Die(int x_pos, int y_pos) //constructor
	    {
	        //variable initializations here
	    }
	    void roll()
	    {
	        //your code here
	    }
	    void show()
	    {
	        //your code here, this will draw what you imagine a die to look like
	    }
	}
  1. Complete the draw() function first. For now it should:
    • clear the screen using background(0); //to whatever bgcolor you like
    • declare and initialize one instance of the Die class
    • Call the show() function for that Die (even though we won't see anything yet)
  2. Now lets work on the Die class.
    • First complete the show() function that displays the die to the screen. Notice that the constructor takes arguments. We'll use those arguments to position the individual die cubes. Don't worry about the dots at first, just get the shape of the dice on the screen for now. (Just draw one dot to represent a roll of 1 for now, the remaining 5 sides you figure out later)
    • Once you like the shape of your die, go back to show() and add some if statements to check how many dots you need to put on the die. Start by "forcing" the die to always roll a one. Check to see that you can get one dot where it is suppose to be, and move on to two, and so on. If you are clever, you can combine some of the ifs and avoid duplicate code.
  3. Now, use nested loops to display at least nine instances of the Die class. This is the power of OOP. It's not that much more work to make 1000 dice as it is to make one. Make sure the dots are on the dice. Your show() function will need to position the dots by adding some small amount to the x and y coordinates of the rect() of the Die
  4. Finally, add code to the draw() function so that your program displays the total for the roll to the screen.

Program requirements

The steps above are only a suggestion. Your program needs to:

  1. Use a class to model a single Die cube
  2. The Die constructor needs to use the two arguments to position the x and y coordinates of the Die cube
  3. Create at least 9 instances of the Die class
  4. Use Math.random() for all random numbers in the assignment
  5. Display the total of all the dice and draw the dice with dots or similar marks
  6. Personalize the title, header and footer of index.html

Other than that, your dice program doesn't have to work or look like any other. Have fun and be creative!

Optional Extras

For a challenge, you might see how many legible dice you can fit on the screen. You can also keep track of the rolls. You could display the average roll, or maybe a graph that shows how often each of the numbers from 2 to 12 have come up. This is useful in some dice games like Settlers of Catan. Check the links below for examples of other students work

Samples of Student Work

With Spread
Organic but structured layout Keep it simple Graduated Color, so pretty Best in show! Soooo many Beast mode Rainbow

Releases

No releases published

Packages

No packages published