Commit 6f1de1c6 authored by Terence Martin's avatar Terence Martin

Score for blocked balls at round end

Score partial points based on ball position whenever a ball is
vanished during the game without it having reached the goal line. This
can happen when a ball is blocked and removed before the final ball
drop, or when the final ball drop does not end the ball at the goal
line.
parent 9213c393
......@@ -16,6 +16,11 @@ var nurdz;
* bottom of the screen, where the goal line is.
*/
game.GOAL_BALL_SCORE = 60;
/**
* The number of points scored per row of advancement of a ball. This is
* applied at the end of the round when the final balls are removed.
*/
game.BALL_POSITION_MULTIPLIER = 2;
/**
* The number of points the human player has.
*/
......@@ -67,6 +72,16 @@ var nurdz;
adjustScore(ball.player, game.GOAL_BALL_SCORE);
}
game.goalBallScore = goalBallScore;
/**
* Score partial points for a ball based on its final resting position in
* the maze.
*
* @param {Ball} ball the ball to score partial points for
*/
function partialBallScore(ball) {
adjustScore(ball.player, ball.mapPosition.y * game.BALL_POSITION_MULTIPLIER);
}
game.partialBallScore = partialBallScore;
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
......@@ -1113,7 +1128,7 @@ 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++) {
for (var ballIndex = 0; ballIndex < 1; ballIndex++) {
// Get the balls from the pool
playerBalls[ballIndex] = this._maze.getBall();
computerBalls[ballIndex] = this._maze.getBall();
......@@ -5133,10 +5148,10 @@ var nurdz;
*/
GameScene.prototype.ballDropComplete = function (ball, isFinal) {
// Did the ball reach the goal?
if (ball.mapPosition.y == game.MAZE_HEIGHT - 2) {
if (ball.mapPosition.y == game.MAZE_HEIGHT - 2)
game.goalBallScore(ball);
console.log("GOOOOOAL!");
}
else if (isFinal == true)
game.partialBallScore(ball);
// Now that the ball is done, where we go depends on where we came
// from.
switch (this.priorState) {
......@@ -5174,7 +5189,9 @@ var nurdz;
* @param {Ball} ball the ball that being removed
*/
GameScene.prototype.blockedBallRemoved = function (ball) {
console.log("Removing blocked ball at " + ball.mapPosition.toString());
// This is a blocked ball that can no longer move, so apply a
// partial score value now.
game.partialBallScore(ball);
};
/**
* The Maze is telling us that it is now empty of gray bricks because it
......
......@@ -11,6 +11,12 @@ module nurdz.game
*/
export const GOAL_BALL_SCORE = 60;
/**
* The number of points scored per row of advancement of a ball. This is
* applied at the end of the round when the final balls are removed.
*/
export const BALL_POSITION_MULTIPLIER = 2;
/**
* The number of points the human player has.
*/
......@@ -69,6 +75,17 @@ module nurdz.game
adjustScore (ball.player, GOAL_BALL_SCORE);
}
/**
* Score partial points for a ball based on its final resting position in
* the maze.
*
* @param {Ball} ball the ball to score partial points for
*/
export function partialBallScore (ball : Ball) : void
{
adjustScore (ball.player, ball.mapPosition.y * BALL_POSITION_MULTIPLIER);
}
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
......
......@@ -478,7 +478,7 @@ module nurdz.game
//
// This always works because the ball pool always has exactly enough
// balls for our purposes.
for (let ballIndex = 0 ; ballIndex < MAZE_WIDTH - 2 ; ballIndex++)
for (let ballIndex = 0 ; ballIndex < 1 ; ballIndex++)
{
// Get the balls from the pool
playerBalls[ballIndex] = this._maze.getBall ();
......
......@@ -531,10 +531,12 @@ module nurdz.game
{
// Did the ball reach the goal?
if (ball.mapPosition.y == MAZE_HEIGHT - 2)
{
goalBallScore (ball);
console.log ("GOOOOOAL!");
}
// The ball did not reach the goal, but if this is a final ball drop
// then score partial points for the ending position of the ball.
else if (isFinal == true)
partialBallScore (ball);
// Now that the ball is done, where we go depends on where we came
// from.
......@@ -579,7 +581,9 @@ module nurdz.game
*/
blockedBallRemoved (ball : Ball) : void
{
console.log("Removing blocked ball at " + ball.mapPosition.toString ());
// This is a blocked ball that can no longer move, so apply a
// partial score value now.
partialBallScore (ball);
}
/**
......
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