Exemplo n.º 1
0
        }// 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();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board.
        /// Pre:  none.
        /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetupGameBoard()
        {
            int squareHeigh = this.splitContainer.Panel1.Height / NUM_OF_ROWS;
            int squareWidth = this.splitContainer.Panel1.Width / NUM_OF_COLUMNS;

            //add square to game board
            for (int i = NUM_OF_ROWS - 1; i >= 0; i--)
            {
                SquareControl squarecontrol;
                for (int j = 0; j < NUM_OF_COLUMNS; j++)
                {
                    int col = j;

                    //nomal, sequence will display from left to righ
                    //check for odd row and display from right to left
                    if (i % 2 == 1)
                    {
                        col = (NUM_OF_COLUMNS - 1) - j;
                    }

                    //nomal, square row from to to botton
                    //revert it, begin at bottom
                    int squarePosition = (Math.Abs((NUM_OF_ROWS - 1) - i) * (NUM_OF_ROWS - 1)) + j;

                    //Create new square
                    squarecontrol = new SquareControl(hareAndTortoiseGame.Board.Squares[squarePosition], hareAndTortoiseGame.Players);

                    //add square to tableLayoutPanel
                    boardTableLayoutPanel.Controls.Add(squarecontrol, col, i);
                }
            }
        }
        } //end GetSquareNumberOfPlayer

        /// <summary>
        /// Tells you which SquareControl object is associated with a given square number.
        /// Pre:  a valid squareNumber is specified; and
        ///       the boardTableLayoutPanel is properly constructed.
        /// Post: the SquareControl object associated with the square number is returned.
        /// </summary>
        /// <param name="squareNumber">The square number.</param>
        /// <returns>Returns the SquareControl object associated with the square number.</returns>
        private SquareControl SquareControlAt(int squareNumber)
        {
            int columnNumber;
            int rowNumber;

            SquareControl control = new SquareControl(Board.Squares[squareNumber], HareAndTortoiseGame.Players);

            MapSquareNumToScreenRowAndColumn(squareNumber, out columnNumber, out rowNumber);
            control = (SquareControl)boardTableLayoutPanel.GetControlFromPosition(columnNumber, rowNumber);

            // Uncomment the following line once you've added the boardTableLayoutPanel to your form.
            return(control);

            // Delete the following line once you've added the boardTableLayoutPanel to your form.
        } //end SquareControlAt
        } // 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
Exemplo n.º 5
0
        /// <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
        } // end ResizeGameBoard

        /// <summary>
        /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board.
        /// Pre:  none.
        /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetupGameBoard()
        {
            // ########################### Code needs to be written to perform the following  ###############################################

            /*
             *   taking each Square of Baord separately create a SquareContol object containing that Square (look at the Constructor for SquareControl)
             *
             *   when it is either the Start Square or the Finish Square set the BackColor of the SquareControl to BurlyWood
             *
             *   DO NOT set the BackColor of any other Square Control
             *
             *   Call MapSquareNumtoScreenRowAnd Column  to determine the row and column position of the SquareControl on the TableLayoutPanel
             *
             *   Add the Control to the TaleLayoutPanel
             *
             */
            SquareControl[] squares = new SquareControl[Board.NUMBER_OF_SQUARES];

            int column;
            int row;

            SquareControl startSquare = new SquareControl(Board.Squares[Board.START_SQUARE_NUMBER], HareAndTortoiseGame.Players);

            MapSquareNumToScreenRowAndColumn(0, out column, out row);
            boardTableLayoutPanel.Controls.Add(startSquare, column, row);
            startSquare.BackColor = Color.BurlyWood;

            for (int i = 0; i < squares.Length; i++)
            {
                squares[i] = new SquareControl(Board.Squares[i + 1], HareAndTortoiseGame.Players);
                MapSquareNumToScreenRowAndColumn(i + 1, out column, out row);
                boardTableLayoutPanel.Controls.Add(squares[i], column, row);
            } // end for

            SquareControl finishSqure = new SquareControl(Board.Squares[Board.FINISH_SQUARE_NUMBER], HareAndTortoiseGame.Players);

            MapSquareNumToScreenRowAndColumn(41, out column, out row);
            boardTableLayoutPanel.Controls.Add(finishSqure, column, row);
            finishSqure.BackColor = Color.BurlyWood;
        }// SetupGameBaord
        }// 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
