GithubHelp home page GithubHelp logo

axu11 / dice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apcslowell/dice

0.0 1.0 0.0 173 KB

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 two or more instances of that class.

Processing 0.39% HTML 0.12% JavaScript 98.89% CSS 0.07% Java 0.54%

dice's Introduction

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 the PowerPoint sides 177 to 223 of the apjava1.pptx presentation helpful.

Start by forking this repository. Open the pde file and you should see the following code:

void setup()
{
    noLoop();
}
void draw()
{
    //your code here
}
void mousePressed()
{
    redraw();
}
class Die //models one single dice cube
{
    //variable declarations here
    Die(int x, int y) //constructor
    {
        //variable initializations here
    }
    void roll()
    {
        //your code here
    }
    void show()
    {
        //your code here
    }
}
  1. Complete the draw() function first. For now it should:
  • clear the screen
  • declare and initialize one instance of the Die class
  • Call the show() function for that Die (even though we won't see anything yet)
  1. Now complete the Die class. You will need to 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. Once you like the shape of your die, go back to show() and add some ifs 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.
  2. 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
  3. Finally, add code to the draw() function so that your program displays the total for the roll to the screen.

Have fun and be creative. Your dice program doesn't have to look or work like any other.

Optional Extras

If you have extra time, you can 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

Christine
Jingbin
Erika
Lucy
Gigi
Vivian

dice's People

Contributors

simart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.