private void showComputerPicks() { m_DataBoard.AddSignToRealTimeBoard(m_FirstSquareChoice); MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard); m_DataBoard.AddSignToRealTimeBoard(m_SecondSquareChoice); MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard); }
private void startRound() { int boardHeight = 0, boardWidth = 0; MessageOrganizer.ClearScreen(); MessageOrganizer.HandleBoardSize(ref boardHeight, ref boardWidth); m_DataBoard = new ModelBoard(boardHeight, boardWidth); }
private void endRound(string i_WinnerName) { MessageOrganizer.WinMessage(i_WinnerName, m_EndGameState); // end the round: m_IsRoundRuning = false; m_GameStillRuning = MessageOrganizer.ReplayGame(); }
private void playerSquarePick(Position io_SquareChoice) { StringBuilder squareToRevelaStr = new StringBuilder(MessageOrganizer.ChooseSquareToReveal(m_DataBoard.BoardHeight, m_DataBoard.BoardWidth)); squareStrToCoordinates(squareToRevelaStr.ToString(), io_SquareChoice); // checks if the choosen square is taken while (!m_DataBoard.IsSquareAvailable(io_SquareChoice)) { MessageOrganizer.TakenSquareMsg(); squareToRevelaStr.Replace(squareToRevelaStr.ToString(), MessageOrganizer.ChooseSquareToReveal(m_DataBoard.BoardHeight, m_DataBoard.BoardWidth)); squareStrToCoordinates(squareToRevelaStr.ToString(), io_SquareChoice); } m_DataBoard.AddSignToRealTimeBoard(io_SquareChoice); MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard); }
public void PlayGame() { // Start of the game m_GameStillRuning = true; m_MainPlayer = new Player(MessageOrganizer.EnterName()); m_IsVersusComputer = (MessageOrganizer.ChooseOpponent() == 2); // checks which opponent is selected // starts the game that's fit for the choosen opponent: if (m_IsVersusComputer) { playerVsComputer(); } else { playerVsPlayer(); } MessageOrganizer.exitGame(); }
private void playerVsPlayer() { Player secondPlayer = new Player(MessageOrganizer.EnterName()); while (m_GameStillRuning) { Player currentPlayer = m_MainPlayer; m_IsRoundRuning = true; m_MainPlayer.Score = secondPlayer.Score = 0; startRound(); while (m_IsRoundRuning) { MessageOrganizer.TurnMsg(currentPlayer.Name); MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard); playerPairPick(); if (m_DataBoard.IsIdenticalPair(m_FirstSquareChoice, m_SecondSquareChoice)) { currentPlayer.Score++; if (checkFullBoard(m_MainPlayer.Score, secondPlayer.Score)) { string winnerName = gameWinner(secondPlayer.Name, secondPlayer.Score); endRound(winnerName); } } else { m_DataBoard.RemovePairFromRealTimeBoard(m_FirstSquareChoice, m_SecondSquareChoice); currentPlayer = currentPlayer == m_MainPlayer ? secondPlayer : m_MainPlayer; System.Threading.Thread.Sleep(2000); // if its not a matched pair let the viewers see the board for additonal second(2 second total) } } } }
private void playerVsComputer() { while (m_GameStillRuning) { m_MainPlayer.Score = 0; bool isMainPlayerTurn = true; m_IsRoundRuning = true; Computer aiComputer; startRound(); aiComputer = new Computer(m_DataBoard.BoardHeight, m_DataBoard.BoardWidth); // turns start: while (m_IsRoundRuning) { if (isMainPlayerTurn) { MessageOrganizer.TurnMsg(m_MainPlayer.Name); } else { MessageOrganizer.TurnMsg(); } MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard); if (isMainPlayerTurn) { playerPairPick(); } else // COMPUTER AI PICK { aiComputer.PickPair(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice); showComputerPicks(); } if (m_DataBoard.IsIdenticalPair(m_FirstSquareChoice, m_SecondSquareChoice)) { if (isMainPlayerTurn) { aiComputer.UpdateMemory(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice, true); m_MainPlayer.Score++; } else { aiComputer.Score++; } if (checkFullBoard(m_MainPlayer.Score, aiComputer.Score)) { string winnerName = gameWinner(string.Empty, aiComputer.Score); endRound(winnerName); } } else { aiComputer.UpdateMemory(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice, false); m_DataBoard.RemovePairFromRealTimeBoard(m_FirstSquareChoice, m_SecondSquareChoice); isMainPlayerTurn = !(isMainPlayerTurn); System.Threading.Thread.Sleep(2000); // if its not a matched pair let the viewers see the board for additonal second(2 second total) } } } }