Commit 831ec388 authored by Terence Martin's avatar Terence Martin

Score for bonus bricks

When a ball passes through a bonus brick during the regular game,
apply a score change to the owner of that ball.
parent 9c54b987
......@@ -7,6 +7,10 @@ var nurdz;
(function (nurdz) {
var game;
(function (game) {
/**
* The number of points that a bonus brick is worth.
*/
game.BONUS_BRICK_SCORE = 10;
/**
* The number of points the human player has.
*/
......@@ -38,7 +42,16 @@ var nurdz;
else
computerScore += value;
}
game.adjustScore = adjustScore;
/**
* Score points due to touching a bonus brick for the owner of the ball
* provided.
*
* @param {Ball} ball the ball that touched the bonus brick
*/
function bonusBrickScore(ball) {
adjustScore(ball.player, game.BONUS_BRICK_SCORE);
}
game.bonusBrickScore = bonusBrickScore;
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
......@@ -3217,6 +3230,8 @@ var nurdz;
// ourselves collected.
if (this._hidden == false)
this.vanish();
// Score points for the owner of the ball as well.
game.bonusBrickScore(ball);
}
else {
// We are simulating, so if we have not already set the flag
......
module nurdz.game
{
/**
* The number of points that a bonus brick is worth.
*/
export const BONUS_BRICK_SCORE = 10;
/**
* The number of points the human player has.
*/
......@@ -27,7 +32,7 @@ module nurdz.game
* @param {number} value the adjustment value; can be positive or
* negative
*/
export function adjustScore (player : PlayerType, value : number) : void
function adjustScore (player : PlayerType, value : number) : void
{
// Update the correct score.
if (player == PlayerType.PLAYER_HUMAN)
......@@ -36,6 +41,17 @@ module nurdz.game
computerScore += value;
}
/**
* Score points due to touching a bonus brick for the owner of the ball
* provided.
*
* @param {Ball} ball the ball that touched the bonus brick
*/
export function bonusBrickScore (ball : Ball) : void
{
adjustScore (ball.player, BONUS_BRICK_SCORE);
}
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
......
......@@ -34,11 +34,15 @@ module nurdz.game
* This value only tracks if you use the methods on the Ball entity to
* vanish or appear it; if you modify it's animation yourself, this will
* get out of sync.
*
* @type {boolean}
*/
private _hidden : boolean;
/**
* This flag is used during the simulation and is used to track if we
* have already been collected or not. This allows the AI to not
* prioritize a move that passes through the same bonus brick twice for
* some reason higher than other paths.
*/
private _simulationCollected : boolean;
/**
......@@ -287,6 +291,9 @@ module nurdz.game
// ourselves collected.
if (this._hidden == false)
this.vanish ();
// Score points for the owner of the ball as well.
bonusBrickScore (ball);
}
else
{
......
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