Game Development Reference
In-Depth Information
const NUM_DICE = 5;
const NUM_SCORES = 13;
const NUM_ROLLS = 3;
Next is a group of variables that hold various CreateJS objects, and a list of EaselJS display objects that will make
up the main groups of game elements (see Listing 7-4).
Listing 7-4. First Set of Variables in fakezee.js, Used to Hold the CreateJS objects for the Game
// createjs
var canvas, stage, queue, spritesheet;
// display objects
var title, diceTray, scoreboard, scoreCard;
Lastly, a few groups of variables are set with initial values (see Listing 7-5).
Listing 7-5. Arrays for Building Scorecard Buttons and Variables for Storing Game Progress
// scorecard buttons
var scorecardButtons = ['ones', 'twos', 'threes', 'fours', 'fives', 'sixes', 'threeKind',
'fourKind', 'small', 'large', 'fullHouse', 'chance'];
var scorecardButtonKeys = [1, 2, 3, 4, 5, 6, 2, 3, 3, 4, 0, 0];
// game values to reset
var section1Score = 0;
var section2Score = 0;
var bonusScore = 0;
var totalScore = 0;
var rollsLeft = 3;
var numScored = 0;
var diceValues = [];
var scoredFakezee = false;
The first group of variables is used to build the category buttons in the scorecard. These buttons will be used
when the player is ready to submit the score after their turn is complete. The scorecardButtons array is used for the
loop when creating the buttons. These values are the strings used to name each button and they are needed in a few
scenarios. Each string dictates what animation to use from the sprite sheet, and is also used to decide how to evaluate
the dice when calculating the category's score.
The scorecardButtonKeys array holds numbers that will be injected into each button and is used to further help
the score calculating process. For example, a single function is used to score all of the categories, ones through sixes.
This value is used to decide what dice values should be added to the score returned. This process will be covered in
much more depth in the “Calculating the Scores” section.
The last series of values are the set of game variables that will be adjusted as the game is played. This is also the
set of values that needs to be reset when restarting the game. These values include scores, how many rolls the player
has left during their turn, the number of scores taken all together, and the value of each die after every roll. The last
variable, scoredFakezee , is used to determine bonus Fakezee points.
When the body is loaded, the init function is called, which sets up the stage.
 
Search WWH ::




Custom Search