mardi 3 janvier 2023

Roll Dice And Play [closed]

  1. Write a model class that represents a die (that is, a cube whose sides are numbered 1 to 6). The class will likely have just one method, throw(), and no attributes. (Hint: use Math.random to write throw.) Then, write an output-view class that displays a die after it has been thrown. Finally, write a controller that lets a user throw two dice repeatedly.
  2. Use the class from the previous exercise to build a game called “draw the house.” The objective is to throw a die repeatedly, and based on the outcome, draw parts of a house. A throw of 6 lets one draw the building, a square; a throw of 5 lets one draw the roof; a throw of 4 lets one draw the door; and a throw of 3 lets one draw a window. (There are two windows.) The finished house looks something like this: /
    / \

| _ | |x| |x|

Of course, the building must be drawn before the roof, and the roof must be drawn before the doors and windows. In addition to the class that represents the die, write a model class that represents the state of a partially built house. Then, write an output view that displays the house, and write a controller that enforces the rules of the game. 8. Make a version of the game in the previous Project that lets two players compete at building their respective houses.

Of course, the building must be drawn before the roof, and the roof must be drawn before the doors and windows. In addition to the class that represents the die, write a model class that represents the state of a partially built house. Then, write an output view that displays the house, and write a controller that enforces the rules of the game.




Aucun commentaire:

Enregistrer un commentaire