/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // Code needs to be added here which does the following: // // for each player // determine the square number of the player // retrieve the SquareControl object with that square number // using the typeOfGuiUpdate, update the appropriate element of // the ContainsPlayers array of the SquareControl object. // int i = 0; foreach (Player o in SpaceRaceGame.Players) { int currentpos = GetSquareNumberOfPlayer(i); SquareControl Squarelocation = SquareControlAt(currentpos); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer && i < SpaceRaceGame.Players.Count) { Squarelocation.ContainsPlayers[i] = true; } else if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer && i <= SpaceRaceGame.Players.Count) { Squarelocation.ContainsPlayers[i] = false; } i = i + 1; } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // Code needs to be added here which does the following: // // for each player // determine the square number of the player // retrieve the SquareControl object with that square number // using the typeOfGuiUpdate, update the appropriate element of // the ContainsPlayers array of the SquareControl object. // for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { // Change the state of the square based on the add or remove player argument. if (typeOfGuiUpdate == 0) // add the player { SquareControlAt(GetSquareNumberOfPlayer(i)).ContainsPlayers[i] = true; // Update SquareControl players binding list } else // remove the player { SquareControlAt(GetSquareNumberOfPlayer(i)).ContainsPlayers[i] = false; // Update SquareControl players binding list } } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
}// end UpdatePlayersGuiLocations /// <summary> /// Adds an animation to the player tokens to move one square at a time. /// Post: the GUI board is updated to match the locations of all Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void SingleStepAnimation(TypeOfGuiUpdate typeOfGuiUpdate) { for (int i = 0; i < HareAndTortoiseGame.NumberOfPlayers; i++) { int playerLocation = GetSquareNumberOfPlayer(i); for (int j = 0; j <= playerLocation; j++) { SquareControl squareControl = SquareControlAt(j); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { squareControl.ContainsPlayers[i] = true; RefreshBoardTablePanelLayout(); Application.DoEvents(); Thread.Sleep(100); } else { squareControl.ContainsPlayers[i] = false; } } } RefreshPlayersInfoInDataGridView(); RefreshBoardTablePanelLayout(); }
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // Remove all players if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { int sqNum = GetSquareNumberOfPlayer(i); SquareControl sqControl = SquareControlAt(sqNum); sqControl.ContainsPlayers[i] = false; } } if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { for (int i = 0; i < SpaceRaceGame.NumberOfGUIPlayers; i++) { int sqNum = GetSquareNumberOfPlayer(i); SquareControl sqControl = SquareControlAt(sqNum); sqControl.ContainsPlayers[i] = true; } } RefreshBoardTablePanelLayout(); //must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // Code needs to be added here which does the following: // // for each player // determine the square number of the player // retrieve the SquareControl object with that square number // using the typeOfGuiUpdate, update the appropriate element of // the ContainsPlayers array of the SquareControl object. // for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { int num_square = GetSquareNumberOfPlayer(i); SquareControl square = SquareControlAt(num_square); if (typeOfGuiUpdate == 0) { square.ContainsPlayers[i] = true; } else { square.ContainsPlayers[i] = false; } } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // Code needs to be added here which does the following: // // for each player // determine the square number of the player // retrieve the SquareControl object with that square number // using the typeOfGuiUpdate, update the appropriate element of // the ContainsPlayers array of the SquareControl object. // for (int player = 0; player < SpaceRaceGame.NumberOfPlayers; player++) { //Find square number int squareNumber = GetSquareNumberOfPlayer(player); //Get the squarecontrol at the square number SquareControl squareNumOfPlayer = SquareControlAt(squareNumber); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { squareNumOfPlayer.ContainsPlayers[player] = true; } else if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { squareNumOfPlayer.ContainsPlayers[player] = false; } } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // Code needs to be added here which does the following: // // for each player // determine the square number of the player // retrieve the SquareControl object with that square number // using the typeOfGuiUpdate, update the appropriate element of // the ContainsPlayers array of the SquareControl object. // RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
} //end UpdatePlayersGuiLocations private void UpdatePlayerGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate, int numberOfTurn) { if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { var control = SquareControlAt(GetSquareNumberOfPlayer(numberOfTurn)); control.ContainsPlayers[numberOfTurn] = true; } else { var control = SquareControlAt(GetSquareNumberOfPlayer(numberOfTurn)); control.ContainsPlayers[numberOfTurn] = false; } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
} //end UpdatePlayersGuiLocations /// <summary> /// For use in single step mode. /// This method has the same functionality as UpdatePlayerGuiLocations /// except for a single player that is specified in the method parameters. /// </summary> private void UpdateSinglePlayerLocation(TypeOfGuiUpdate typeOfGuiUpdate, int playerNumber) { // Update the location of the players after a round int position = GetSquareNumberOfPlayer(playerNumber); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { SquareControlAt(position).ContainsPlayers[playerNumber] = true; } else if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { SquareControlAt(position).ContainsPlayers[playerNumber] = false; } RefreshBoardTablePanelLayout(); } //end UpdatePlayersGuiLocations
} // end ResetGame /// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens (or "pieces") are removed from their old squares /// or added to their new squares. E.g. when all players are moved back to the Start. /// /// For each of the players, this method is to use the GetSquareNumberOfPlayer method to find out /// which square number the player is on currently, then use the SquareControlAt method /// to find the corresponding SquareControl, and then update that SquareControl so that it /// knows whether the player is on that square or not. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed by using one or more methods /// in the HareAndTortoiseGame class. Otherwise, you won't see any change on the screen. /// /// Because this method moves ALL players, it should NOT be used when animating a SINGLE player's /// movements from square to square. /// /// /// Post: the GUI board is updated to match the locations of all Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { //##################### Code needs to be added here. ############################################################ int numberOfPlayers = GetNumberOfPlayers(); if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { for (int i = 0; i < HareAndTortoiseGame.MAX_PLAYERS; i++) { int squareNumber = GetSquareNumberOfPlayer(i); SquareControl control = new SquareControl(Board.Squares[squareNumber], HareAndTortoiseGame.Players); control = SquareControlAt(squareNumber); if (control == null) { throw new ArgumentException("Control invalid."); } else { control.Visible = true; control.ContainsPlayers[i] = false; } //end if } // end for } else if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { for (int i = 0; i < numberOfPlayers; i++) { int squareNumber = GetSquareNumberOfPlayer(i); SquareControl control = new SquareControl(Board.Squares[squareNumber], HareAndTortoiseGame.Players); control = SquareControlAt(squareNumber); if (control == null) { throw new ArgumentException("Control invalid."); } else { control.Visible = true; control.ContainsPlayers[i] = true; } // end if } // end for } // end if RefreshBoardTablePanelLayout(); // Must be the last line in this method. DO NOT put it inside a loop. }// end UpdatePlayersGuiLocations
} //end UpdatePlayersGuiLocations private void UpdatePlayersGuiLocationsSingleSteps(TypeOfGuiUpdate typeOfGuiUpdate, int counter) { int position = GetSquareNumberOfPlayer(counter); SquareControl squareControl = SquareControlAt(position); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { //Square square = new Square(position.ToString(), position); //SquareControlAt(position); squareControl.ContainsPlayers[counter] = true; } else { squareControl.ContainsPlayers[counter] = false; } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { int location = GetSquareNumberOfPlayer(i); SquareControl Square = SquareControlAt(location); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { Square.ContainsPlayers[i] = true; } else if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { Square.ContainsPlayers[i] = false; } } RefreshBoardTablePanelLayout(); } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { for (int iterator = 0; iterator < SpaceRaceGame.NumberOfPlayers; iterator++) { int squarenum = GetSquareNumberOfPlayer(iterator); SquareControl square = SquareControlAt(squarenum); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { square.ContainsPlayers[iterator] = true; } else if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { square.ContainsPlayers[iterator] = false; } } RefreshBoardTablePanelLayout(); } //end UpdatePlayersGuiLocations
}//end UpdatesPlayersDataGridView /// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { // Change the state of the square based on the add or remove player argument. if (typeOfGuiUpdate == 0) // add the player { SquareControlAt(GetSquareNumberOfPlayer(i)).ContainsPlayers[i] = true; // Update SquareControl players binding list } else // remove the player { SquareControlAt(GetSquareNumberOfPlayer(i)).ContainsPlayers[i] = false; // Update SquareControl players binding list } } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { for (var i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { var control = SquareControlAt(GetSquareNumberOfPlayer(i)); control.ContainsPlayers[i] = true; } } else { for (var i = 0; i < SpaceRaceGame.Players.Count; i++) { var control = SquareControlAt(GetSquareNumberOfPlayer(i)); control.ContainsPlayers[i] = false; } } RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens (or "pieces") are removed from their old squares /// or added to their new squares. E.g. when all players are moved back to the Start. /// /// For each of the players, this method is to use the GetSquareNumberOfPlayer method to find out /// which square number the player is on currently, then use the SquareControlAt method /// to find the corresponding SquareControl, and then update that SquareControl so that it /// knows whether the player is on that square or not. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed by using one or more methods /// in the HareAndTortoiseGame class. Otherwise, you won't see any change on the screen. /// /// Because this method moves ALL players, it should NOT be used when animating a SINGLE player's /// movements from square to square. /// /// /// Post: the GUI board is updated to match the locations of all Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { //##################### Code needs to be added here. ############################################################ for (int i = 0; i < HareAndTortoiseGame.NumberOfPlayers; i++) { int playerLocation = GetSquareNumberOfPlayer(i); SquareControl squareControl = SquareControlAt(playerLocation); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { squareControl.ContainsPlayers[i] = true; } else { squareControl.ContainsPlayers[i] = false; } } RefreshPlayersInfoInDataGridView(); RefreshBoardTablePanelLayout(); // Must be the last line in this method. DO NOT put it inside a loop. }// end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // For each player, determine the square number of the player, // retrieve the SquareControl object with that square number // using the typeOfGuiUpdate, update the appropriate element of // the ContainsPlayers array of the SquareControl object. for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { int position = GetSquareNumberOfPlayer(i); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { SquareControlAt(position).ContainsPlayers[i] = true; } else if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { SquareControlAt(position).ContainsPlayers[i] = false; } } RefreshBoardTablePanelLayout(); } //end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens are removed from their old squares /// or added to their new squares. E.g. at the end of a round of play or /// when the Reset button has been clicked. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed. /// Otherwise, you won't see any change on the screen. /// /// Pre: the Players objects in the SpaceRaceGame have each players' current locations /// Post: the GUI board is updated to match /// </summary> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { int playerNo = 0; foreach (Player currentPlayer in SpaceRaceGame.Players) { if (currentPlayer.RocketFuel != 0) { int squareNum = GetSquareNumberOfPlayer(playerNo); SquareControl controlObject = SquareControlAt(squareNum); //called to move player to their new space if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { controlObject.ContainsPlayers[playerNo] = true; } else { //called to remove player from their current space if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { controlObject.ContainsPlayers[playerNo] = false; } } } else { //still show where the player with no fuel is int squareNum = GetSquareNumberOfPlayer(playerNo); SquareControl currentLocation = SquareControlAt(squareNum); currentLocation.ContainsPlayers[playerNo] = true; } playerNo++; }//end of foreach loop RefreshBoardTablePanelLayout();//must be the last line in this method. Do not put inside above loop. } //end UpdatePlayersGuiLocations
}// end UpdatePlayersGuiLocations /// <summary> /// Updates location of a player identified by player number /// Pre: Specified type of GUI update (AddPlayer or RemovePlayer) /// Post: The GUI borad is updated to match the location of the player /// </summary> /// <param name="typeOfGuiUpdate"></param> /// <param name="playerNumber"></param> private void UpdateSinglePlayerGuiLocation(TypeOfGuiUpdate typeOfGuiUpdate, int playerNumber) { if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { int squareNumber = GetSquareNumberOfPlayer(playerNumber); SquareControl control = new SquareControl(Board.Squares[squareNumber], HareAndTortoiseGame.Players); control = SquareControlAt(squareNumber); if (control == null) { throw new ArgumentException("Control invalid"); } else { control.Visible = true; control.ContainsPlayers[playerNumber] = false; } // end if } else if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { int squareNumber = GetSquareNumberOfPlayer(playerNumber); SquareControl control = new SquareControl(Board.Squares[squareNumber], HareAndTortoiseGame.Players); control = SquareControlAt(squareNumber); if (control == null) { throw new ArgumentException("Control invalid"); } else { control.Visible = true; control.ContainsPlayers[playerNumber] = true; } // end if } // end if RefreshBoardTablePanelLayout(); } // end UpdateSinglePlayerGuiLocation
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens (or "pieces") are removed from their old squares /// or added to their new squares. E.g. when all players are moved back to the Start. /// /// For each of the players, this method is to use the GetSquareNumberOfPlayer method to find out /// which square number the player is on currently, then use the SquareControlAt method /// to find the corresponding SquareControl, and then update that SquareControl so that it /// knows whether the player is on that square or not. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed by using one or more methods /// in the HareAndTortoiseGame class. Otherwise, you won't see any change on the screen. /// /// Because this method moves ALL players, it should NOT be used when animating a SINGLE player's /// movements from square to square. /// /// /// Post: the GUI board is updated to match the locations of all Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // stores current square player is in int squarenum; SquareControl sq; for (int i = 0; i < HareAndTortoiseGame.NumberOfPlayers; i++) { squarenum = GetSquareNumberOfPlayer(i); sq = SquareControlAt(squarenum); // remove player from SquareControl if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { sq.ContainsPlayers[i] = false; } // adds player to SquareControl else if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { sq.ContainsPlayers[i] = true; } } RefreshBoardTablePanelLayout(); // Must be the last line in this method. DO NOT put it inside a loop. }// end UpdatePlayersGuiLocations
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens (or "pieces") are removed from their old squares /// or added to their new squares. E.g. when all players are moved back to the Start. /// /// For each of the players, this method is to use the GetSquareNumberOfPlayer method to find out /// which square number the player is on currently, then use the SquareControlAt method /// to find the corresponding SquareControl, and then update that SquareControl so that it /// knows whether the player is on that square or not. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed by using one or more methods /// in the hareAndTortoiseGame class. Otherwise, you won't see any change on the screen. /// /// Because this method moves ALL players, it should NOT be used when animating a SINGLE player's /// movements from square to square. /// /// Pre: the Players objects in the hareAndTortoiseGame give the players' current locations. /// Post: the GUI board is updated to match the locations in the Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { RefreshBoardTablePanelLayout(); // Should be the last line in this method. Do not put inside a loop. }
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens (or "pieces") are removed from their old squares /// or added to their new squares. E.g. when all players are moved back to the Start. /// /// For each of the players, this method is to use the GetSquareNumberOfPlayer method to find out /// which square number the player is on currently, then use the SquareControlAt method /// to find the corresponding SquareControl, and then update that SquareControl so that it /// knows whether the player is on that square or not. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed by using one or more methods /// in the hareAndTortoiseGame class. Otherwise, you won't see any change on the screen. /// /// Because this method moves ALL players, it should NOT be used when animating a SINGLE player's /// movements from square to square. /// /// Pre: the Players objects in the hareAndTortoiseGame give the players' current locations. /// Post: the GUI board is updated to match the locations in the Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { // remove players from their old squares. if (typeOfGuiUpdate == TypeOfGuiUpdate.RemovePlayer) { for (int squareNumber = 0; squareNumber < hareAndTortoiseGame.Players.Count; squareNumber++) { int playerSquare = GetSquareNumberOfPlayer(squareNumber); SquareControlAt(playerSquare).ContainsPlayers[squareNumber] = false; }//end for } // add players to their new squares. else if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { for (int squareNumber = 0; squareNumber < hareAndTortoiseGame.NumberOfPlayers; squareNumber++) { int playerSquare = GetSquareNumberOfPlayer(squareNumber); SquareControlAt(playerSquare).ContainsPlayers[squareNumber] = true; }//end for }// end if RefreshBoardTablePanelLayout(); // Should be the last line in this method. Do not put inside a loop. }
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens (or "pieces") are removed from their old squares /// or added to their new squares. E.g. when all players are moved back to the Start. /// /// For each of the players, this method is to use the GetSquareNumberOfPlayer method to find out /// which square number the player is on currently, then use the SquareControlAt method /// to find the corresponding SquareControl, and then update that SquareControl so that it /// knows whether the player is on that square or not. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed by using one or more methods /// in the HareAndTortoiseGame class. Otherwise, you won't see any change on the screen. /// /// Because this method moves ALL players, it should NOT be used when animating a SINGLE player's /// movements from square to square. /// /// /// Post: the GUI board is updated to match the locations of all Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { //##################### Code needs to be added here. ############################################################ for (int i = 0; i < HareAndTortoiseGame.NumberOfPlayers; i++) { int playerLocation = GetSquareNumberOfPlayer(i); SquareControl squareControl = SquareControlAt(playerLocation); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { squareControl.ContainsPlayers[i] = true; } else { squareControl.ContainsPlayers[i] = false; } } RefreshPlayersInfoInDataGridView(); RefreshBoardTablePanelLayout(); // Must be the last line in this method. DO NOT put it inside a loop. }
/// <summary> /// Adds an animation to the player tokens to move one square at a time. /// Post: the GUI board is updated to match the locations of all Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void SingleStepAnimation(TypeOfGuiUpdate typeOfGuiUpdate) { for (int i = 0; i < HareAndTortoiseGame.NumberOfPlayers; i++) { int playerLocation = GetSquareNumberOfPlayer(i); for (int j = 0; j <= playerLocation; j++) { SquareControl squareControl = SquareControlAt(j); if (typeOfGuiUpdate == TypeOfGuiUpdate.AddPlayer) { squareControl.ContainsPlayers[i] = true; RefreshBoardTablePanelLayout(); Application.DoEvents(); Thread.Sleep(100); } else { squareControl.ContainsPlayers[i] = false; } } } RefreshPlayersInfoInDataGridView(); RefreshBoardTablePanelLayout(); }
/// <summary> /// At several places in the program's code, it is necessary to update the GUI board, /// so that player's tokens (or "pieces") are removed from their old squares /// or added to their new squares. E.g. when all players are moved back to the Start. /// /// For each of the players, this method is to use the GetSquareNumberOfPlayer method to find out /// which square number the player is on currently, then use the SquareControlAt method /// to find the corresponding SquareControl, and then update that SquareControl so that it /// knows whether the player is on that square or not. /// /// Moving all players from their old to their new squares requires this method to be called twice: /// once with the parameter typeOfGuiUpdate set to RemovePlayer, and once with it set to AddPlayer. /// In between those two calls, the players locations must be changed by using one or more methods /// in the HareAndTortoiseGame class. Otherwise, you won't see any change on the screen. /// /// Because this method moves ALL players, it should NOT be used when animating a SINGLE player's /// movements from square to square. /// /// /// Post: the GUI board is updated to match the locations of all Players objects. /// </summary> /// <param name="typeOfGuiUpdate">Specifies whether all the players are being removed /// from their old squares or added to their new squares</param> private void UpdatePlayersGuiLocations(TypeOfGuiUpdate typeOfGuiUpdate) { //##################### Code needs to be added here. ############################################################ RefreshBoardTablePanelLayout(); // Must be the last line in this method. DO NOT put it inside a loop. }// end UpdatePlayersGuiLocations