Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class _
- {
- static void StampaRiga(ConsoleColor fg, ConsoleColor bg, int r, int c, string s)
- {
- ConsoleColor vecchio_fg = Console.ForegroundColor;
- ConsoleColor vecchio_bg = Console.BackgroundColor;
- Console.ForegroundColor = fg;
- Console.BackgroundColor = bg;
- int vecchio_c = Console.CursorLeft;
- int vecchio_r = Console.CursorTop;
- Console.CursorLeft = c;
- Console.CursorTop = r;
- Console.Write(s);
- Console.CursorLeft = vecchio_c;
- Console.CursorTop = vecchio_r;
- Console.ForegroundColor = vecchio_fg;
- Console.BackgroundColor = vecchio_bg;
- }
- static void StampaRettangolo(ConsoleColor bg, int r, int c, int lung, int alt)
- {
- ConsoleColor vecchio_bg = Console.BackgroundColor;
- Console.BackgroundColor = bg;
- int n;
- string s = "";
- for (n = 0; n < lung; n = n + 1)
- {
- s = s + " ";
- }
- for (n = 0; n < alt; n = n + 1)
- {
- StampaRiga(bg, bg, r + n, c, s);
- }
- Console.BackgroundColor = vecchio_bg;
- }
- static int Main(string[] args)
- {
- Random r = new Random();
- int n = r.Next(1, 101);
- Console.Clear();
- StampaRettangolo(ConsoleColor.Blue, 0, 0, 35, 25);
- StampaRettangolo(ConsoleColor.Green, 0, 35, 45, 25);
- Console.BackgroundColor = ConsoleColor.Blue;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("Indovina il numero... tra 1 e 100");
- int nt = 0;
- bool ok = false;
- do
- {
- Console.ForegroundColor = ConsoleColor.Green;
- int t = 0;
- bool numeroCorretto = false;
- do
- {
- try
- {
- Console.Write("Scrivi un numero: ");
- string s = Console.ReadLine();
- t = int.Parse(s);
- numeroCorretto = true;
- }
- catch (Exception)
- {
- Console.WriteLine("Numero errato!");
- }
- }
- while (numeroCorretto == false);
- nt = nt + 1;
- if (t == n)
- {
- StampaRettangolo(ConsoleColor.Cyan, 12, 35, 45, 13);
- Console.BackgroundColor = ConsoleColor.Cyan;
- Console.ForegroundColor = ConsoleColor.Magenta;
- Console.CursorLeft = 36;
- Console.CursorTop = 12;
- Console.WriteLine("Hai indovinato !!");
- StampaRettangolo(ConsoleColor.Green, 0, 35, 45, 1);
- Console.CursorLeft = 36;
- Console.CursorTop = 13;
- if (nt == 1)
- Console.WriteLine("Nuovo record mondiale. Hai indovinato in 1 solo tentativo se imbattibile !!!!!!!!!!!!.");
- else if (nt <= 5)
- Console.WriteLine("Campione !! hai indovinato in {0} tentativi.", nt);
- else if (nt <= 8)
- Console.WriteLine("Bravo !! hai indovinato in {0} tentativi.", nt);
- else if (nt <= 12)
- Console.WriteLine("Benino !! hai indovinato in {0} tentativi.", nt);
- else
- Console.WriteLine("Scarso !! Sai contatare ? Hai indovinato in {0} tentativi.", nt);
- Console.Beep(600, 500);
- Console.ReadLine();
- ok = true;
- }
- else if (t < n)
- {
- StampaRiga(ConsoleColor.Red, ConsoleColor.Green, 0, 41 - 5, "Numero troppo piccolo.... ritenta");
- }
- else
- {
- StampaRiga(ConsoleColor.Red, ConsoleColor.Green, 0, 41 - 5, "Numero troppo grande.... ritenta ");
- }
- }
- while (ok == false);
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment