/// <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); }