Пример #1
0
        /// <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
Пример #2
0
        /// <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
Пример #3
0
 /// <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
Пример #4
0
        /// <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
Пример #5
0
        }// end ResizeGUIGameBoard

        /// <summary>
        /// Creates a SquareControl for each square and adds it to the appropriate square of the tableLayoutPanel.
        ///
        /// Pre:  none.
        /// Post: the tableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetUpGUIGameBoard()
        {
            for (int squareNum = Board.START_SQUARE_NUMBER; squareNum <= Board.FINISH_SQUARE_NUMBER; squareNum++)
            {
                Square        square        = Board.Squares[squareNum];
                SquareControl squareControl = new SquareControl(square, SpaceRaceGame.Players);
                AddControlToTableLayoutPanel(squareControl, squareNum);
            } //endfor
        }     // end SetupGameBoard
Пример #6
0
        }// ResizeGUIGameBoard

        /// <summary>
        /// Creates a SquareControl for each square and adds it to the appropriate square of the tableLayoutPanel.
        /// Pre:  none.
        /// Post: the tableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetUpGUIGameBoard()
        {
            for (var squareNum = Board.StartSquareNumber; squareNum <= Board.FinishSquareNumber; squareNum++)
            {
                var square        = Board.Squares[squareNum];
                var squareControl = new SquareControl(square, SpaceRaceGame.Players);
                AddControlToTableLayoutPanel(squareControl, squareNum);
            } //endfor
        }     // end SetupGameBoard
        } //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.
        ///
        /// 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
Пример #9
0
        /// <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
Пример #10
0
        /// <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