Ejemplo n.º 1
0
            public static void GameLoop()
            {
                int    exactMatch   = 0;
                int    partialMatch = 0;
                int    hint         = 1;
                bool   gameOver     = false;
                string guessString;
                Phrase actual = new Phrase();

                while (!gameOver)
                {
                    Console.Write("Enter your guess: ");
                    guessString = Console.ReadLine();

                    if (guessString == "hint")
                    {
                        string padding = new string('-', Phrase.PhraseSize - hint);
                        Console.WriteLine("{0}{1}", actual.Value.Substring(0, hint), padding);

                        // begin -- for debugging only
                        Console.WriteLine("{0} G x {1}", actual.Value, actual.Count.G);
                        Console.WriteLine("{0} A x {1}", actual.Value, actual.Count.A);
                        Console.WriteLine("{0} T x {1}", actual.Value, actual.Count.T);
                        Console.WriteLine("{0} C x {1}", actual.Value, actual.Count.C);
                        // end -- for debugging only

                        if (hint < Phrase.PhraseSize)
                        {
                            hint++;
                        }

                        else
                        {
                            Console.WriteLine("No more hints! Game Over.");
                            gameOver = true;
                        }
                    }

                    else
                    {
                        Phrase guess = new Phrase(guessString);
                        if (!actual.Compare(guess, out exactMatch, out partialMatch))
                        {
                            Console.WriteLine("You have {0} exact and {1} partial matches. Try again.", exactMatch, partialMatch);
                        }

                        else
                        {
                            Console.WriteLine("Congratulations! You Win!");
                            gameOver = true;
                        }
                    }
                }
            }
Ejemplo n.º 2
0
            public static void GameLoop()
            {
                int exactMatch = 0;
                int partialMatch = 0;
                int hint = 1;
                bool gameOver = false;
                string guessString;
                Phrase actual = new Phrase();

                while (!gameOver)
                {
                    Console.Write("Enter your guess: ");
                    guessString = Console.ReadLine();

                    if (guessString == "hint")
                    {
                        string padding = new string('-', Phrase.PhraseSize - hint);
                        Console.WriteLine("{0}{1}", actual.Value.Substring(0, hint), padding);

                        // begin -- for debugging only
                        Console.WriteLine("{0} G x {1}", actual.Value, actual.Count.G);
                        Console.WriteLine("{0} A x {1}", actual.Value, actual.Count.A);
                        Console.WriteLine("{0} T x {1}", actual.Value, actual.Count.T);
                        Console.WriteLine("{0} C x {1}", actual.Value, actual.Count.C);
                        // end -- for debugging only

                        if (hint < Phrase.PhraseSize)
                        {
                            hint++;
                        }

                        else
                        {
                            Console.WriteLine("No more hints! Game Over.");
                            gameOver = true;
                        }
                    }

                    else
                    {
                        Phrase guess = new Phrase(guessString);
                        if (!actual.Compare(guess, out exactMatch, out partialMatch))
                        {
                            Console.WriteLine("You have {0} exact and {1} partial matches. Try again.", exactMatch, partialMatch);
                        }

                        else
                        {
                            Console.WriteLine("Congratulations! You Win!");
                            gameOver = true;
                        }

                    }

                }
            }