public void Run() { Ex02.ConsoleUtils.Screen.Clear(); Board.PrintBoard(null, r_LengthOfGuess, m_NumberOfTotalGuesses); m_GameResult = eGameResult.StillPlaying; while (m_NumOfLeftGuesses > 0) { string verifiedInputString = VerifyInputFromUser(); if (verifiedInputString.Equals("Q")) { m_GameResult = eGameResult.Abort; break; } eGuessLetter[] currentGuess = getVerifyInputFromUser(verifiedInputString); Turn currentTurn = new Turn(m_ComputerAnswer, currentGuess); int cellToAddCurrentTurn = m_NumberOfTotalGuesses - m_NumOfLeftGuesses; m_TurnArray[cellToAddCurrentTurn] = currentTurn; Ex02.ConsoleUtils.Screen.Clear(); Board.PrintBoard(m_TurnArray, r_LengthOfGuess, m_NumberOfTotalGuesses); if (currentTurn.IsCorrect()) { m_GameResult = eGameResult.Win; break; } m_NumOfLeftGuesses--; } if (m_NumOfLeftGuesses == 0) { m_GameResult = eGameResult.Loss; Board.WriteLine(string.Format("The real soultion was {0} , sorry maybe next time.", m_ComputerAnswerStringFormat)); } }
private static string buildTurnLine(Turn i_Turn) { eGuessLetter[] guessLetters = i_Turn.GuessLetters; eGuessResult[] guessResults = i_Turn.GuessResults; StringBuilder turnLine = new StringBuilder(); turnLine.Append('|'); for (int i = 0; i < i_Turn.LengthOfGuess; i++) { turnLine.Append(' '); turnLine.Append(guessLetters[i]); } turnLine.Append(' '); turnLine.Append('|'); for (int i = 0; i < i_Turn.LengthOfGuess; i++) { if (guessResults[i] == eGuessResult.WrongGuess) { turnLine.Append(' '); } else { turnLine.Append(guessResults[i]); } if (i < i_Turn.LengthOfGuess - 1) { turnLine.Append(' '); } } turnLine.Append('|'); return(turnLine.ToString()); }