static void Main(string[] args) { var choice = ""; GameMenu menu = new GameMenu(); while (true) { Console.ForegroundColor = System.ConsoleColor.White; Console.WriteLine("Choose a game (or q to quit):"); menu.DisplayMenu(); choice = Console.ReadLine(); if (choice == "q") { break; } switch (choice) { case ("1"): var game = new NumberGuessGame(); game.StartGame(); break; default: Console.WriteLine("Make a selection, or type 'q' to quit."); break; } } }
static void Main(string[] args) { PrintIntroduction(); Task task = NumberGuessGame.Timer(10); bool isGameOver = false; task.ContinueWith((task) => isGameOver = true); int guess = -1; while (!isGameOver) { string guessStr = Console.ReadLine(); try { guess = Int32.Parse(guessStr); } catch (Exception e) { } if (guess == hiddenNumber) { isGameOver = true; } else { Console.WriteLine("Wrong! try again"); } } Console.Clear(); if (guess == hiddenNumber) { Console.WriteLine("Lmao you are good, you won!"); } else { Console.WriteLine("Lmao you ran out of time and you suck, you lost."); } Console.WriteLine($"BTW the number was {hiddenNumber}"); }
private static int SetupGame() { int difficulty = 0; while (!(difficulty > 0 && difficulty < 6)) { Console.WriteLine("Let's star off by setting the difficulty. Choose a difficulty between 1-5"); try { difficulty = Int32.Parse(Console.ReadLine()); } catch (Exception e) { difficulty = 0; } } int maxNum = 11 * difficulty; hiddenNumber = NumberGuessGame.GenerateNumber(1, maxNum); return(maxNum - 1); }