Esempio n. 1
0
        /// <summary>
        /// Load game resources
        /// </summary>
        public static void LoadGameResources()
        {
            // load resources
            Gallows.LoadGallowsDrawing();

            // define game difficulties
            Difficulties.Add(new GameDifficulty
            {
                Level             = 1,
                Name              = "Mineur",
                MinimumWordLength = 0,
                GallowsParts      = new List <string>()
                {
                    "1", "2", "3", "4", "a", "b", "c", "d", "e", "f"
                }
            });
            Difficulties.Add(new GameDifficulty
            {
                Level             = 2,
                Name              = "Majeur",
                MinimumWordLength = 5,
                GallowsParts      = new List <string>()
                {
                    "12", "34", "a", "b", "cd", "ef"
                }
            });
            Difficulties.Add(new GameDifficulty
            {
                Level             = 3,
                Name              = "Terrible",
                MinimumWordLength = 6,
                GallowsParts      = new List <string>()
                {
                    "1234", "a", "bcd", "ef"
                }
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if character submitted by player is in mystery word
        /// and if end of game (victory or defeat) is triggered
        /// </summary>
        /// <param name="Character">Character submitted by player</param>
        /// <returns>True or False (end of game)</returns>
        public static bool CheckCharacterAndEndOfGame(
            string Character)
        {
            // add submitted character to used character list
            // if not already in list
            if (!UsedCharacters.Contains(Character))
            {
                UsedCharacters.Add(Character);
            }

            // check if submitted character is in mystery word
            if (Word.MysteryWord.Contains(Character))
            {
                // character is in mystery word
                // replace each character in hidden word
                // with matching character submitted by player

                // transform words in char arrays
                char[] CharactersInMysteryWord = Word.MysteryWord.ToCharArray();
                char[] CharactersInHiddenWord  = Word.HiddenWord.ToCharArray();

                // browse chhosen word char array to compare with submitted character
                for (int Index = 0; Index < Word.MysteryWord.Length; Index++)
                {
                    // character exists at that place in mystery word
                    // so put it at the same place in hidden word
                    if (CharactersInMysteryWord[Index] == char.Parse(Character))
                    {
                        CharactersInHiddenWord[Index] = char.Parse(Character);
                    }
                }

                // rebuild HiddenWord string from char array
                Word.HiddenWord = string.Join("", CharactersInHiddenWord);

                // check victory
                if (CheckVictory())
                {
                    // victory is triggered
                    // show mysterious word
                    Word.DisplayHiddenWord();

                    // show message
                    Utilities.WriteRichText(
                        "Bravo, vous êtes innocent, vous échappez donc à la potence !",
                        2,
                        20,
                        ConsoleColor.Green);

                    // save score
                    Utilities.SaveScore("GAGNÉ");

                    // this is the end of the game
                    return(true);
                }
            }
            else
            {
                // character is not in mystery word

                // increment number of errors
                NumberOfErrors++;

                // draw gallow part matching number of errors
                Gallows.DrawGallows(
                    CurrentDifficulty.GallowsParts[NumberOfErrors - 1]);

                // check defeat
                if (CheckDefeat())
                {
                    // defeat is triggered
                    // show mysterious word
                    Word.HiddenWord = Word.MysteryWord;
                    Word.DisplayHiddenWord();

                    // show message
                    Utilities.WriteRichText(
                        "Dommage, retenez la leçon pour votre prochaine vie !",
                        2,
                        20,
                        ConsoleColor.Red);

                    // save score
                    Utilities.SaveScore("PERDU");

                    // this is the end of the game
                    return(true);
                }
            }

            // refresh screen by displaying game data
            Word.DisplayHiddenWord();
            DisplayPossibleCharacters();

            // this is not the end of the game
            return(false);
        }