Beispiel #1
0
 /// <summary>
 /// Checks to see if the current player has won the game by connecting 4 tokens on the antidiagonal.
 /// </summary>
 /// <param name="player">the current player</param>
 /// <param name="i">Horizontal coordinate</param>
 /// <param name="j">Vertical coordinate</param>
 /// <returns>Returns true if antidiagonal victory has occurred.</returns>
 private bool checkDiagonalToRight(char player, uint i, uint j)
 {
     if ((i + 3) < boardWidth && (j + 3) < boardHeight && board[i + 1, j + 1] == player &&
         board[i + 2, j + 2] == player && board[i + 3, j + 3] == player)
     {
         victory = victoryTypes.diagonal;
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 /// <summary>
 /// Checks to see if the current player has won the game by connecting 4 tokens on the main diagonal.
 /// </summary>
 /// <param name="player">the current player</param>
 /// <param name="i">Horizontal coordinate</param>
 /// <param name="j">Vertical coordinate</param>
 /// <returns>Returns true if main diagonal victory has occurred.</returns>
 private bool checkDiagonalToLeft(char player, uint i, uint j)
 {
     if ((i - 3) >= 0 && (j + 3) < boardHeight && board[i - 1, j + 1] == player &&
         board[i - 2, j + 2] == player && board[i - 3, j + 3] == player)
     {
         victory = victoryTypes.diagonal;
         return(true);
     }
     return(false);
 }
Beispiel #3
0
 /// <summary>
 /// Checks to see if the current player has won the game by connecting 4 tokens horizontally.
 /// </summary>
 /// <param name="player">the current player</param>
 /// <param name="i">Horizontal coordinate</param>
 /// <param name="j">Vertical coordinate</param>
 /// <returns>Returns true if horizontal victory has occurred.</returns>
 private bool checkHorizonal(char player, uint i, uint j)
 {
     if ((i + 3) < boardWidth && board[i + 1, j] == player &&
         board[i + 2, j] == player && board[i + 3, j] == player)
     {
         victory = victoryTypes.horizontal;
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 /// <summary>
 /// Checks to see if the current player has won the game by connecting 4 tokens vertically.
 /// </summary>
 /// <param name="player">the current player</param>
 /// <param name="i">Horizontal coordinate</param>
 /// <param name="j">Vertical coordinate</param>
 /// <returns>Returns true if vertical victory has occurred.</returns>
 private bool checkVertical(char player, uint i, uint j)
 {
     if ((j + 3) < boardHeight && board[i, j + 1] == player &&
         board[i, j + 2] == player && board[i, j + 3] == player)
     {
         victory = victoryTypes.vertical;
         return(true);
     }
     return(false);
 }
Beispiel #5
0
 /// <summary>
 /// Checks to see if the game has ended in a draw.
 /// </summary>
 /// <returns>Returns true if a draw has occurred, false if otherwise.</returns>
 private bool checkDraw()
 {
     for (uint i = 0; i < boardWidth; i++)
     {
         if (board[i, boardHeight - 1] == 'o')
         {
             return(false);
         }
     }
     victory = victoryTypes.draw;
     return(true);
 }