Exemplo n.º 8
0
        /// <summary>
        /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board.
        /// Pre:  none.
        /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetupGameBoard()
        {
            // ########################### Code needs to be written to perform the following  ###############################################

            /*
             *   taking each Square of Baord separately create a SquareContol object containing that Square (look at the Constructor for SquareControl)
             *
             *   when it is either the Start Square or the Finish Square set the BackColor of the SquareControl to BurlyWood
             *
             *   DO NOT set the BackColor of any other Square Control
             *
             *   Call MapSquareNumtoScreenRowAnd Column  to determine the row and column position of the SquareControl on the TableLayoutPanel
             *
             *   Add the Control to the TaleLayoutPanel
             *
             */

            for (int i = Board.START_SQUARE_NUMBER; i <= Board.FINISH_SQUARE_NUMBER; i++)
            {
                Square        square        = new Square(Board.Squares[i].Number, Board.Squares[i].Name);
                SquareControl squareControl = new SquareControl(square, HareAndTortoiseGame.Players);

                if (square.Number == Board.START_SQUARE_NUMBER || square.Number == Board.FINISH_SQUARE_NUMBER)
                {
                    squareControl.BackColor = Color.BurlyWood;
                }

                int row;
                int col;


                MapSquareNumToScreenRowAndColumn(i, out row, out col);

                boardTableLayoutPanel.Controls.Add(squareControl, col, row);
            }
        }// SetupGameBaord
        /// <summary>
        /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board.
        /// Pre:  none.
        /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetupGameBoard()
        {
            // ########################### Code needs to be written to perform the following  ###############################################
            /*
             *   taking each Square of Baord separately create a SquareContol object containing that Square (look at the Constructor for SquareControl)
             *
             *   when it is either the Start Square or the Finish Square set the BackColor of the SquareControl to BurlyWood
             *
             *   DO NOT set the BackColor of any other Square Control
             *
             *   Call MapSquareNumtoScreenRowAnd Column  to determine the row and column position of the SquareControl on the TableLayoutPanel
             *
             *   Add the Control to the TaleLayoutPanel
             *
             */

            for (int i = Board.START_SQUARE_NUMBER; i <= Board.FINISH_SQUARE_NUMBER; i++)
            {
                Square square = new Square(Board.Squares[i].Number, Board.Squares[i].Name);
                SquareControl squareControl = new SquareControl(square, HareAndTortoiseGame.Players);

                if (square.Number == Board.START_SQUARE_NUMBER || square.Number == Board.FINISH_SQUARE_NUMBER)
                {
                    squareControl.BackColor = Color.BurlyWood;
                }

                int row;
                int col;

                MapSquareNumToScreenRowAndColumn(i, out row, out col);

                boardTableLayoutPanel.Controls.Add(squareControl, col, row);
            }
        }
        /// <summary>
        /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board.
        /// Pre:  none.
        /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetupGameBoard()
        {
            int squareHeigh = this.splitContainer.Panel1.Height / NUM_OF_ROWS;
            int squareWidth = this.splitContainer.Panel1.Width / NUM_OF_COLUMNS;

            //add square to game board
            for (int i = 0; i < NUM_OF_ROWS; i++)
            {
                for (int j = 0; j < NUM_OF_COLUMNS; j++)
                {
                    //create control
                    SquareControl squarecontrol = new SquareControl(hareAndTortoiseGame.Board.Squares[(i*(NUM_OF_ROWS-1))+j], hareAndTortoiseGame.Players);
                    //check row for correct arrange as row
                    if (i % 2 == 0)
                    {

                        squarecontrol.Left = j * squareWidth;
                    }
                    else
                    {
                        squarecontrol.Left = (NUM_OF_COLUMNS -1 -j) * squareWidth;
                    }
                    //set top position of square
                    squarecontrol.Top = ((NUM_OF_ROWS- 1) - i) * squareHeigh;
                    squarecontrol.Size = new Size(squareWidth, squareHeigh);
                    this.splitContainer.Panel1.Controls.Add(squarecontrol);
                }
            }
        }
        /// <summary>
        /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board.
        /// Pre:  none.
        /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetupGameBoard()
        {
            SquareControl squareControl;
            Square squareGui;

            //the row of 0,2,4,6
            for (int row = 0; row < boardTableLayoutPanel.RowCount; row+=2)
            {
                for (int column = 0; column < boardTableLayoutPanel.ColumnCount; column++)
                {
                    squareGui = hareAndTortoiseGame.Board.Squares[36 - row * 6 + column];
                    squareControl = new SquareControl(squareGui, hareAndTortoiseGame.Players);

                    // Add the PictureBox object to boardTableLayoutPanel.
                    boardTableLayoutPanel.Controls.Add(squareControl, column, row);
                }//end colume
            }//end row

            //the row of 1,3,5,7
            for (int row = 1; row < boardTableLayoutPanel.RowCount - 1; row += 2)
            {
                for (int column = 0; column < boardTableLayoutPanel.ColumnCount; column++)
                {

                    squareGui = hareAndTortoiseGame.Board.Squares[41 - row * 6 - column];
                    squareControl = new SquareControl(squareGui, hareAndTortoiseGame.Players);

                    // Add the PictureBox object to boardTableLayoutPanel.
                    boardTableLayoutPanel.Controls.Add(squareControl, column, row);
                } // end column
            } // end row
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board.
        /// Pre:  none.
        /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board.
        /// </summary>
        private void SetupGameBoard()
        {
            // ########################### Code needs to be written to perform the following  ###############################################

            /*
             *   taking each Square of Baord separately create a SquareContol object containing that Square (look at the Constructor for SquareControl)
             *
             *   when it is either the Start Square or the Finish Square set the BackColor of the SquareControl to BurlyWood
             *
             *   DO NOT set the BackColor of any other Square Control
             *
             *   Call MapSquareNumtoScreenRowAnd Column  to determine the row and column position of the SquareControl on the TableLayoutPanel
             *
             *   Add the Control to the TaleLayoutPanel
             *
             */
            //HareAndTortoiseGame.InitialiseAllThePlayers();
            int row = 0;
            int col = 0;
            int n   = Board.Squares.Length - NUM_OF_COLUMNS;

            SquareControl[] squarecontrol = new SquareControl[42];
            for (int i = Board.Squares.Length - 1; i >= 0; i--)
            {
                // making a new square control to display the squares
                squarecontrol[i] = new SquareControl(Board.Squares[n], HareAndTortoiseGame.Players);
                // setting the current squares location
                Board.Squares[i].Location = n;

                // adding square control to layout panel
                boardTableLayoutPanel.Controls.Add(squarecontrol[i]);
                // calculate n which is the location of the square
                row++;
                if (col % 2 == 0)
                {
                    n++;
                }
                else
                {
                    n--;
                }
                if (row > NUM_OF_COLUMNS - 1)
                {
                    if (n == 42)
                    {
                        n = 35;
                    }
                    else if (n == 29)
                    {
                        n = 24;
                    }
                    else if (n == 30)
                    {
                        n = 23;
                    }
                    else if (n == 17)
                    {
                        n = 12;
                    }
                    else if (n == 18)
                    {
                        n = 11;
                    }
                    else if (n == 5)
                    {
                        n = 0;
                    }
                    row = 0;
                    col++;
                }
            }
            ResetGame();
        }// SetupGameBaord