Time for action – managing turns
1. Add the
Turn Management
region and its two methods to theTankBattlesGame
class as follows:#region Turn Management private void ActivatePlayer(int playerNumber) { UIHelper.SetElementVisibility("p", true, uiElements); UIHelper.SetButtonState( "p" + (playerNumber+1).ToString(), false, uiElements); currentPlayer = playerNumber; } private void DeactivatePlayer(int playerNumber) { UIHelper.SetButtonState( "p" + (playerNumber+1).ToString(), true, uiElements); } #endregion
2. In the
checkForShotImpacts()
method of theTankBattlesGame
class, just after the line that readsShotManager.HitProcessed =
true
, add the following lines of code:if (gameState != GameState.GameOver) { ActivatePlayer((currentPlayer + 1) % 2); }
3. At the end of the
StartNewRound()
method in theTankBattlesGame
class, set the initial state of the players when a new game is started, as follows:DeactivatePlayer(1); ActivatePlayer(0);
4. In the
UIButton_Clicked...