Exercise: One-dimensional spacefight
The game have several levels. Solve them one after the other.
- The computer "thinks" about a random integer between 1 and 20 then asks the player. The player types in an integer. The computer says if it is too small, to big, or direct hit.
- The user can guess multiple times. Exit only when there was a direct hit.
- The user can enter x any time and quite the game.
- The user can enter p any time and the hidden value is printed (cheating)
- Allow the user to change the game to "move" mode by typing "m". In this mode after every guess after we compared the values change the hidden number by -2, -1, 0, 1, or 2.
- If the user enters "d" we switch to the "debug-mode" of the game. In this mode, before every turn we print the current hidden value.