Example #1
0
 /// <summary>
 /// loads the appropriate square control object into each cell of the table layout panel
 /// </summary>
 private void SetUpGuiGameBoard()
 {
     // for each row
     for (int row = 0; row < NUM_OF_ROWS; row++)
     {
         // for each column
         for (int column = 0; column < NUM_OF_COLUMNS; column++)
         {
             Current_Square = Board.GetGameBoardSquare(column + (row * NUM_OF_COLUMNS));
             Square_Box     = new SquareControl(Current_Square, HareAndTortoise_Game.Players);
             if (Current_Square.GetName() == "Start" || Current_Square.GetName() == "Finish")
             {
                 Square_Box.BackColor = Color.BurlyWood;
             }
             // if row number is divisible by 2, orientate squares left to right
             if (row % 2 == 0)
             {
                 gameBoardPanel.Controls.Add(Square_Box, column, (NUM_OF_ROWS - 1) - row);
             }
             // if row number is divisible by 2, orientate squares right to left
             else
             {
                 gameBoardPanel.Controls.Add(Square_Box, (NUM_OF_COLUMNS - 1) - column, (NUM_OF_ROWS - 1) - row);
             }
         }
     }
 }//end SetUpGuiGameBoard()
        private void SetUpGuiGameBoard()
        {
            int row;
            int column;
            for (int i = Board.START_SQUARE; i <= Board.FINISH_SQUARE; i++) {
                Square position = Board.GetGameBoardSquare(i);
                SquareControl control = new SquareControl(position, HareAndTortoise_Game.Players);
                if (i == Board.START_SQUARE || i == Board.FINISH_SQUARE) {
                    control.BackColor = Color.BurlyWood;
                }

                MapSquareToTablePanel(i, out column, out row);
                // Now adding the square controllers to each box in gameBoardPanel
                gameBoardPanel.Controls.Add(control, column, row);
            }
        }
        /// <summary>
        /// Moves playerTokens one by one and square by square from their previous location to the new one.
        /// This function had to be made more complex just to tackle the situation when after a roll dice a player moves few positions back rather than forward.
        /// </summary>
        public void MapOnePlayer()
        {
            BindingList <Player> playerList;

            playerList = HareAndTortoise_Game.Players;
            for (int i = 0; i < HareAndTortoise_Game.numberOfPlayers; i++)
            {
                int a      = playerList[i].LastLocation.Number;
                int b      = playerList[i].Location.Number;
                int counts = System.Math.Abs(a - b);
                while (counts != 0)
                {
                    int row, column;
                    MapSquareToTablePanel(a, out row, out column);
                    SquareControl sqControl = (SquareControl)gameBoardPanel.GetControlFromPosition(column, row);
                    sqControl.ContainsPlayers[i] = false;
                    gameBoardPanel.Invalidate(true);
                    Application.DoEvents();
                    int y;
                    if (a < b)  // moves y one step towards current Location by adding to a
                    {
                        y = a + 1;
                    }
                    else        // moves y one step towards current Location by subtracting from  a
                    {
                        y = a - 1;
                    }
                    MapSquareToTablePanel(y, out row, out column);
                    sqControl = (SquareControl)gameBoardPanel.GetControlFromPosition(column, row);
                    sqControl.ContainsPlayers[i] = true;
                    gameBoardPanel.Invalidate(true);
                    Application.DoEvents();
                    if (a < b)         // This if else decides to keep increasing the counter or decreasing
                    {
                        a++;
                    }
                    else
                    {
                        a--;
                    }
                    counts--;
                }
            }
        }
 private void SetUpGuiGameBoard()
 {
     for (int i = Board.START_SQUARE; i <= Board.END_SQUARE; i++)
     {
         Square        sq            = Board.GetGameBoardSquare(i);
         SquareControl squareControl = new SquareControl(sq, HareAndTortoise_Game.Players);
         if (sq.Number == Board.START_SQUARE || sq.Number == Board.END_SQUARE)
         {
             squareControl.BackColor = Color.BurlyWood;
         }
         else
         {
             //Donot Set colour
         }
         int row;
         int column;
         MapSquareToTablePanel(i, out row, out column);
         gameBoardPanel.Controls.Add(squareControl, column, row);
     }
 }//end SetUpGuiGameBoard()
Example #5
0
        } //end ResizeGameBoard

        /// <summary>
        /// Update each square object in which players reside
        /// </summary>
        /// <param name="clear">determines whether the update is clearing players or adding them</param>
        public void UpdatePlayerSquares(bool clear)
        {
            for (int player = 0; player < HareAndTortoise_Game.NumberOfPlayers; player++)
            {
                // Get location (square object) of corresponding player object
                Square _Player_location = HareAndTortoise_Game.Players[player].Location;
                // Get corresponding square number from Square
                int square_number = _Player_location.GetNumber();
                // Get the control object of square number by finding its row and column
                SquareControl _Control = (SquareControl)GetControlOfSquareNumber(square_number);
                // Set corresponding bool of ContainsPlayers to true
                if (clear)
                {
                    _Control.ContainsPlayers[player] = true;
                }
                else
                {
                    _Control.ContainsPlayers[player] = false;
                }
            }
            // Re-display game board
            gameBoardPanel.Invalidate(true);
        }
        } //end ResizeGameBoard

        /// <summary>
        /// gets square control objects of every player based on their location
        /// and makes them visible
        /// by changing ContainsPlayer property value for that particular player
        /// </summary>
        /// <param name="status"> True status makes playerTokens visible whereas False make them invisible</param>
        public void MapPlayers(bool status)
        {
            BindingList <Player> playerList;

            playerList = HareAndTortoise_Game.Players;
            for (int i = 0; i < HareAndTortoise_Game.numberOfPlayers; i++)
            {
                Square location = playerList[i].Location;
                int    row, column;
                int    number = location.Number;
                MapSquareToTablePanel(number, out row, out column);
                SquareControl sqControl = (SquareControl)gameBoardPanel.GetControlFromPosition(column, row);
                if (status == true)
                {
                    sqControl.ContainsPlayers[i] = true;
                    gameBoardPanel.Invalidate(true);
                }
                else if (status == false)
                {
                    sqControl.ContainsPlayers[i] = false;
                    gameBoardPanel.Invalidate(true);
                }
            }
        }