internal static string GetValidMoveString(BoardGame i_BoardGame) { string currentMoveString = Console.ReadLine(); while (!checkValidMoveInput(currentMoveString, i_BoardGame)) { Console.WriteLine("Invalid move! please enter a new move"); currentMoveString = Console.ReadLine(); } return(currentMoveString); }
internal static string GetFirstMoveFromUser(Player i_CurrentPlayer, BoardGame i_BoardGame) { string message; string currentMoveString; i_BoardGame.PrintBoard(); message = string.Format("{0}'s turn:", i_CurrentPlayer.Name); Console.WriteLine(message); currentMoveString = GetValidMoveString(i_BoardGame); return(currentMoveString); }
internal void StartGame() { string nameOfPlayer1; short boardSize; string typeOfSeconedPlayer; nameOfPlayer1 = GameUI.GetPlayerName(); this.m_Player1 = new Player(eShapeType.X, nameOfPlayer1, ePlayerType.Person); boardSize = GameUI.GetBoardSize(); typeOfSeconedPlayer = GameUI.GetTypeOfSecondPlayer(); setSeconedPlayer(typeOfSeconedPlayer); this.m_BoardGame = new BoardGame(boardSize); gameRound(); }
internal static string GetMessageInvalidQuit(BoardGame i_BoardGame) { string currentMoveString; Console.WriteLine("You can't quit at this point of the game. Please Enter a valid move"); currentMoveString = Console.ReadLine(); while (!checkValidMoveInput(currentMoveString, i_BoardGame) || currentMoveString.Equals("Q")) { Console.WriteLine("Invalid move! please enter a new move"); currentMoveString = Console.ReadLine(); } return(currentMoveString); }
internal void MoveOnBoard(BoardGame i_BoardGame) { switch (this.MoveType) { case (eTypeOfMove.Regular): if (m_FromSquare.Type == eSquareType.X && m_ToSquare.Row == 0) { m_ToSquare.Type = eSquareType.K; } else if (m_FromSquare.Type == eSquareType.O && m_ToSquare.Row == i_BoardGame.GetSize() - 1) { m_ToSquare.Type = eSquareType.U; } else { m_ToSquare.Type = m_FromSquare.Type; } m_FromSquare.Type = eSquareType.None; break; case (eTypeOfMove.Jump): capturePieceOnBoard(i_BoardGame); if (m_FromSquare.Type == eSquareType.X && m_ToSquare.Row == 0) { m_ToSquare.Type = eSquareType.K; } else { if (m_FromSquare.Type == eSquareType.O && m_ToSquare.Row == i_BoardGame.GetSize() - 1) { m_ToSquare.Type = eSquareType.U; } else { m_ToSquare.Type = m_FromSquare.Type; } } m_FromSquare.Type = eSquareType.None; break; } }
internal static string GetMoveFromUser(Player i_PrevioustPlayer, Player i_NextPlayer, BoardGame i_BoardGame, string i_PrevioustMove) { string message; string currentMoveString; i_BoardGame.PrintBoard(); message = string.Format("{0}'s move was ({1}): {2}{3}{4}'s turn ({5}):", i_PrevioustPlayer.Name, i_PrevioustPlayer.GetShapeType(), i_PrevioustMove, Environment.NewLine, i_NextPlayer.Name, i_NextPlayer.GetShapeType()); Console.WriteLine(message); currentMoveString = GetValidMoveString(i_BoardGame); return(currentMoveString); }
private void gameRound() { string currentMoveString; string prevMoveString; this.m_BoardGame.BuildBoard(); currentMoveString = playFirstMoveOfGame(); while (this.m_GameStatus == eGameStatus.NotFinished) { if (v_Turn) { prevMoveString = currentMoveString; currentMoveString = GameUI.GetMoveFromUser(m_Player2, m_Player1, m_BoardGame, prevMoveString); if (GameUI.IsQuitInput(currentMoveString)) { if (checkForQuitting(m_Player1, m_Player2)) { break; } else { currentMoveString = GameUI.GetMessageInvalidQuit(m_BoardGame); } } playCurrentPlayerTurn(m_Player1, m_Player2, ref currentMoveString, prevMoveString); } else { if (m_Player2.PlayerType == ePlayerType.Person) { prevMoveString = currentMoveString; currentMoveString = GameUI.GetMoveFromUser(m_Player1, m_Player2, m_BoardGame, prevMoveString); if (GameUI.IsQuitInput(currentMoveString)) { if (checkForQuitting(m_Player2, m_Player1)) { break; } else { currentMoveString = GameUI.GetMessageInvalidQuit(m_BoardGame); } } playCurrentPlayerTurn(m_Player2, m_Player1, ref currentMoveString, prevMoveString); } else { playComputerTurn(ref currentMoveString); } checkGameStatus(); } } if (GameUI.checkForAnotherGameRound()) { v_Turn = true; this.m_GameStatus = eGameStatus.NotFinished; short sizeOfBoard = m_BoardGame.Size; this.m_BoardGame = new BoardGame(sizeOfBoard); gameRound(); } }