int currentLevel = 0; int linesCompletedThisLevel = 0; const float floodAccelerationPerLevel = 0.5f; Vector2 levelTextPosition = new Vector2(512, 215);
StartNewLevel()
method to the Game1 class:private void StartNewLevel() { currentLevel++; floodCount = 0.0f; linesCompletedThisLevel = 0; floodIncreaseAmount += floodAccelerationPerLevel; gameBoard.ClearBoard(); gameBoard.GenerateNewPieces(false); }
Update()
method of the Game1 class by updating the case section for GameState.TitleScreen
to include the following right before the game state is set to GameState.Playing:
currentLevel = 0; floodIncreaseAmount = 0.0f; StartNewLevel();
CheckScoringChain()
method to increment the linesCompletedThisLevel
variable right after playerScore += DetermineScore(WaterChain.Count)
;linesCompletedThisLevel++;
CheckScoringChain()
method, add the following to call the StartNewLevel()
method if necessary. Place this code directly after the foreach
loop that fades out tiles on the board:if (linesCompletedThisLevel >= 10) { StartNewLevel(); }
Draw()
method to display the current level in the appropriate location on the screen. Place this code right after the spriteBatch.DrawString()
call that displays the player's score:spriteBatch.DrawString(pericles36Font, currentLevel.ToString(), levelTextPosition, Color.Black);
The current game level and the number of lines the player has completed in the current level are tracked as integers (currentLevel and linesCompletedThisLevel)
. The two constants, baseFloodAmount
and floodAccelerationPerLevel
, determine how much water is added to the facility every time the flood is updated. Finally, the levelTextPosition
vector points to the location on the screen where the level number will be displayed.
The StartNewLevel()
method increases the currentLevel
, and clears the floodCount
and lineCompletedThisLevel
variables. It increases the floodIncreaseAmount
by the value of floodAccelerationPerLevel
and then clears the game board. Finally, new pieces are generated for each square on the board.
When beginning a new game (the updates in Step 3) we can simply set currentLevel
and floodIncreaseAmount
to zero, and then call the StartNewLevel()
method. Since both of these variables are increased by StartNewLevel()
the first level of a new game will begin with the appropriate values.
Step 4 increases the counter that tracks the number of lines the player has completed on the current level every time a scoring chain results in points. Step 5 checks to see if the player has completed 10
or more lines. If they have, a new level is started.
Finally, drawing the level number is a call to the simple form of SpriteBatch.DrawString()
just as we did for displaying the player's score.
There are a number of different things you could do to spruce up Flood Control. Here are a few suggestions to try using the knowledge you have gained over these two chapters:
LoadContent()
method and display it when appropriate. Tile_Sheet.png
file by adding an additional (fourth) column and then copying the first two columns to columns three and four. Draw bolts in the four corners of each of the twelve new piece images and modify the draw code to add an additional 40 pixels to the X value of the source Rectangle
if the piece contains the locked suffix. Grant extra points for using locked pieces in a scoring chain.3.145.2.184