/// <summary> /// Господи, хватит. /// </summary> public static void Tutorial() { Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("*Press Enter to see the next step.*"); Console.ForegroundColor = ConsoleColor.Magenta; AnimatedLine.WriteLine("I choose a secret number (N digits and there are no duplicates) and ask you to guess what the number is. When you make a guess, I provide a hint with the following info:"); Console.ReadLine(); AnimatedLine.WriteLine(" -The number of 'bulls', which are digits in the guess that are in the correct position."); Console.ReadLine(); AnimatedLine.WriteLine(" -The number of 'cows', which are digits in the guess that are in your secret number but are located in the wrong position. Specifically, the non-bull digits in the guess that could be rearranged such that they become bulls."); Console.ReadLine(); Console.WriteLine(); AnimatedLine.WriteLine("Example: "); AnimatedLine.Write("My number is "); Console.ForegroundColor = ConsoleColor.Yellow; AnimatedLine.WriteLine("3459"); Console.ForegroundColor = ConsoleColor.Magenta; AnimatedLine.Write("You type "); Console.ForegroundColor = ConsoleColor.Yellow; AnimatedLine.WriteLine("3490"); Console.ForegroundColor = ConsoleColor.Magenta; Console.ReadLine(); AnimatedLine.WriteLine("I give you a hint: "); Console.ForegroundColor = ConsoleColor.Yellow; AnimatedLine.WriteLine("Bulls: 2"); AnimatedLine.WriteLine("Cows: 1"); Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Magenta; AnimatedLine.WriteLine("It means 3, 4 are 'Bulls' and 9 is a 'Cow'."); Console.ReadLine(); AnimatedLine.WriteLine("Good luck!"); Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Если ты лох, то напиши /answer вместо своего предположения"); Console.ReadLine(); Console.Clear(); Console.ForegroundColor = ConsoleColor.White; }
/// <summary> /// Void Start(bool tutorial) starts main cycle of the program and sets start values. /// </summary> /// <param name="tutorial"> bool tutorial = 1 makes program show you a tutorial scene. = 0 ignores the tutorial. </param> static void Start(bool tutorial) { Console.ForegroundColor = ConsoleColor.White; string[] phrases = new string[3] { "-Oops! It's not my number. Try another!", "-He-he. You're wrong. Try next time!", "-Loser! Maybe try another number;)" }; string line; int n = 0; int[] slot = new int[4]; Random rnd = new Random(); if (tutorial) { Game.Tutorial(); } Console.ForegroundColor = ConsoleColor.Magenta; Console.Write("Choose the amount of digits there should be in my number(1 to 9 including): "); Console.ForegroundColor = ConsoleColor.Yellow; while (!Int32.TryParse(Console.ReadLine(), out n)) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write("Choose the amount of digits there should be in my number(1 to 9 including): "); Console.ForegroundColor = ConsoleColor.Yellow; } n = (new Game(n)).N; Array.Resize(ref slot, n); Game bnc = new Game(n); bnc.Generate(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("-Lets start! Try to guess the number I choose!"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(new String('#', bnc.N)); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); // Main cycle. while (!bnc.Gameover) { Console.ForegroundColor = ConsoleColor.White; Console.Write("Type: "); Console.ForegroundColor = ConsoleColor.Yellow; line = Console.ReadLine(); if (line == "/answer") { Console.WriteLine(bnc.ToString(bnc.ToGuess)); } else { try { slot = bnc.CorrectForm(line); if (!bnc.CheckInput(slot)) { Console.WriteLine(); throw new Exception(); } else { if (bnc.Guess(slot)) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; AnimatedLine.WriteLine(String.Format("-Congratulations! Game over! You've won in {0} attempts!", bnc.Attempts)); AnimatedLine.Write("Correct answer is "); Console.ForegroundColor = ConsoleColor.Magenta; AnimatedLine.WriteLine(bnc.ToString(bnc.ToGuess) + '!'); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); AnimatedLine.WriteLine("Your attempts:"); foreach (int[] item in bnc.Steps) { Console.WriteLine(bnc.ToString(item)); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(Game.ShowState(bnc.CheckState(item))); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); } Console.ForegroundColor = ConsoleColor.White; } else { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(); AnimatedLine.WriteLine(phrases[rnd.Next() % phrases.Length]); Console.ForegroundColor = ConsoleColor.White; } } Console.Write("__________________________________________"); Console.WriteLine(); Console.WriteLine(); } catch { continue; } } } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Any button to restart!"); Console.ReadKey(); Console.Clear(); Start(false); }