Computer Science 111 Spring 2012, Lab #9 = Hw9
April 18-19, 2010, Due 11:59 p.m. Monday April 23

The purpose of today's lab and homework is to gain more experience with classes, objects, graphics and programming logic and to have a little fun.
  1. Boot your machine into the local Mac OSX operating system.
  2. Get the dice-rolling code
    We will modify the dice rolling code that we went over in class.
    Start by getting copies of the three Python files into your Desktop/CSC111 directory:
    roller.py
    dieview.py
    button.py
    Note: These files are also in the handout directory for the class accounts via getcopy.
    Run the python interpreter, then directly 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. Now we will work on the larger task, which is to implement the dice rolling part of the game yahtzee. In this part, we'll just take a look at a working version and then read about what to do:
    rollerYahtzee.pyc
  4. Modify the code so as to roll dice for a yahtzee game.
    You need all three files (button.py, dieview.py, and roller.py), but 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 correct 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. You may think of a better way to do it. 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, with values of True or False.
    4. Construct a while loop. Here's how mine looks:
          pt = win.getMouse()     # get the next mouseclick
              # statements in here will process the results of the mouseclick
          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 by 11:59 pm Monday April 23.

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