Jujuv

[C# | Fun] Plus ou moins

Nov 27th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. /* En hommage au respect et à la logique, tués tragiquement par Guillaume "Baka-Masteru" Dupont
  8.  * ce 13 Novembre 2015 lors d'une session de test du jeu "Plus ou moins".
  9.  * Les témoins racontent que l'horrible individu aurais tenter de rentrer son nombre min bien
  10.  * trop gros pour le nombre max de sa victime. */
  11. namespace Game_plus_moins
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             bool mKeep = true;
  18.             do
  19.             {
  20.                 Console.WriteLine("------------[MENU]------------");
  21.                 Console.WriteLine("1) Lancer le jeu");
  22.                 Console.WriteLine("2) Quitter");
  23.  
  24.                 switch(Console.ReadLine())
  25.                 {
  26.                     case "1": Game(); mKeep = false;  break;
  27.                     case "2": mKeep = false; break;
  28.                     default: Console.WriteLine("[ERREUR] Saisie invalide"); break;
  29.                 }
  30.             } while (mKeep);
  31.         }
  32.  
  33.         static void Game(int min = -1, int max = -2)
  34.         {
  35.             bool won = false;
  36.             int nbTours = 0;
  37.             Random rnd = new Random();
  38.  
  39.             if (min == -1 && max == -2)
  40.             {
  41.                 Console.WriteLine("[INFO] Choisir un nombre max");
  42.                 max = Convert.ToInt16(Console.ReadLine());
  43.                 Console.WriteLine("[INFO] Choisir un nombre min");
  44.                 min = Convert.ToInt16(Console.ReadLine());
  45.             }
  46.  
  47.  
  48.             if (min >= max)//Sécurité Anti-Guillaume (aka "Baka-Masteru")
  49.             {
  50.                 Console.WriteLine("[ERREUR] BAKA ! - Min ne peut être suppérieur ou égale à max");
  51.                 Game();
  52.             }
  53.  
  54.             int target = rnd.Next(min, max + 1);
  55.             Console.WriteLine("[INFO] Saisir un nombre entre {0} et {1}", min, max);
  56.  
  57.             while(!won)
  58.             {
  59.                 int uInput = Convert.ToInt32(Console.ReadLine());
  60.                 nbTours++;
  61.  
  62.                 if (uInput > max || uInput < min)//Sécurité Anti-Guillaume (aka "Baka-Masteru")
  63.                     Console.WriteLine("BAKA ! Le nombre saisi doit être compris entre {0} et {1}", min, max);
  64.  
  65.                 if (uInput > target)
  66.                     Console.WriteLine("C'est moins !");
  67.                 else if (uInput < target)
  68.                     Console.WriteLine("C'est plus !");
  69.                 else
  70.                 {
  71.                     Console.WriteLine("BRAVO ! Tu a gagné en {0} tours !", nbTours);
  72.                     won = true;
  73.                     nbTours = 0;
  74.                 }
  75.             }
  76.  
  77.             Console.WriteLine("--------[MENU]--------");
  78.             Console.WriteLine("Que souhaitez-vosu faire ?");
  79.             Console.WriteLine("1) Relancer une partie avec les même parramétres (min & max)");
  80.             Console.WriteLine("2) Relancer une partie en changeant les parramétres (min & max)");
  81.             Console.WriteLine("3) Quitter");
  82.  
  83.             switch (Convert.ToInt16(Console.ReadLine()))
  84.             {
  85.                 case 1: Game(min, max); break;
  86.                 case 2: Game(); break;
  87.                 case 3: Console.WriteLine("Au revoir !"); System.Threading.Thread.Sleep(2000); break;
  88.                 default: Console.WriteLine("[ERREUR]  Saisie invalide"); break;
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment