Tuesday, January 24, 2012

Know the dice, Be the dice

Today, I managed to get the program to recognize what numbers the dice have been rolled to. The screenshot below shows what I've accomplished. It doesn't look like much, but the numbers at the bottom of the screen are the values of the dice that have been rolled. Before, the program could only throw a few cubes around, but I was able to get the program to recognize that each side has a number, and to recognize when that side is face up. From here, I could easily add Yahtzee like scoring to it, but with the program as it is, I could only roll once and hope to get something good. Next, will be adding the functionality of picking dice and keeping those from being rolled in the next roll. From there, it should be simple to create a Yahtzee game. The code snippet below is the function that calculates the orientation of the die and appends a number to the diceValues list based on which face is pointing up.


diceValues = []
for d in self.winlist.keys():
            l, m, n = self.winlist[d]
            a = int(l+0.5)
            b = int(m+0.5)
            c = int(n+0.5)
            if b == 0 and c == -89:
               diceValues.append(1)
            elif b == 0 and c == 0:
               diceValues.append(2)
            elif b == 90:
               diceValues.append(3)
            elif b < -88:
               diceValues.append(4)
            elif b == 0 and c != 90:
               diceValues.append(5)
            elif b == 0 and c == 90:
               diceValues.append(6)

No comments:

Post a Comment