Commit b9fdd5b2 authored by Terence Martin's avatar Terence Martin

Include values for tracking rounds

This introduces a current round and maximum round to the game state,
along with methods for resetting the game to a new start for a given
number of levels, advancing levels, and seeing if it is the end of the
game or not.

This works such that a maximum level count of 0 or smaller counts as a
single round game played with half balls. Any game that is more than a
single round will report the last round condition when it's the last
round, which can be used to turn on the automatic arrows in maze
generation.
parent 028b7eec
......@@ -27,6 +27,16 @@ var nurdz;
* in the maze. This makes for a shorter game.
*/
game.halfBalls = false;
/**
* The current round number in the game. This advances every time the last
* ball is dropped at the end of a round.
*/
game.currentRound = 1;
/**
* The maximum number of rounds in the game. Once the current round exceeds
* this value, the game is officially over.
*/
game.maxRounds = 1;
/**
* The number of points the human player has.
*/
......@@ -35,6 +45,61 @@ var nurdz;
* The number of poitns the computer player has.
*/
var computerScore = 0;
/**
* Set up a new game to be played over the given number of total rounds. A
* value of 0 or smaller means that we will be playing only a single round,
* but with half balls.
*
* This will set the current round to 1 and reset the scores.
*
* @param {number} totalRounds the total number of rounds; can be 0 to
* indicate a 1 round game played with half balls.
*/
function newGame(totalRounds) {
// Start at round one and store the total rounds given. When the total
// rounds is 0 or smaller, assume 1.
game.currentRound = 1;
game.maxRounds = (totalRounds > 0) ? totalRounds : 1;
// We want to use half balls only when total rounds is 0 or smaller.
game.halfBalls = (totalRounds <= 0) ? true : false;
// Start the game with empty scores.
resetScores();
}
game.newGame = newGame;
/**
* Skip the round counter to indicate that we're in the next round now.
*/
function nextRound() {
game.currentRound++;
}
game.nextRound = nextRound;
/**
* Check to see if we think the game should be over right now. This is based
* purely on the current round number, so this should only be checked after
* modifying that value.
*
* @returns {boolean} true if the game is now over, false otherwise
*/
function isGameOver() {
return game.currentRound > game.maxRounds;
}
game.isGameOver = isGameOver;
/**
* Return an indication as to whether this is the last round of the game or
* not. This always returns false if the maximum number of rounds is not
* greater than 1, because the use of this function is for determing last
* round setup, which only happens for a game longer than one round.
*
* @returns {boolean} true if this is the last round
*/
function isLastRound() {
// Never the last round for a single round game
if (game.maxRounds == 1)
return false;
// This is the last round when we meet or exceed the last round.
return game.currentRound >= game.maxRounds;
}
game.isLastRound = isLastRound;
/**
* Reset the score values for both players.
*/
......
......@@ -24,6 +24,18 @@ module nurdz.game
*/
export let halfBalls : boolean = false;
/**
* The current round number in the game. This advances every time the last
* ball is dropped at the end of a round.
*/
export let currentRound : number = 1;
/**
* The maximum number of rounds in the game. Once the current round exceeds
* this value, the game is officially over.
*/
export let maxRounds : number = 1;
/**
* The number of points the human player has.
*/
......@@ -34,6 +46,68 @@ module nurdz.game
*/
let computerScore : number = 0;
/**
* Set up a new game to be played over the given number of total rounds. A
* value of 0 or smaller means that we will be playing only a single round,
* but with half balls.
*
* This will set the current round to 1 and reset the scores.
*
* @param {number} totalRounds the total number of rounds; can be 0 to
* indicate a 1 round game played with half balls.
*/
export function newGame (totalRounds : number) : void
{
// Start at round one and store the total rounds given. When the total
// rounds is 0 or smaller, assume 1.
currentRound = 1;
maxRounds = (totalRounds > 0) ? totalRounds : 1;
// We want to use half balls only when total rounds is 0 or smaller.
halfBalls = (totalRounds <= 0) ? true : false;
// Start the game with empty scores.
resetScores ();
}
/**
* Skip the round counter to indicate that we're in the next round now.
*/
export function nextRound () : void
{
currentRound++;
}
/**
* Check to see if we think the game should be over right now. This is based
* purely on the current round number, so this should only be checked after
* modifying that value.
*
* @returns {boolean} true if the game is now over, false otherwise
*/
export function isGameOver () : boolean
{
return currentRound > maxRounds;
}
/**
* Return an indication as to whether this is the last round of the game or
* not. This always returns false if the maximum number of rounds is not
* greater than 1, because the use of this function is for determing last
* round setup, which only happens for a game longer than one round.
*
* @returns {boolean} true if this is the last round
*/
export function isLastRound () : boolean
{
// Never the last round for a single round game
if (maxRounds == 1)
return false;
// This is the last round when we meet or exceed the last round.
return currentRound >= maxRounds;
}
/**
* Reset the score values for both players.
*/
......
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