void ColorDefiner(LingoGame lingo, string userWord) { lingo.InitLingo(lingo.lingoWord); LetterState[] allletters = new LetterState[userWord.Length]; List <char> list = new List <char>(); for (int i = 0; i < userWord.Length; i++) { if (lingo.lingoWord[i] != userWord[i]) { list.Add(lingo.lingoWord[i]); } } for (int i = 0; i < userWord.Length; i++) { if (lingo.lingoWord[i] == userWord[i]) { allletters[i] = LetterState.Correct; } else if (list.Contains(userWord[i])) { allletters[i] = LetterState.WrongPosition; list.Remove(userWord[i]); } else { allletters[i] = LetterState.Incorrect; } } ColorPrinter(allletters, userWord); Console.WriteLine(); }
string UserInput(LingoGame lingo) { string userword = ""; do { userword = MyTools.ReadTools.ReadString("Please enter a (5 letter)word : "); } while (lingo.lingoWord.Length != userword.Length); return(userword); }
public bool isGuessed(LingoGame game, string playerword) { bool isguessed; if (game.lingoWord == playerword) { isguessed = true; } else { isguessed = false; } return(isguessed); }
bool PlayLingo(LingoGame lingo) { bool isRoundWin = false; int nrOfAttempts = 5; string playerWord = ""; while (nrOfAttempts > 0 && lingo.isGuessed(lingo, playerWord) == false) { playerWord = UserInput(lingo); ColorDefiner(lingo, playerWord); if (lingo.isGuessed(lingo, playerWord) == true) { isRoundWin = true; } else { nrOfAttempts--; Console.WriteLine("You have {0} attempts left", nrOfAttempts); } } return(isRoundWin); }
void Start() { LingoGame Lingo = new LingoGame(); string filename = "words.txt"; List <string> lingoWords = Reader(filename); SecretwordInit(ref lingoWords, ref Lingo); if (PlayLingo(Lingo) == true) { Console.WriteLine("\nSecret word was {0}", Lingo.lingoWord); Console.WriteLine("\n\nYou won! Congratz!"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nSecret word was {0}", Lingo.lingoWord); Console.WriteLine("\n\nBetter luck next time!!"); Console.ResetColor(); } Console.ReadKey(); }
void SecretwordInit(ref List <string> words, ref LingoGame Lingo) { Random rnd = new Random(); Lingo.lingoWord = words[rnd.Next(0, words.Count)]; }