Advertisement
Guest User

asdasd

a guest
Nov 16th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
IO 1.31 KB | None | 0 0
  1. Game := Object clone do(
  2.   init := method(
  3.     solution ::= (Random value * 100) floor;
  4.     min ::= 0;
  5.     max ::= 100;
  6.     success ::= false;
  7.     tries ::= 10;
  8.   )
  9. );
  10.  
  11. Game prompt := method(
  12.   "Guess a random number between #{min} and #{max} (e.g. #{((min + max) / 2) ceil}), you have #{tries} tries>" interpolate println
  13. );
  14.  
  15. Game play := method(
  16.   while (tries > 0 and success == false,
  17.     prompt;
  18.     input := File standardInput readLine asNumber;
  19.     if(input == solution,
  20.       "you got it" println; success = true,
  21.       if((input < solution),
  22.         "higher" println; min = input,
  23.         "lower" println; max = input)
  24.     )
  25.     tries = tries - 1;
  26.   )
  27. );
  28.  
  29. Game clone play
  30.  
  31. //////////////////////////////////////////////////////////////////////////////////////////////////////
  32. ///////////////////////////////////Output/////////////////////////////////////////////////////////////
  33. //////////////////////////////////////////////////////////////////////////////////////////////////////
  34. Io> Game clone play
  35. Guess a random number between 0 and 100 (e.g. 50), you have 10 tries>
  36. 50
  37. higher
  38.  
  39.   Exception: Slot tries not found. Must define slot using := operator before updating.
  40.   ---------
  41.   updateSlot                          Command Line 1
  42.   Game play                            Command Line 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement