public void Play() { // Reset Variables Player.Guesses = 7; Player.Won = false; // Add difficulty multiplier later CorrectNumber = rand.Next(MinGuess, MaxGuess); Console.WriteLine(CorrectNumber); // As long as the player has guesses, guess. while (Player.Guesses > 0 && !Player.Won) { // Determine if the guess is actually valid. bool invalidGuess = true; while (invalidGuess) { Fancy.Write($"\t({Player.Guesses} left) Guess a number: "); string guess = Fancy.ReadLine(ConsoleColor.Green).ToLower(); EvaluateGuess(guess, out invalidGuess); } } if (Player.Won) { Fancy.Write("\nWell done! ", afterPause: 500); Player.Won = true; Player.Win++; Player.Plays++; int scoreGained = (Player.Guesses + 1) * (int)Diff; Fancy.Write("You got " + scoreGained + " points! Here are your stats:\n", color: ConsoleColor.Green); Player.Score += scoreGained; } else { Fancy.Write("\nYou lost. It happens to the best of us....\n", afterPause: 750); Player.Won = false; Player.Loss++; Player.Plays++; } Player.ShowAll(); GameIO.SaveGame(Player, Diff); // Save the game. Fancy.Write("\nDo you want to play again? (y or n) "); string answer = Fancy.ReadLine(ConsoleColor.Cyan); if (answer != "y") { Player.IsPlaying = false; } }
// Peice of code that returns the difficulty that the player chooses. public static int AskForDifficulty() { try { int difficulty = Convert.ToInt32(Fancy.ReadLine(ConsoleColor.Red)); if (difficulty <= 0 || difficulty >= 5) { throw new FormatException(); } Fancy.Write("Going with " + SetDifficulty(difficulty) + " difficulty"); return(difficulty); } catch (FormatException) { int difficulty = 2; Fancy.Write("That is not a valid difficulty. I'll just set you at " + SetDifficulty(difficulty) + "\n", afterPause: 500); return(difficulty); } }