Advertisement
Guest User

Untitled

a guest
May 13th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 3.02 KB | None | 0 0
  1. import haxe.io.Input;
  2. import haxe.io.Output;
  3.  
  4. class Random
  5. {
  6.     public static inline function int(from:Int, to:Int):Int
  7.     {
  8.         return from + Math.floor(((to - from + 1) * Math.random()));
  9.     }
  10. }
  11.  
  12. class Something
  13. {
  14.     private var input: Input;
  15.     private var output: Output;
  16.     public static function main(): Void
  17.     {
  18.         var instance: Something = new Something(Sys.stdin(), Sys.stdout());
  19.         instance.playGame();
  20.     }
  21.     public function new(input: Input, output: Output): Void
  22.     {
  23.         this.input = input;
  24.         this.output = output;
  25.     }
  26.     public function playGame(): Void
  27.     {
  28.         output.writeString("Enter your name: ");
  29.         var name: String = input.readLine();
  30.         if (name == "")
  31.         {
  32.             name = "Player";
  33.         }
  34.         output.writeString("Alright then, " + name + ", let's have some fun.\n");
  35.         output.writeString("\nEnter the password: ");
  36.         var pass: String = input.readLine();
  37.         if (pass != name)
  38.         {
  39.             output.writeString("That's not the correct password....\n");
  40.             output.writeString("Have fun on your train under the ocean.\n\n");
  41.         }
  42.         if (pass == name)
  43.         {
  44.             output.writeString("Good. Let's play a game.\n\n");
  45.         }
  46.         output.writeString("enter min: ");
  47.         var min: Int = Std.parseInt(input.readLine());
  48.         if (min < 10 || min > 1000000)
  49.         {
  50.             min = 10;
  51.         }
  52.         output.writeString("enter max: ");
  53.         var max: Int = Std.parseInt(input.readLine());
  54.         if (max < 10 || max > 1000000)
  55.         {
  56.             max = 1000000;
  57.         }
  58.         while (true)
  59.         {
  60.             var tries: Int = 0;
  61.             var number: Int = Random.int(min,max);
  62.             output.writeString("\nGuess between " + min + " and " + max + "\n\n");
  63.             while (true)
  64.             {
  65.                 output.writeString("Guess: ");
  66.                 var guess: Int = Std.parseInt(input.readLine());
  67.                 if (guess == 0)
  68.                 {
  69.                     output.writeString("invalid input detected\n\n");
  70.                     continue;
  71.                 }
  72.                 if (guess < min || guess > max)
  73.                 {
  74.                     output.writeString("\nout of range\n");
  75.                     continue;
  76.                 }
  77.                 tries++;
  78.                 if (guess < number)
  79.                 {
  80.                     output.writeString("higher\n");
  81.                 }
  82.                 else if (guess > number)
  83.                 {
  84.                     output.writeString("lower\n");
  85.                 }
  86.                 else if (guess == number)
  87.                 {
  88.                     output.writeString("\nmatch found by " + name + " in " + tries + " tries\n");
  89.                     break;
  90.                 }
  91.                 else
  92.                 {
  93.                     output.writeString("\ninvalid input detected\n\n");
  94.                     break;
  95.                 }
  96.             }
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement