Computer Science 111 Fall 2006, Lab #9 = Hw9
November 16, 2006, Due Tuesday November 21, midnight

The purpose of today's lab is to gain more experience with classes, objects and graphics and to have a little fun.
  1. Boot your machine into Linux.
  2. Get the dice-rolling code
    We will modify the dice rolling code that we went over in class today.
    Start by getting copies of the three Python files:
    getcopy roller.py
    getcopy dieview.py
    getcopy button.py
    In python, import roller, and run roller.main(). It will produce an initial window like this:
    After you click on the roll button, you'll see something like this:
  3. Take a look at a working version to see what to do:
    getcopy rollerYahtzee.pyc
  4. Modify the code so as to roll dice for a yahtzee game. You will only need to modify the file roller.py
    To get started:
    1. Create 5 dice in a row instead of two and set them to random values. This involves
      • Using 5 variables instead of 2 in roller.main, creating 5 instances of dieview and setting tbe x coordinates of each Point in the 5 dice.
      • Making the window bigger (look at the GraphWin Constructor specification on page 151)
      • Do these things first and get the dice to look nice before going on to the rolling stage.
        Here's how mine looks:

        Important Note: The first roll is done for you. In other words the dice come out with different, random values on them. This is a little different than the roller example where they all started at 1. You'll have to call the right button method to do this, after you have created them of course, but before the while loop.

    2. Now create five separate buttons, one for each die. Once one of these buttons is clicked and changes the face of a die, it cannot be clicked again to change a die unless the large choose roll button has been clicked, and there is another roll to be done.
    3. Logic is important in this program.
      1. I used five separate variables to keep track of whether each die button had been clicked or not. Use your Boolean types here.
      2. I also use two more variables to keep track of which roll I am on. Again, I use Boolean types here, True or False.
    4. Construct a while loop. Here's how mine looks:
          pt = win.getMouse()
      
          while not (roll1 and roll2):   # if both are True, condition is False
      
      The program gets the next mouseclick, and processes it, as long as roll1 and roll2 are not both True. The body of the while loop is a big if-elif-else statement.

    This homework is due Tuesday Nov 21 at midnight.

    After putting the documentation in (at the top and throughout), submit it by typing
    submit homework9 roller.py