Beispiel #1
0
        public static void EstimateScore(Word secretWord, int numberOfMistakes)
        {
            bool isNewTopScore = Scoreboard.ScoreboardInstance.IsNewTopScore(numberOfMistakes);
            string comment = numberOfMistakes == 1 ? " mistake" : " mistakes";

            Console.WriteLine("The secret word is " + secretWord.MaskedWord);
            Console.Write("\nYou won with " + numberOfMistakes + comment);

            if (!usedHelp && isNewTopScore)
            {
                Console.Write("\nPlease enter your name for the top scoreboard: ");

                string newTopPlayerName = Console.ReadLine();
                Player newTopPlayer = new Player(newTopPlayerName, numberOfMistakes);

                Scoreboard.ScoreboardInstance.AddPlayer(newTopPlayer);

                ShowScoreboard();
            }
            else if (!isNewTopScore)
            {
                Console.Write(" but your result is lower than top scores\n");
            }
            else
            {
                Console.Write(" but you have cheated. You are not allowed to enter into the scoreboard.\n");
            }

            usedHelp = false;
        }
 private static void Help(Word Game)
 {
     Console.WriteLine("OK, I reveal for you the next letter " + "\""
                        + Game.GetPlayedWord()[Game.GetPrintedWord().IndexOf('_') / 2] + "\"");
     int FirstMissingLetter = Game.GetPrintedWord().IndexOf('_');
     Game.WriteTheLetter(Game.GetPlayedWord()[FirstMissingLetter / 2]);
     NotUseHelp = false;
 }
Beispiel #3
0
		public void WordIndexOfLetter()
		{
			char letter = 't';

            Word word = new Word();

			int letterIndex = word.NumberOfLetterOccurrences(letter);

			Assert.IsNotNull(letterIndex);
		}
Beispiel #4
0
		public void TheLetterAsSomeChar()
		{
			char letter = '%';

            Word word = new Word();

			bool hasLetter = word.ContainsLetter(letter);

			Assert.AreEqual(hasLetter, false, "The word can't contain a char!");
		}
Beispiel #5
0
		public void WordNotContainsLetter()
		{
			char letter = 'h';

            Word word = new Word();

			bool hasLetter = word.ContainsLetter(letter);

			Assert.IsNotNull(hasLetter);
		}
Beispiel #6
0
		public void WordContainsLetter()
		{
			char letter = 'x';

            Word word = new Word();

			bool hasLetter = word.ContainsLetter(letter);

            Assert.AreEqual(hasLetter, false, "This letter isn't included in the word");
		}
