Example #1
0
 /// <summary>
 /// Update the game board state if a player wins or a cat's game happens.
 /// </summary>
 /// <param name="winner">The winning player of the game.</param>
 public void UpdateGameboardState(out PlayerPiece winner)
 {
     //
     // Player X has won
     //
     if (ThreeInARow(PlayerPiece.X))
     {
         _currentRoundState = GameboardState.PlayerXWin;
         winner             = PlayerPiece.X;
     }
     //
     // A player O has won
     //
     else if (ThreeInARow(PlayerPiece.O))
     {
         _currentRoundState = GameboardState.PlayerOWin;
         winner             = PlayerPiece.O;
     }
     //
     // All positions filled
     //
     else if (IsCatsGame())
     {
         _currentRoundState = GameboardState.CatsGame;
         winner             = PlayerPiece.None;
     }
     // Other situation
     else
     {
         winner = PlayerPiece.None;
     }
 }
Example #2
0
        /// <summary>
        /// Update the game board state if a player wins or a cat's game happens.
        /// </summary>
        public void UpdateGameboardState(int column, Sound applause)
        {
            //Get the row index of the most recent move in the column
            int row = LastMoveInColumn(column);

            //Create a gameboard position for the most recent move
            GameboardPosition gameboardPosition = new GameboardPosition(row, column);

            //Get the piece (X or O) of the most recent move
            PlayerPiece piece = GetPlayerPieceByGameBoardPosition(gameboardPosition);

            //Check for a win
            if (FourInARow(piece, gameboardPosition))
            {
                applause.playSound();

                if (piece == PlayerPiece.X)
                {
                    _currentRoundState = GameboardState.PlayerXWin;
                }
                else
                {
                    _currentRoundState = GameboardState.PlayerOWin;
                }
            }

            //Check if all positions are filled
            else if (IsCatsGame())
            {
                _currentRoundState = GameboardState.CatsGame;
            }
        }
Example #3
0
 /// <summary>
 /// Update game to be next player's turn
 /// </summary>
 private void SetNextPlayer()
 {
     if (_currentRoundState == GameboardState.PlayerOneTurn)
     {
         _currentRoundState = GameboardState.PlayerTwoTurn;
     }
     else
     {
         _currentRoundState = GameboardState.PlayerOneTurn;
     }
 }
Example #4
0
 /// <summary>
 /// Switch the game board state to the next player.
 /// </summary>
 private void SetNextPlayer()
 {
     if (CurrentRoundState == GameboardState.PlayerXTurn)
     {
         CurrentRoundState = GameboardState.PlayerOTurn;
     }
     else
     {
         CurrentRoundState = GameboardState.PlayerXTurn;
     }
 }
Example #5
0
 /// <summary>
 /// Switch the game board state to the next player.
 /// </summary>
 private void SetNextPlayer()
 {
     if (CurrentRoundState == GameboardState.PLAYER_REDTURN)
     {
         CurrentRoundState = GameboardState.PLAYER_BLUETURN;
     }
     else
     {
         CurrentRoundState = GameboardState.PLAYER_REDTURN;
     }
 }
Example #6
0
 /// <summary>
 /// Switch the game board state to the next player.
 /// </summary>
 public void SetNextPlayer()
 {
     if (_currentRoundState == GameboardState.PlayerXTurn)
     {
         _currentRoundState = GameboardState.PlayerOTurn;
     }
     else
     {
         _currentRoundState = GameboardState.PlayerXTurn;
     }
 }
Example #7
0
        public void InitalizeGameboard()
        {
            CurrentRoundState = GameboardState.NewGame;

            for (int row = 0; row < MAX_ROWS; row++)
            {
                for (int column = 0; column < MAX_COLUMNS; column++)
                {
                    CurrentBoard[row][column] = PLAYER_NONE;
                }
            }
        }
Example #8
0
        public void InitializeGameboard()
        {
            CurrentRoundState = GameboardState.NewRound;

            for (int row = 0; row < MAX_NUM_OF_ROWS_COLUMNS; row++)
            {
                for (int column = 0; column < MAX_NUM_OF_ROWS_COLUMNS; column++)
                {
                    CurrentBoard[row][column] = PLAYER_PIECE_NONE;
                }
            }
        }
