Commit 028b7eec authored by Terence Martin's avatar Terence Martin

Include generation option to use half balls

When this is enabled, only every other ball is generated into the top
of the maze, instead of a ball in every column. This makes for an
extra short game.
parent f887e42e
......@@ -21,6 +21,12 @@ var nurdz;
* applied at the end of the round when the final balls are removed.
*/
game.BALL_POSITION_MULTIPLIER = 2;
/**
* True if we should generate a level with only half of the normal number
* of balls. This will only generate a ball into the even numbered columns
* in the maze. This makes for a shorter game.
*/
game.halfBalls = false;
/**
* The number of points the human player has.
*/
......@@ -1136,8 +1142,11 @@ var nurdz;
* Currently this fill up the top row with balls for the player only,
* but it should also store balls for the computer into another data
* structure.
*
* @param {boolean} halfBalls true if we should generate half of the
* usual number of balls, to make for a shorter game.
*/
MazeGenerator.prototype.placeBalls = function () {
MazeGenerator.prototype.placeBalls = function (halfBalls) {
// Get the arrays that store the player and comptuer balls from
// the contents object.
var playerBalls = this._contents.playerBalls;
......@@ -1148,6 +1157,10 @@ var nurdz;
// This always works because the ball pool always has exactly enough
// balls for our purposes.
for (var ballIndex = 0; ballIndex < game.MAZE_WIDTH - 2; ballIndex++) {
// If we are rendering half balls and this is not an even numbered
// column, skip it.
if (halfBalls && ballIndex % 2 != 0)
continue;
// Get the balls from the pool
playerBalls[ballIndex] = this._maze.getBall();
computerBalls[ballIndex] = this._maze.getBall();
......@@ -1173,10 +1186,10 @@ var nurdz;
* us, but does not take care to reap any objects in the pools first;
* that is up to the caller.
*
* @param includeAutomatic true if arrows can be generated as
* automatically flipping, or false otherwise.
* @param {boolean} halfBalls true if half the usual number of balls should be generated per player
* @param {boolean} includeAutomatic true if arrows should be generated as automatically flipping
*/
MazeGenerator.prototype.generate = function (includeAutomatic) {
MazeGenerator.prototype.generate = function (halfBalls, includeAutomatic) {
// Empty the maze of all of its contents.
this.emptyMaze();
// Now generate the contents of the maze.
......@@ -1185,7 +1198,7 @@ var nurdz;
this.genGrayBricks();
this.genBonusBricks();
// Now we can place the balls in.
this.placeBalls();
this.placeBalls(halfBalls);
};
return MazeGenerator;
}());
......@@ -4780,7 +4793,7 @@ var nurdz;
this._ballMoveFinalized = false;
this._droppingFinalBall = false;
// Now generate the contents of the maze.
this._generator.generate(true);
this._generator.generate(game.halfBalls, true);
// Reset the scores
game.resetScores();
// If there is a listener, tell it now that the generation has
......
......@@ -17,6 +17,13 @@ module nurdz.game
*/
export const BALL_POSITION_MULTIPLIER = 2;
/**
* True if we should generate a level with only half of the normal number
* of balls. This will only generate a ball into the even numbered columns
* in the maze. This makes for a shorter game.
*/
export let halfBalls : boolean = false;
/**
* The number of points the human player has.
*/
......
......@@ -471,8 +471,11 @@ module nurdz.game
* Currently this fill up the top row with balls for the player only,
* but it should also store balls for the computer into another data
* structure.
*
* @param {boolean} halfBalls true if we should generate half of the
* usual number of balls, to make for a shorter game.
*/
private placeBalls () : void
private placeBalls (halfBalls : boolean) : void
{
// Get the arrays that store the player and comptuer balls from
// the contents object.
......@@ -486,6 +489,11 @@ module nurdz.game
// balls for our purposes.
for (let ballIndex = 0 ; ballIndex < MAZE_WIDTH - 2 ; ballIndex++)
{
// If we are rendering half balls and this is not an even numbered
// column, skip it.
if (halfBalls && ballIndex % 2 != 0)
continue;
// Get the balls from the pool
playerBalls[ballIndex] = this._maze.getBall ();
computerBalls[ballIndex] = this._maze.getBall ();
......@@ -515,10 +523,10 @@ module nurdz.game
* us, but does not take care to reap any objects in the pools first;
* that is up to the caller.
*
* @param includeAutomatic true if arrows can be generated as
* automatically flipping, or false otherwise.
* @param {boolean} halfBalls true if half the usual number of balls should be generated per player
* @param {boolean} includeAutomatic true if arrows should be generated as automatically flipping
*/
generate (includeAutomatic : boolean) : void
generate (halfBalls : boolean, includeAutomatic : boolean) : void
{
// Empty the maze of all of its contents.
this.emptyMaze ();
......@@ -530,7 +538,7 @@ module nurdz.game
this.genBonusBricks ();
// Now we can place the balls in.
this.placeBalls ();
this.placeBalls (halfBalls);
}
}
}
\ No newline at end of file
......@@ -1254,7 +1254,7 @@ module nurdz.game
this._droppingFinalBall = false;
// Now generate the contents of the maze.
this._generator.generate (true);
this._generator.generate (halfBalls, true);
// Reset the scores
resetScores ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment