예제 #1
0
파일: Game.cs 프로젝트: ofiriro3/C-ex1
        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));
            }
        }
예제 #2
0
파일: Board.cs 프로젝트: ofiriro3/C-ex1
        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());
        }