Aslai

Guess My Number

Feb 5th, 2012
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7.  
  8. namespace NumberGuesser
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             String[] lessthan = { "<", "less", "under", "less than", "less then", "small", "smaller", "lower", "low", "go lower", "down" };
  15.             String[] morethan = { ">", "more", "over", "more than", "more then", "big", "bigger", "higher", "high", "go higher", "up" };
  16.             String[] equalthan = { "=", "==", "yes", "equal", "exactly", "correct", "right", "perfect", "great", "excellent", "indeed", "equal to" };
  17.             String[] affirmative = { "yes", "y", "ye", "yea", "sure", "ok", "okay", "why not", "affirmative", "alright", "I guess", "please" };
  18.             String[] negative = { "no", "nah", "nope", "naw", "argh", "negative" };
  19.  
  20.  
  21.  
  22.             Console.WriteLine("Welcome, {0}", Environment.UserName);
  23.             while (true)
  24.             {
  25.                 Console.WriteLine("Please guess a number between 1 and 100 (but don't tell me!)");
  26.                 Console.WriteLine("Press any key when you're ready...");
  27.                 Console.ReadKey(true);
  28.                 int guess = 50;
  29.                 int guesses = 0;
  30.                 int off = 25;
  31.                 Console.Write("I");
  32.                 while (true)
  33.                 {
  34.                     Console.Write("s it greater than, equal to or less than");
  35.                     Thread.Sleep(400);
  36.                     Console.Write(".");
  37.                     Thread.Sleep(400);
  38.                     Console.Write(".");
  39.                     Thread.Sleep(400);
  40.                     Console.Write(".");
  41.                     Thread.Sleep(1000);
  42.                     Console.WriteLine(" {0}?", guess);
  43.                     String response = Console.ReadLine();
  44.                     int cont = 0;
  45.                     foreach (String ans in lessthan)
  46.                     {
  47.                         if (response.ToLower().Contains(ans))
  48.                         {
  49.                             guess -= off;
  50.                             off /= 2;
  51.                             cont = 1;
  52.  
  53.                             ++guesses;
  54.                             break;
  55.                         }
  56.                     }
  57.                     if (cont == 0)
  58.                     {
  59.                         foreach (String ans in morethan)
  60.                         {
  61.                             if (response.ToLower().Contains(ans))
  62.                             {
  63.                                 guess += off;
  64.                                 off /= 2;
  65.                                 cont = 1;
  66.                                 ++guesses;
  67.                                 break;
  68.                             }
  69.                         }
  70.                     }
  71.                     if (off == 0) off = 1;
  72.                     if (cont == 0)
  73.                     {
  74.                         foreach (String ans in equalthan)
  75.                         {
  76.                             if (response.ToLower().Contains(ans))
  77.                             {
  78.                                 cont = 2;
  79.                                 break;
  80.                             }
  81.                         }
  82.                     }
  83.                     switch (cont)
  84.                     {
  85.                         case 0:
  86.                             Console.Write("I don't understand what you just said!\nI");
  87.                             break;
  88.                         case 1:
  89.                             Console.Write("If it's not that, then i");
  90.                             break;
  91.                         case 2:
  92.                             ++guesses;
  93.                             Console.WriteLine("\n\nSo your number was {0}, eh? You never stood a chance. It only took me {1} guesse{2}!", guess, guesses, guesses == 1 ? "" : "s");
  94.                             break;
  95.                     }
  96.                     if (cont == 2)
  97.                         break;
  98.                 }
  99.                 Console.WriteLine("\n\n\nWould you like to play again?");
  100.  
  101.                 int status = 0;
  102.                 do
  103.                 {
  104.                     String resp = Console.ReadLine();
  105.                     foreach (String ans in affirmative)
  106.                     {
  107.                         if (resp.ToLower().Contains(ans))
  108.                         {
  109.                             Console.Clear();
  110.                             Console.WriteLine("Okay!\n\n");
  111.                             status = 1;
  112.                             break;
  113.                         }
  114.                     }
  115.                     if (status == 0)
  116.                     {
  117.                         foreach (String ans in negative)
  118.                         {
  119.                             if (resp.ToLower().Contains(ans))
  120.                             {
  121.                                 Console.WriteLine("Alright, I'll see you around!\n\n\t(Press any key)");
  122.                                 status = 2;
  123.                                 break;
  124.                             }
  125.                         }
  126.                     }
  127.                     if (status != 0)
  128.                         break;
  129.                     Console.WriteLine("I'm sorry, what do you mean?");
  130.                 } while (true);
  131.                 if (status == 2) break;
  132.             }
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment