luca020400

Untitled

Jul 13th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1. using System;
  2.  
  3. class _
  4. {
  5.  
  6.     static void StampaRiga(ConsoleColor fg, ConsoleColor bg, int r, int c, string s)
  7.     {
  8.         ConsoleColor vecchio_fg = Console.ForegroundColor;
  9.         ConsoleColor vecchio_bg = Console.BackgroundColor;
  10.  
  11.         Console.ForegroundColor = fg;
  12.         Console.BackgroundColor = bg;
  13.  
  14.         int vecchio_c = Console.CursorLeft;
  15.         int vecchio_r = Console.CursorTop;
  16.  
  17.         Console.CursorLeft = c;
  18.         Console.CursorTop = r;
  19.  
  20.         Console.Write(s);
  21.  
  22.         Console.CursorLeft = vecchio_c;
  23.         Console.CursorTop = vecchio_r;
  24.  
  25.         Console.ForegroundColor = vecchio_fg;
  26.         Console.BackgroundColor = vecchio_bg;
  27.     }
  28.  
  29.     static void StampaRettangolo(ConsoleColor bg, int r, int c, int lung, int alt)
  30.     {
  31.         ConsoleColor vecchio_bg = Console.BackgroundColor;
  32.         Console.BackgroundColor = bg;
  33.  
  34.         int n;
  35.  
  36.         string s = "";
  37.         for (n = 0; n < lung; n = n + 1)
  38.         {
  39.             s = s + " ";
  40.         }
  41.  
  42.         for (n = 0; n < alt; n = n + 1)
  43.         {
  44.             StampaRiga(bg, bg, r + n, c, s);
  45.         }
  46.         Console.BackgroundColor = vecchio_bg;
  47.     }
  48.  
  49.     static int Main(string[] args)
  50.     {
  51.         Random r = new Random();
  52.         int n = r.Next(1, 101);
  53.         Console.Clear();
  54.         StampaRettangolo(ConsoleColor.Blue, 0, 0, 35, 25);
  55.         StampaRettangolo(ConsoleColor.Green, 0, 35, 45, 25);
  56.  
  57.         Console.BackgroundColor = ConsoleColor.Blue;
  58.         Console.ForegroundColor = ConsoleColor.Yellow;
  59.         Console.WriteLine("Indovina il numero... tra 1 e 100");
  60.  
  61.         int nt = 0;
  62.         bool ok = false;
  63.         do
  64.         {
  65.             Console.ForegroundColor = ConsoleColor.Green;
  66.             int t = 0;
  67.             bool numeroCorretto = false;
  68.             do
  69.             {
  70.                 try
  71.                 {
  72.                     Console.Write("Scrivi un numero: ");
  73.                     string s = Console.ReadLine();
  74.                     t = int.Parse(s);
  75.                     numeroCorretto = true;
  76.                 }
  77.                 catch (Exception)
  78.                 {
  79.                     Console.WriteLine("Numero errato!");
  80.                 }
  81.             }
  82.             while (numeroCorretto == false);
  83.  
  84.             nt = nt + 1;
  85.  
  86.             if (t == n)
  87.             {
  88.                 StampaRettangolo(ConsoleColor.Cyan, 12, 35, 45, 13);
  89.  
  90.                 Console.BackgroundColor = ConsoleColor.Cyan;
  91.                 Console.ForegroundColor = ConsoleColor.Magenta;
  92.                 Console.CursorLeft = 36;
  93.                 Console.CursorTop = 12;
  94.                 Console.WriteLine("Hai indovinato !!");
  95.  
  96.                 StampaRettangolo(ConsoleColor.Green, 0, 35, 45, 1);
  97.  
  98.                 Console.CursorLeft = 36;
  99.                 Console.CursorTop = 13;
  100.                 if (nt == 1)
  101.                     Console.WriteLine("Nuovo record mondiale. Hai indovinato in 1 solo tentativo se imbattibile !!!!!!!!!!!!.");
  102.                 else if (nt <= 5)
  103.                     Console.WriteLine("Campione !! hai indovinato in {0} tentativi.", nt);
  104.                 else if (nt <= 8)
  105.                     Console.WriteLine("Bravo !! hai indovinato in {0} tentativi.", nt);
  106.                 else if (nt <= 12)
  107.                     Console.WriteLine("Benino !! hai indovinato in {0} tentativi.", nt);
  108.                 else
  109.                     Console.WriteLine("Scarso !! Sai contatare ? Hai indovinato in {0} tentativi.", nt);
  110.  
  111.                 Console.Beep(600, 500);
  112.  
  113.                 Console.ReadLine();
  114.  
  115.                 ok = true;
  116.             }
  117.             else if (t < n)
  118.             {
  119.                 StampaRiga(ConsoleColor.Red, ConsoleColor.Green, 0, 41 - 5, "Numero troppo piccolo.... ritenta");
  120.             }
  121.             else
  122.             {
  123.                 StampaRiga(ConsoleColor.Red, ConsoleColor.Green, 0, 41 - 5, "Numero troppo grande.... ritenta ");
  124.             }
  125.         }
  126.         while (ok == false);
  127.  
  128.         return 0;
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment