Example #1
0
        public void Start()
        {
            var gameLoop = new GameLoop();
            var myGame   = new NewGame();

            myGame.InitializeGame();
            gameLoop.Start(myGame);
        }
Example #2
0
        public void Start()
        {
            const int testgame = 1;
            const int realgame = 2;

            int choice;

            while (true)
            {
                Console.WriteLine("How do you want to play the game? \n{0} = Test \n{1} = Fun", testgame, realgame);
                string input     = Console.ReadLine();
                bool   isInteger = int.TryParse(input, out choice);

                if (isInteger)
                {
                    if (choice == testgame || choice == realgame)
                    {
                        break;
                    }
                }

                Console.Clear();
                Console.WriteLine("Not a valid input");
            }

            var gameLoop = new GameLoop();
            var db       = new DataBase("words.txt");
            var myGame   = new NewGame(db);

            if (choice == testgame)
            {
                Console.WriteLine("What is your test word?");
                myGame.TheWord = Console.ReadLine();
            }

            Console.Clear();
            gameLoop.Start(myGame);
        }
Example #3
0
        public void Start(NewGame game)
        {
            //Display GameGUI = new Display();
            //Display.updateDisplay();

            //bool done = false;
            //while(!done)
            //{

            //Menu titlescreen = new Menu()

            //Menu.Start()



            string tempinput   = "";
            string lettersUsed = "";
            string message     = "";

            int    guessesLeft = 5;
            bool   done        = false;
            string _theword    = game.myWord.theWord;

            StringBuilder sbBlanks = new StringBuilder();

            for (int i = 0; i < _theword.Length; i++)
            {
                sbBlanks.Append("_");
            }

            Console.WriteLine("Welcome to Hangman! The word is {0} letters long. Make your best guess!", _theword.Length);

            while (!done)
            {
                Console.WriteLine(message);
                Console.WriteLine("word: {0}", _theword);
                Console.WriteLine(" {0}", sbBlanks.ToString());
                Console.WriteLine("Previous Guesses: {0}", lettersUsed);
                Console.WriteLine("Guesses Left: {0}", guessesLeft + 1);
                Console.WriteLine("Guess: ");

                tempinput = Console.ReadLine();
                if (tempinput.Length < 1)
                {
                    Console.Clear();
                    continue;
                }
                tempinput = tempinput[0].ToString();

                if (lettersUsed.Contains(tempinput))
                {
                    message = "Already guessed that!";
                }

                else if (_theword.Contains(tempinput))
                {
                    message      = "YAY";
                    lettersUsed += tempinput;
                    int letterindex = 0;
                    //var indeces = new List<int>;

                    for (int i = 0; i < _theword.Length; i++)
                    {
                        letterindex = _theword.IndexOf(tempinput, i);
                        if (letterindex >= 0)
                        {
                            i           = letterindex;
                            sbBlanks[i] = tempinput[0];
                        }
                    }

                    if (!sbBlanks.ToString().Contains("_"))
                    {
                        // Console.Clear();
                        Console.WriteLine("You win!!!");
                        done = true;
                        break;
                    }
                }
                else
                {
                    message      = "BOO";
                    lettersUsed += tempinput;

                    Console.WriteLine("Guesses Left: {0}", guessesLeft);

                    if (guessesLeft == 0)
                    {
                        Console.Clear();
                        Console.WriteLine("You lose!!");
                        done = true;
                        break;
                    }
                    guessesLeft--;
                }
                Console.Clear();
            }

            Console.ReadLine();
        }
Example #4
0
        public void Start(NewGame game)
        {
            var gameState      = new GameState(game.TheWord);
            var guessValidator = new GuessValidator();
            var display        = new Display();

            Console.WriteLine("Welcome to Hangman! \nThe word is {0} letters long. \nMake your best guess!", gameState.TheWord.Length);

            //Console.WriteLine("     0 \n    -|- \n    / \\   ");

            SoundPlayer player = new SoundPlayer(@"C:\Users\david.platillero\Documents\Visual Studio 2012\Projects\HangJohn\HangMan_Console\POL-cactus-land-short.wav");

            player.PlayLooping();

            bool done = false;

            while (!done)
            {
                Console.Write("Guess: ");
                var currentGuess = Console.ReadLine();

                if (!guessValidator.Valid(currentGuess))
                {
                    Console.WriteLine("Not a valid input");
                    continue;
                }

                currentGuess = guessValidator.getValidatedString(currentGuess);
                var whatHappened = gameState.ProcessGuess(currentGuess);
                Console.Clear();

                switch (whatHappened)
                {
                case WhatHappened.Correct:
                    Console.WriteLine("Correct!");
                    break;

                case WhatHappened.Duplicate:
                    Console.WriteLine("You already guessed that!");
                    break;

                case WhatHappened.Incorrect:
                    Console.WriteLine("Bummer... that's not in the word!");
                    break;

                case WhatHappened.Lose:
                    Console.WriteLine("You Lose :( \nThe word was {0} \n{1}", gameState.TheWord, display.FullMan);
                    done = true;
                    break;

                case WhatHappened.Win:
                    Console.WriteLine("You Win! :) \nThe word was {0}", gameState.TheWord);
                    done = true;
                    break;
                }

                if (!done)
                {
                    display.Update(gameState);
                }
            }

            Console.ReadLine();
        }