public void Start() { eGameResult gameResult; bool isPressedQ; bool isPlayerWantAnotherRound = true; m_IO = new IOhandler(); initGame(); m_Board = new Board(Move.s_Height, Move.s_Width); m_Engine = new Engine(m_Board, m_Player1, m_Player2); while (isPlayerWantAnotherRound) { m_IO.ShowBoard(m_Board); isPressedQ = m_Engine.Run(); if (isPressedQ) { m_IO.ShowGoodByeMessage(); } else { gameResult = GetGameResult(m_Player1, m_Player2); m_IO.ShowGameResultMessage(m_Player1, m_Player2, gameResult); isPlayerWantAnotherRound = m_IO.GetStartNewGameSelection(); if (isPlayerWantAnotherRound) { m_Board = new Board(Move.s_Height, Move.s_Width); m_Engine = new Engine(m_Board, m_Player1, m_Player2); } } } m_IO.ShowGoodByeMessage(); }
public bool Run() { Player[] Players = new Player[2]; Players[0] = m_Player1; Players[1] = m_Player2; bool nextMoveIsLegal; bool currPlayerHasMoves = true; bool nextPlayerHasMoves = true; Move nextMove = m_IO.GetNextMove(Players[0]); bool nextMoveIsQuit = nextMove.IsQuitMove(); while (!nextMoveIsQuit && (currPlayerHasMoves || nextPlayerHasMoves)) { if (Players[0].Type == Player.ePlayerType.Player) { nextMoveIsLegal = CheckIfMoveIsLegal(nextMove, Players[0]); } else { nextMove = acheiveOneLegalMoveOfComputer(Players[0]); nextMoveIsLegal = true; } if (nextMoveIsLegal) { m_Board.UpdateBoardCauseLegalMove(nextMove, Players[0].Color); m_IO.ClearScreen(); m_IO.ShowBoard(m_Board); nextPlayerHasMoves = PlayerHasAnyValidMoves(Players[1]); if (nextPlayerHasMoves) { swapPlayers(Players); } else { m_IO.ShowNoAvailbleMovesForPlayer(Players[1].PlayerName); } } else { m_IO.ShowIllegalMoveMessage(); } currPlayerHasMoves = PlayerHasAnyValidMoves(Players[0]); if (currPlayerHasMoves && Players[0].Type == Player.ePlayerType.Player) { nextMove = m_IO.GetNextMove(Players[0]); } nextMoveIsQuit = nextMove.IsQuitMove(); } m_Player1.Score = m_Board.AmountOfColorInBoard(m_Player1.Color); m_Player2.Score = m_Board.AmountOfColorInBoard(m_Player2.Color); return(nextMoveIsQuit); }