My first step is breaking down the game into pieces. I need to have pictures of each die face (I have actually already created this in Flash). I need to have a way to reference each die face separately. I need to have a way to generate a random number, and then assign that random number to its corresponding die face. Once the die face is chosen, I need to display it to the player. I need to create a button for the player to click in order to roll the die, and I need to program the button to connect it to the code generating the random number. I need to have two dice in order to create the final craps game, so whatever code I create to roll one die, I will just repeat. The button will have to somehow initiate the code for both die rolls.
So here are my first tasks:
- Create graphical elements (die faces, buttons).
- Assign variables for two random numbers.
- Create function to generate random numbers and assign to their respective die faces.
- Create an event listener for the button that rolls the dice.
The tasks above will set up the basic die-rolling part of the game. But I need to do a bit more to create the actual Craps game. I need to check if it’s the player’s first turn. I need to check whether the first number rolled equals 7 or 11, and if it does I need to let the player know they won. If the first number rolled is not 7 or 11, I need to check whether the first number rolled equals 2, 3, or 12, and if it equals any of those I need to let the player know they lost. If the first number rolled is not 2, 3, 7, 11, or 12, I need to store the first number in a variable. On each subsequent turn, I need to check the number rolled on that turn against 7 and 11 (lose) and against the first number rolled (win), and I need to let the player know the result of their roll.
So here are the additional tasks for the full Craps game:
- Create output fields to display messages to the player.
- Create a Boolean variable for First Turn.
- Create an if statement to check the first number; it should give the player either a win message, a lose message, or tell them their “point” (the first number they rolled). This should also set the First Turn variable to False.
- Create an if statement to check subsequent rolls against 7, 11, and their point, and give them a win message, a lose message, or keep rolling message.
- Create a function to end the game when a win or lose condition has been reached.
- Create a button to restart the game, along with event handler for the button.
Now, all I have to do is actually build the game in Flash! I’ll be building it in stages, and I’ll post each stage here as it is finished.