Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- /* En hommage au respect et à la logique, tués tragiquement par Guillaume "Baka-Masteru" Dupont
- * ce 13 Novembre 2015 lors d'une session de test du jeu "Plus ou moins".
- * Les témoins racontent que l'horrible individu aurais tenter de rentrer son nombre min bien
- * trop gros pour le nombre max de sa victime. */
- namespace Game_plus_moins
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool mKeep = true;
- do
- {
- Console.WriteLine("------------[MENU]------------");
- Console.WriteLine("1) Lancer le jeu");
- Console.WriteLine("2) Quitter");
- switch(Console.ReadLine())
- {
- case "1": Game(); mKeep = false; break;
- case "2": mKeep = false; break;
- default: Console.WriteLine("[ERREUR] Saisie invalide"); break;
- }
- } while (mKeep);
- }
- static void Game(int min = -1, int max = -2)
- {
- bool won = false;
- int nbTours = 0;
- Random rnd = new Random();
- if (min == -1 && max == -2)
- {
- Console.WriteLine("[INFO] Choisir un nombre max");
- max = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("[INFO] Choisir un nombre min");
- min = Convert.ToInt16(Console.ReadLine());
- }
- if (min >= max)//Sécurité Anti-Guillaume (aka "Baka-Masteru")
- {
- Console.WriteLine("[ERREUR] BAKA ! - Min ne peut être suppérieur ou égale à max");
- Game();
- }
- int target = rnd.Next(min, max + 1);
- Console.WriteLine("[INFO] Saisir un nombre entre {0} et {1}", min, max);
- while(!won)
- {
- int uInput = Convert.ToInt32(Console.ReadLine());
- nbTours++;
- if (uInput > max || uInput < min)//Sécurité Anti-Guillaume (aka "Baka-Masteru")
- Console.WriteLine("BAKA ! Le nombre saisi doit être compris entre {0} et {1}", min, max);
- if (uInput > target)
- Console.WriteLine("C'est moins !");
- else if (uInput < target)
- Console.WriteLine("C'est plus !");
- else
- {
- Console.WriteLine("BRAVO ! Tu a gagné en {0} tours !", nbTours);
- won = true;
- nbTours = 0;
- }
- }
- Console.WriteLine("--------[MENU]--------");
- Console.WriteLine("Que souhaitez-vosu faire ?");
- Console.WriteLine("1) Relancer une partie avec les même parramétres (min & max)");
- Console.WriteLine("2) Relancer une partie en changeant les parramétres (min & max)");
- Console.WriteLine("3) Quitter");
- switch (Convert.ToInt16(Console.ReadLine()))
- {
- case 1: Game(min, max); break;
- case 2: Game(); break;
- case 3: Console.WriteLine("Au revoir !"); System.Threading.Thread.Sleep(2000); break;
- default: Console.WriteLine("[ERREUR] Saisie invalide"); break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment