public void ExitEmptyScoreBoardTest()
 {
     using (StringWriter sw = new StringWriter())
     {
         WordGuesser wordGuesser = new WordGuesser();
         Console.SetOut(sw);
         CommandExecuter.Exit(wordGuesser);
         Assert.AreEqual<string>("Good bye!\r\n", sw.ToString());
     }
 }
 public static void Restart()
 {
     Console.WriteLine();
     string word = WordSelector.SelectRandomWord();
     //Console.WriteLine(word);
     WordInitializator.BegginingOfTheGameInitialization(word);
     WordGuesser wg = new WordGuesser() { Word = word };
     while (WordInitializator.num1 < word.Length && WordGuesser.IsExited == false)
         wg.GuessLetter();
 }
Ejemplo n.º 3
0
        private static void PlayGame(string[] words)
        {
            Random r = new Random();

            word = words[r.Next(words.Length)].ToUpper();
            WordGuesser    guesser = new WordGuesser(word);
            HashSet <char> guessed = new HashSet <char>();

            //11 rows for user info output
            gibbet = new GibbetDrawing(0, Constants.GibbetHeight + 11);

            while (guesser.ToString() != word && mistakes <= Constants.AllowedMistakes)
            {
                DrawGame(guesser, guessed, word, gibbet);

                Console.SetCursorPosition(gibbet.Location[0], gibbet.Location[1] + 2);
                Console.WriteWithGradient("Your guess: (or \"Escape\" to end) ", Color.Yellow, Color.Fuchsia, 25);
                Console.WriteLine();
                ConsoleKeyInfo letterChoice = Console.ReadKey();

                if (letterChoice.Key == ConsoleKey.Escape)
                {
                    Menu.Initialize();
                    break;
                }
                char letter = letterChoice.KeyChar.ToString().ToUpper().First();

                if (!word.Contains(letter) && !guessed.Contains(letter))
                {
                    guessed.Add(letter);
                    mistakes++;
                    gibbet.Update();
                    DrawGame(guesser, guessed, word, gibbet);
                    if (mistakes >= Constants.AllowedMistakes)
                    {
                        isWon        = false;
                        currentScore = ScoreBoard.GetScore();
                        finalScore  += currentScore;
                        DisplayResult();
                        break;
                    }
                }

                guesser.Update(letter);
                DrawGame(guesser, guessed, word, gibbet);
            }
            currentScore = ScoreBoard.GetScore();
            finalScore  += currentScore;
        }
Ejemplo n.º 4
0
        public static void Restart()
        {
            Console.WriteLine();
            string word = WordSelector.SelectRandomWord();

            //Console.WriteLine(word);
            WordInitializator.BegginingOfTheGameInitialization(word);
            WordGuesser wg = new WordGuesser()
            {
                Word = word
            };

            while (WordInitializator.num1 < word.Length && WordGuesser.IsExited == false)
            {
                wg.GuessLetter();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Displays 11 rows of user info + gibbet drawing
 /// </summary>
 /// <param name="guesser"></param>
 /// <param name="guessed"></param>
 /// <param name="word"></param>
 /// <param name="gibbet"></param>
 private static void DrawGame(WordGuesser guesser, HashSet <char> guessed, string word, GibbetDrawing gibbet)
 {
     Console.Clear();
     Console.WriteLine("----------------------------------", Color.Aquamarine);
     Console.WriteLine($"Player:{player.Name}  --  Best score:{player.Score:F0}", Color.Khaki);
     Console.WriteLine("----------------------------------", Color.Aquamarine);
     Console.WriteLine($"Current level:{gameLevel}    {Message.ChooseLetter}", Color.Khaki);
     if (!Constants.DEBUG_MODE)
     {
         Console.WriteLine($"---------DEBUG: {word}--------", Color.Aquamarine);
     }
     else
     {
         Console.WriteLine("----------------------------------", Color.Aquamarine);
     }
     Console.WriteLine();
     Console.WriteLine(guesser.ToString(), Color.CornflowerBlue);
     Console.WriteLine();
     Console.WriteLine(Message.AlreadyGuessed, Color.Yellow);
     Console.WriteLine();
     Console.WriteLine(String.Join(" ", guessed), Color.Red);
     Console.WriteLine();
     gibbet.Print();
 }