Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Game := Object clone do(
- init := method(
- solution ::= (Random value * 100) floor;
- min ::= 0;
- max ::= 100;
- success ::= false;
- tries ::= 10;
- )
- );
- Game prompt := method(
- "Guess a random number between #{min} and #{max} (e.g. #{((min + max) / 2) ceil}), you have #{tries} tries>" interpolate println
- );
- Game play := method(
- while (tries > 0 and success == false,
- prompt;
- input := File standardInput readLine asNumber;
- if(input == solution,
- "you got it" println; success = true,
- if((input < solution),
- "higher" println; min = input,
- "lower" println; max = input)
- )
- tries = tries - 1;
- )
- );
- Game clone play
- //////////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////Output/////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////
- Io> Game clone play
- Guess a random number between 0 and 100 (e.g. 50), you have 10 tries>
- 50
- higher
- Exception: Slot tries not found. Must define slot using := operator before updating.
- ---------
- updateSlot Command Line 1
- Game play Command Line 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement