Commit 770002c1 authored by Terence Martin's avatar Terence Martin

Clear unplayed balls at the appropriate time

This ensures that if any balls are unplayed for either player (due to
being blocked), they are visually removed from the screen while all of
the blocked balls are being removed, so that they don't remain just
dangling there at the end of the run.
parent ef9e9917
...@@ -554,6 +554,25 @@ var nurdz; ...@@ -554,6 +554,25 @@ var nurdz;
// Clear cells at all locations. // Clear cells at all locations.
for (var i = 0; i < game.MAZE_WIDTH * game.MAZE_HEIGHT; i++) for (var i = 0; i < game.MAZE_WIDTH * game.MAZE_HEIGHT; i++)
this._contents[i] = null; this._contents[i] = null;
// Clear the unplayed ball arrays as well. No hiding in this case
// because this gets called during initialization, where there might
// not be any valid arrays yet.
this.clearUnplayedBalls(false);
};
/**
* Clear the unplayed balls from the data storage for them; this affects
* both players.
*
* If the hide parameter is true, this will first tell any balls that
* still exist as an unplayed ball to hide itself before the array is
* cleaned up, so that the balls are also visually removed.
*/
MazeContents.prototype.clearUnplayedBalls = function (hide) {
// SHould we hide any?
if (hide) {
this.hideBallsInArray(this._playerBalls);
this.hideBallsInArray(this._computerBalls);
}
// Ensure that the ball arrays for both players are fully empty. // Ensure that the ball arrays for both players are fully empty.
for (var i = 0; i < game.MAZE_WIDTH - 2; i++) { for (var i = 0; i < game.MAZE_WIDTH - 2; i++) {
this._playerBalls[i] = null; this._playerBalls[i] = null;
...@@ -5247,6 +5266,12 @@ var nurdz; ...@@ -5247,6 +5266,12 @@ var nurdz;
// Tell the computer that they're starting their turn now. // Tell the computer that they're starting their turn now.
this._computer.ai_startingTurn(); this._computer.ai_startingTurn();
break; break;
// When we are entering the state for removing all blocked
// balls, make sure that the maze contents discards all unplayed
// balls so that they visually leave the screen.
case game.GameState.REMOVE_BLOCKED_BALLS:
this._maze.contents.clearUnplayedBalls(true);
break;
// When we enter the final ball drop, hide the player and // When we enter the final ball drop, hide the player and
// computer characters. // computer characters.
case game.GameState.FINAL_BALL_DROP: case game.GameState.FINAL_BALL_DROP:
......
...@@ -351,6 +351,29 @@ module nurdz.game ...@@ -351,6 +351,29 @@ module nurdz.game
for (let i = 0 ; i < MAZE_WIDTH * MAZE_HEIGHT ; i++) for (let i = 0 ; i < MAZE_WIDTH * MAZE_HEIGHT ; i++)
this._contents[i] = null; this._contents[i] = null;
// Clear the unplayed ball arrays as well. No hiding in this case
// because this gets called during initialization, where there might
// not be any valid arrays yet.
this.clearUnplayedBalls (false);
}
/**
* Clear the unplayed balls from the data storage for them; this affects
* both players.
*
* If the hide parameter is true, this will first tell any balls that
* still exist as an unplayed ball to hide itself before the array is
* cleaned up, so that the balls are also visually removed.
*/
clearUnplayedBalls (hide : boolean) : void
{
// SHould we hide any?
if (hide)
{
this.hideBallsInArray (this._playerBalls);
this.hideBallsInArray (this._computerBalls);
}
// Ensure that the ball arrays for both players are fully empty. // Ensure that the ball arrays for both players are fully empty.
for (let i = 0 ; i < MAZE_WIDTH - 2 ; i++) for (let i = 0 ; i < MAZE_WIDTH - 2 ; i++)
{ {
...@@ -359,6 +382,7 @@ module nurdz.game ...@@ -359,6 +382,7 @@ module nurdz.game
} }
} }
/** /**
* Given an array of balls which is the full size of the content area of * Given an array of balls which is the full size of the content area of
* the maze (less the walls on either sides), check and see if any of * the maze (less the walls on either sides), check and see if any of
......
...@@ -646,6 +646,13 @@ module nurdz.game ...@@ -646,6 +646,13 @@ module nurdz.game
this._computer.ai_startingTurn (); this._computer.ai_startingTurn ();
break; break;
// When we are entering the state for removing all blocked
// balls, make sure that the maze contents discards all unplayed
// balls so that they visually leave the screen.
case GameState.REMOVE_BLOCKED_BALLS:
this._maze.contents.clearUnplayedBalls (true);
break;
// When we enter the final ball drop, hide the player and // When we enter the final ball drop, hide the player and
// computer characters. // computer characters.
case GameState.FINAL_BALL_DROP: case GameState.FINAL_BALL_DROP:
......
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