Example #9
0
        /// <summary>
        /// Initialize gameboard, set all positions to None
        /// </summary>
        public void InitializeGameboard()
        {
            _currentRoundState = GameboardState.NewRound;

            //set all positions to None
            for (int row = 0; row < MAX_ROWS; row++)
            {
                for (int col = 0; col < MAX_COLS; col++)
                {
                    _positionState[row, col] = PlayerColor.None;
                }
            }
        }
        /// <summary>
        /// fill the game board array with "None" enum values
        /// </summary>
        public void InitializeGameboard()
        {
            _currentRoundState = GameboardState.NewRound;

            for (int xAxis = 0; xAxis < MAX_NUM_OF_ROWS_COLUMNS; xAxis++)
            {
                for (int yAxis = 0; yAxis < MAX_NUM_OF_ROWS_COLUMNS; yAxis++)
                {
                    for (int zAxis = 0; zAxis < MAX_NUM_OF_ROWS_COLUMNS; zAxis++)
                    {
                        _positionState[xAxis, yAxis, zAxis] = PlayerPiece.None;
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// fill the game board array with "None" enum values
        /// </summary>
        public void InitializeGameboard()
        {
            CurrentRoundState = GameboardState.NewRound;

            //
            // Set all PlayerPiece array values to "None"
            //
            for (int row = 0; row < MaxNumOfRowsColumns; row++)
            {
                for (int column = 0; column < MaxNumOfRowsColumns; column++)
                {
                    CurrentBoard[row][column] = PLAYER_PIECE_NONE;
                }
            }
        }
Example #12
0
        /// <summary>
        /// fill the game board array with "None" enum values
        /// </summary>
        public void InitializeGameboard()
        {
            CurrentRoundState = GameboardState.NewRound;

            //
            // Set all PlayerPiece array values to "None"
            //
            for (int row = 0; row < MAX_NUM_OF_ROWS_COLUMNS; row++)
            {
                for (int column = 0; column < MAX_NUM_OF_ROWS_COLUMNS; column++)
                {
                    CurrentBoard[row][column] = PLAYER_PIECE_NONE;
                }
            }
        }
        /// <summary>
        /// fill the game board array with "None" enum values
        /// </summary>
        public void InitializeGameboard()
        {
            _currentRoundState = GameboardState.NewRound;

            //
            // Set all PlayerPiece array values to "None"
            //
            for (int row = 0; row < MAX_NUM_OF_ROWS_COLUMNS; row++)
            {
                for (int column = 0; column < MAX_NUM_OF_ROWS_COLUMNS; column++)
                {
                    _positionState[row, column] = PlayerPiece.None;
                }
            }
        }
Example #14
0
 public void UpdateGameboardState()
 {
     if (FourInARow(PLAYER_PIECE_X))
     {
         CurrentRoundState = GameboardState.PlayerXWin;
     }
     if (FourInARow(PLAYER_PIECE_O))
     {
         CurrentRoundState = GameboardState.PlayerOWin;
     }
     else if (IsCatsGame())
     {
         CurrentRoundState = GameboardState.CatsGame;
     }
 }
Example #15
0
        /// <summary>
        /// fill the game board array with "None" enum values
        /// </summary>
        public void InitializeGameboard()
        {
            CurrentRoundState = GameboardState.NewRound;

            //
            // Set all PlayerPiece array values to "None"
            //
            for (int row = 0; row < MAX_NUM_OF_ROWS_COLUMNS; row++)
            {
                for (int column = 0; column < MAX_NUM_OF_ROWS_COLUMNS; column++)
                {
                    CurrentBoard[row][column] = EMPTY_BOARD_LOCATION_COLOR;
                }
            }
        }
Example #16
0
 /// <summary>
 /// Update gameboard status if a win/draw occurs
 /// </summary>
 public void UpdateGameboardState()
 {
     //check for win conditions
     if (FourInARow(PlayerColor.Red))
     {
         _currentRoundState = GameboardState.PlayerOneWin;
     }
     else if (FourInARow(PlayerColor.Blue))
     {
         _currentRoundState = GameboardState.PlayerTwoWin;
     }
     else if (IsDrawGame())
     {
         _currentRoundState = GameboardState.PlayerDraw;
     }
 }
Example #17
0
        /// <summary>
        /// fill the game board array with "None" enum values
        /// </summary>
        public void InitializeGameboard()
        {
            _currentRoundState = GameboardState.NewRound;
            _rows    = new List <int>();
            _columns = new List <int>();

            //
            // Set all PlayerPiece array values to "None"
            //
            for (int row = 0; row < MAX_NUM_OF_ROWS; row++)
            {
                _rows.Add(row);

                for (int column = 0; column < MAX_NUM_OF_COLUMNS; column++)
                {
                    _columns.Add(column);
                    _positionState[row, column] = PlayerPiece.None;
                }
            }
        }
Example #18
0
 /// <summary>
 /// Update the game board state if a player wins or a cat's game happens.
 /// </summary>
 public void UpdateGameboardState()
 {
     if (ThreeInARow(PLAYER_PIECE_X))
     {
         CurrentRoundState = GameboardState.PlayerXWin;
     }
     //
     // A player O has won
     //
     else if (ThreeInARow(PLAYER_PIECE_O))
     {
         CurrentRoundState = GameboardState.PlayerOWin;
     }
     //
     // All positions filled
     //
     else if (IsCatsGame())
     {
         CurrentRoundState = GameboardState.CatsGame;
     }
 }
 /// <summary>
 /// Update the game board state if a player wins or a cat's game happens.
 /// </summary>
 public void UpdateGameboardState()
 {
     if (FourInARow(PlayerPiece.X))
     {
         _currentRoundState = GameboardState.PlayerXWin;
     }
     //
     // A player O has won
     //
     else if (FourInARow(PlayerPiece.O))
     {
         _currentRoundState = GameboardState.PlayerOWin;
     }
     //
     // All positions filled
     //
     else if (IsCatsGame())
     {
         _currentRoundState = GameboardState.CatsGame;
     }
 }
Example #20
0
 /// <summary>
 /// Update the game board state if a player wins or a cat's game happens.
 /// </summary>
 public void UpdateGameboardState()
 {
     if (ThreeInARow(PLAYER_RED_CHIP_COLOR))
     {
         CurrentRoundState = GameboardState.PLAYER_REDWIN;
     }
     //
     // A player O has won
     //
     else if (ThreeInARow(PLAER_BLUE_CHIP_COLOR))
     {
         CurrentRoundState = GameboardState.PLAYER_BLUEWIN;
     }
     //
     // All positions filled
     //
     else if (IsCatsGame())
     {
         CurrentRoundState = GameboardState.CatsGame;
     }
 }
Example #21
0
 public void UpdateGameboardState()
 {
     for (int row = 0; row < MAX_ROWS; row++)
     {
         for (int column = 0; column < MAX_COLUMNS; column++)
         {
             for (int count = row; count <= (MAX_ROWS - 4); count++)
             {
                 if ((CurrentBoard[count][column].Color == CurrentBoard[count + 1][column].Color) &&
                     (CurrentBoard[count + 1][column].Color == CurrentBoard[count + 2][column].Color) &&
                     (CurrentBoard[count + 2][column].Color == CurrentBoard[count + 3][column].Color))
                 {
                     if (CurrentBoard[count][column].Color == PLAYER_RED.Color)
                     {
                         CurrentRoundState = GameboardState.PlayerRedWin;
                     }
                     else if (CurrentBoard[count][column].Color == PLAYER_YELLOW.Color)
                     {
                         CurrentRoundState = GameboardState.PlayerYellowWin;
                     }
                 }
                 if (column <= (MAX_COLUMNS - 4))
                 {
                     if ((CurrentBoard[count][column].Color == CurrentBoard[count + 1][column + 1].Color) &&
                         (CurrentBoard[count + 1][column + 1].Color == CurrentBoard[count + 2][column + 2].Color) &&
                         (CurrentBoard[count + 2][column + 2].Color == CurrentBoard[count + 3][column + 3].Color))
                     {
                         if (CurrentBoard[count][column].Color == PLAYER_RED.Color)
                         {
                             CurrentRoundState = GameboardState.PlayerRedWin;
                         }
                         else if (CurrentBoard[count][column].Color == PLAYER_YELLOW.Color)
                         {
                             CurrentRoundState = GameboardState.PlayerYellowWin;
                         }
                     }
                 }
                 if (column >= 3)
                 {
                     if ((CurrentBoard[count][column].Color == CurrentBoard[count + 1][column - 1].Color) &&
                         (CurrentBoard[count + 1][column - 1].Color == CurrentBoard[count + 2][column - 2].Color) &&
                         (CurrentBoard[count + 2][column - 2].Color == CurrentBoard[count + 3][column - 3].Color))
                     {
                         if (CurrentBoard[count][column].Color == PLAYER_RED.Color)
                         {
                             CurrentRoundState = GameboardState.PlayerRedWin;
                         }
                         else if (CurrentBoard[count][column].Color == PLAYER_YELLOW.Color)
                         {
                             CurrentRoundState = GameboardState.PlayerYellowWin;
                         }
                     }
                 }
             }
             for (int count = column; count <= (MAX_COLUMNS - 4); count++)
             {
                 if ((CurrentBoard[row][count].Color == CurrentBoard[row][count + 1].Color) &&
                     (CurrentBoard[row][count + 1].Color == CurrentBoard[row][count + 2].Color) &&
                     (CurrentBoard[row][count + 2].Color == CurrentBoard[row][count + 3].Color))
                 {
                     if (CurrentBoard[row][count].Color == PLAYER_RED.Color)
                     {
                         CurrentRoundState = GameboardState.PlayerRedWin;
                     }
                     else if (CurrentBoard[row][count].Color == PLAYER_YELLOW.Color)
                     {
                         CurrentRoundState = GameboardState.PlayerYellowWin;
                     }
                 }
             }
         }
     }
     if (IsTieGame())
     {
         CurrentRoundState = GameboardState.Draw;
     }
 }