Beispiel #7
0
        public static void GiveHint(Word secretWord)
        {
            int firstMissingLetter = secretWord.MaskedWord.IndexOf('_');
            char hintLetter = secretWord.SecretWord[firstMissingLetter / 2];

            Console.WriteLine("OK, I reveal for you the next letter \'{0}\'", hintLetter);

            secretWord.RevealLetterPosition(hintLetter);

            usedHelp = true;
        }
        static void Main(string[] args)
        {
            for (int playersNumber = 0; playersNumber < 6; playersNumber++)
            {
                TopPlayers[playersNumber] = DefaultTopPlayer;
            }

            Random RandomWord = new Random();

            while (true)
            {   //main loop, used to restart game automatically

                Console.Write("\nWelcome to “Hangman” game.Please try to guess my secret word.\nUse 'top' to view the top scoreboard,"
                        + "'restart' to start a new game, \n'help' to cheat and 'exit' to quit the game.\n");

                int PlayerMistakes = 0;
                string PlayedWord = Words[RandomWord.Next(0, 10)];
                System.Text.StringBuilder PrintedWord = new System.Text.StringBuilder();

                System.Text.StringBuilder InputString = new System.Text.StringBuilder();
                PrintedWord.Clear();

                for (int WordLenght = 0; WordLenght < PlayedWord.Length; WordLenght++)
                {   //makes _ _ _ _ _...
                    PrintedWord.Append("_ ");
                }

                Word WordsInGame = new Word();
                WordsInGame.SetPlayedWord(PlayedWord);
                WordsInGame.SetPrintedWord(PrintedWord);

                while (WordsInGame.GetPrintedWord().Contains('_'))
                {
                    //start new game

                    Console.WriteLine("The secret word is " + WordsInGame.GetPrintedWord());

                    Console.Write("Enter your guess: ");
                    InputString.Clear();
                    InputString.Append(Console.ReadLine());

                    if (InputString.Length == ONE_LETTER)
                    {
                        InputLetter = (InputString[0]);
                    }

                    if (InputString.Length == ONE_LETTER && WordsInGame.Isletter(char.ToLower(InputLetter)))
                    {

                        if (WordsInGame.CheckForLetter(char.ToLower(InputLetter)))
                        {
                            WordsInGame.WriteTheLetter(char.ToLower(InputLetter));
                            Console.WriteLine("Good job! You revealed " + WordsInGame.NumberOfInput(InputLetter) + " letter");
                        }
                        else
                        {
                            Console.WriteLine("Sorry! There are no unrevealed letters " + "\"" + char.ToLower(InputLetter) + "\"");
                            PlayerMistakes++;
                        }

                    }
                    else
                    {
                        bool Restart = false;

                        switch (InputString.ToString())
                        {
                            case "help": Help(WordsInGame); break;

                            case "exit": Environment.Exit(0); break;

                            case "restart": Restart = true; break;

                            case "top": Top(); break;

                            default:
                                {
                                    Console.WriteLine("Incorect input");
                                    PlayerMistakes++;
                                    break;
                                }
                        }

                        if (Restart)
                        {
                            Console.WriteLine("Game is Restarted");
                            break;
                        }
                    }

                }   //end of while

                if (!WordsInGame.GetPrintedWord().Contains('_'))
                {
                    Console.WriteLine("The secret word is " + WordsInGame.GetPrintedWord());
                    Console.Write("\nYou won with " + PlayerMistakes + " mistakes");

                    bool BetterThanLast = TopPlayers[4].PlayerScore > PlayerMistakes;
                    if (NotUseHelp && BetterThanLast)
                    {

                        Console.Write("\nPlease enter your name for the top scoreboard: ");

                        TopPlayers[GameCounter] = new TopPlayer { PlayerName = Console.ReadLine(), PlayerScore = PlayerMistakes };

                        if (GameCounter < 5)
                        {
                            GameCounter++;
                        }

                        Array.Sort(TopPlayers, (TopPlayer1, topPlayer2) => TopPlayer1.PlayerScore.CompareTo(topPlayer2.PlayerScore));
                        Top();
                    }
                    else if (!BetterThanLast)
                    {
                        Console.Write(" but your result is lower than top scores\n");
                    }
                    else
                    {
                        Console.Write(" but you have cheated. \nYou are not allowed to enter into the scoreboard.\n");
                    }

                    PlayerMistakes = 0;
                    NotUseHelp = true;
                }
            }   //end of master loop
        }
        public void GameEngineGiveHintTest()
        {
            Word word = new Word();

            GameEngine.GiveHint(word);
        }
        public void GameEngineEstimateScoreWithHelpTest()
        {
			int mistakes = 1;
            Word word = new Word();

            GameEngine.GiveHint(word);
			GameEngine.EstimateScore(word, mistakes);
        }
        public void GameEngineEstimateScoreTest()
        {
			int mistakes = 1;
            Word word = new Word();

			GameEngine.EstimateScore(word, mistakes);
        }
Beispiel #12
0
	    public void WordWriteTheLetterInHiddenWord()
	    {
		    char letter = 't';

            Word word = new Word();

			string writhedLetter = word.RevealLetterPosition(letter);

		    Assert.IsNotNull(writhedLetter);
	    }
Beispiel #13
0
		public void WordCreation()
		{
			Word word = new Word();

			Assert.IsNotNull(word);
		}
Beispiel #14
0
        static void Main(string[] args)
        {
            bool keepPlaying = true;

            while (keepPlaying)
            {
                // Intro
                Player player = new Player();
                word = new Word();
                ProgramStart();
                player.Name = GetPlayerName();
                Welcome(player.Name);
                DifficultySetup();

                // Loopa spelrundan
                while (gameContinues)
                {
                    DrawGame(player.Life);
                    char guessedLetter = GuessLetter();
                    bool guess = word.CheckLetter(guessedLetter);
                    if (guess == true)
                    {
                        Console.WriteLine("Du gissade rätt bokstav!");
                    }
                    else
                    {
                        player.Damage();
                        Console.WriteLine("Du gissade fel! Du har " + player.Life + " försök kvar!");
                    }

                    if (word.IsComplete())
                    {
                        Console.WriteLine("\n\rOrdet är [" + word.ShownWord + "]");
                        Console.WriteLine("Du vann spelet!");
                        gameContinues = false;
                    }

                    if (player.Life <= 0)
                    {
                        string gameOver = File.ReadAllText("../../../gubbe/gameover.txt");
                        Console.WriteLine(gameOver);
                        Console.WriteLine("Det rätta ordet var {0}", word.SecretWord);
                        gameContinues = false;
                    }
                }

                // Spelrundan är över
                keepPlaying = AskPlayAgain();
            }

            // Game Over
            GameEnd();
            Console.ReadLine();
        }