Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import haxe.io.Input;
- import haxe.io.Output;
- class Random
- {
- public static inline function int(from:Int, to:Int):Int
- {
- return from + Math.floor(((to - from + 1) * Math.random()));
- }
- }
- class Something
- {
- private var input: Input;
- private var output: Output;
- public static function main(): Void
- {
- var instance: Something = new Something(Sys.stdin(), Sys.stdout());
- instance.playGame();
- }
- public function new(input: Input, output: Output): Void
- {
- this.input = input;
- this.output = output;
- }
- public function playGame(): Void
- {
- output.writeString("Enter your name: ");
- var name: String = input.readLine();
- if (name == "")
- {
- name = "Player";
- }
- output.writeString("Alright then, " + name + ", let's have some fun.\n");
- output.writeString("\nEnter the password: ");
- var pass: String = input.readLine();
- if (pass != name)
- {
- output.writeString("That's not the correct password....\n");
- output.writeString("Have fun on your train under the ocean.\n\n");
- }
- if (pass == name)
- {
- output.writeString("Good. Let's play a game.\n\n");
- }
- output.writeString("enter min: ");
- var min: Int = Std.parseInt(input.readLine());
- if (min < 10 || min > 1000000)
- {
- min = 10;
- }
- output.writeString("enter max: ");
- var max: Int = Std.parseInt(input.readLine());
- if (max < 10 || max > 1000000)
- {
- max = 1000000;
- }
- while (true)
- {
- var tries: Int = 0;
- var number: Int = Random.int(min,max);
- output.writeString("\nGuess between " + min + " and " + max + "\n\n");
- while (true)
- {
- output.writeString("Guess: ");
- var guess: Int = Std.parseInt(input.readLine());
- if (guess == 0)
- {
- output.writeString("invalid input detected\n\n");
- continue;
- }
- if (guess < min || guess > max)
- {
- output.writeString("\nout of range\n");
- continue;
- }
- tries++;
- if (guess < number)
- {
- output.writeString("higher\n");
- }
- else if (guess > number)
- {
- output.writeString("lower\n");
- }
- else if (guess == number)
- {
- output.writeString("\nmatch found by " + name + " in " + tries + " tries\n");
- break;
- }
- else
- {
- output.writeString("\ninvalid input detected\n\n");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement