private MoveWinsGameCheck GameIsADraw(MoveWinsGameCheck moveWinsGameCheck) { if (GameBoard.All(x => KnotsAndCrossesEngine.Player.Any(y => x == y))) { moveWinsGameCheck.GameIsADraw = true; moveWinsGameCheck.GameComplete = true; GameStatusMessage = "Cats game, game ends in a draw!"; } else { moveWinsGameCheck.GameIsADraw = false; } return(moveWinsGameCheck); }
private MoveWinsGameCheck CheckMoveWinsGame() { WinningMove winningMovePos = WinningMove.Row1; bool horizontalCheck = false; if (GameBoard[0] == GameBoard[1] && GameBoard[1] == GameBoard[2]) { winningMovePos = WinningMove.Row1; horizontalCheck = true; WinningMoves = new List <string>() { "0,0", "0,1", "0,2" }; } else if (GameBoard[3] == GameBoard[4] && GameBoard[4] == GameBoard[5]) { winningMovePos = WinningMove.Row2; horizontalCheck = true; WinningMoves = new List <string>() { "1,0", "1,1", "1,2" }; } else if (GameBoard[6] == GameBoard[7] && GameBoard[7] == GameBoard[8]) { winningMovePos = WinningMove.Row3; horizontalCheck = true; WinningMoves = new List <string>() { "2,0", "2,1", "2,2" }; } bool verticalCheck = false; if (GameBoard[0] == GameBoard[3] && GameBoard[3] == GameBoard[6]) { winningMovePos = WinningMove.Col1; verticalCheck = true; WinningMoves = new List <string>() { "0,0", "1,0", "2,0" }; } else if (GameBoard[1] == GameBoard[4] && GameBoard[4] == GameBoard[7]) { winningMovePos = WinningMove.Col2; verticalCheck = true; WinningMoves = new List <string>() { "0,1", "1,1", "2,1" }; } else if (GameBoard[2] == GameBoard[5] && GameBoard[5] == GameBoard[8]) { winningMovePos = WinningMove.Col3; verticalCheck = true; WinningMoves = new List <string>() { "0,2", "1,2", "2,2" }; } bool diagonalCheck = false; if (GameBoard[0] == GameBoard[4] && GameBoard[4] == GameBoard[8]) { winningMovePos = WinningMove.Diag1; diagonalCheck = true; WinningMoves = new List <string>() { "0,0", "1,1", "2,2" }; } else if (GameBoard[2] == GameBoard[4] && GameBoard[4] == GameBoard[6]) { winningMovePos = WinningMove.Diag2; diagonalCheck = true; WinningMoves = new List <string>() { "0,2", "1,1", "2,0" }; } string winningGameMessage = string.Empty; bool moveWinsGame = false; if (horizontalCheck || verticalCheck || diagonalCheck) { moveWinsGame = true; WinningPlayer = PlayerSwitch + 1; winningGameMessage = $"Congratulations!! Player { WinningPlayer } wins!"; GameStatusMessage = CurrentPlayerIsUser ? "Congratulations you win" : "Unlucky the computer wins"; } var moveWinsGameCheck = new MoveWinsGameCheck() { MoveWinsGame = moveWinsGame, WinningMovePos = winningMovePos, WinningGameMessage = winningGameMessage, GameComplete = moveWinsGame, }; return(moveWinsGameCheck); }