// initialize game score and give the turn to player for next round private void initializeGame() { m_PlayerTurn = true; m_IsFirstTurn = true; m_ScoreOfOpponent = 0; m_ScoreOfPlayer = 0; m_TotalScore = 0; // this part is in charge of getting the board size from the user int numOfRows = 0; int numOfColumns = 0; GameUserInterface.SetBoardSize(ref numOfRows, ref numOfColumns); m_Game = new MemoryGameLogic(numOfRows, numOfColumns, m_AgainstComputer); m_Game.GenerateRandomizedBoard(); clearAndPrint(); }
// interacts with the player and require from the player a legal input of a cell to reveal // handle illegal input such as, out of bound of the board, a cell that is already exposed internal static Tuple <int, int> PlayerTurn(string i_NameOfPlayer, MemoryGameLogic i_Game, ref bool io_WantsToQuit) { string answerToCheck = Console.ReadLine(); io_WantsToQuit = answerToCheck.Equals("Q"); bool isValidInput = i_Game.IsValidInputCell(answerToCheck); bool isValidRange = isValidInput && i_Game.IsValidRangeForCell(answerToCheck); bool isValidCell = isValidRange && i_Game.IsValidCell(answerToCheck); while (!io_WantsToQuit && (!isValidInput || !isValidRange || !isValidCell)) { if (io_WantsToQuit) { break; } else { if (!isValidInput) { Console.WriteLine("Invalid input, please try again"); } else if (!isValidRange) { Console.WriteLine("Invalid range input, please try again"); } else if (!isValidCell) { Console.WriteLine("The cell you choose is already exposed, please try another one"); } answerToCheck = Console.ReadLine(); io_WantsToQuit = answerToCheck.Equals("Q"); isValidInput = i_Game.IsValidInputCell(answerToCheck); isValidRange = isValidInput && i_Game.IsValidRangeForCell(answerToCheck); isValidCell = isValidRange && i_Game.IsValidCell(answerToCheck); } } // default value won't be used if io_WantToQuit = true Tuple <int, int> retPair = new Tuple <int, int>(0, 0); if (!io_WantsToQuit) { retPair = new Tuple <int, int>(answerToCheck[1] - k_FirstRowIndex, answerToCheck[0] - k_FirstColumnIndex); } return(retPair); }