Exercise: one-dimensional space-fight
-
We develop an interactive game called the one-dimensional space-fight.
-
We have a spaceship in the one-dimensional space we need to shoot down.
-
The distance of the spaceship is represented by an integer number. We can shoot by entering an integer number.
-
The computer generates a random integer number between 0-20. (The distance of the spaceship.)
-
The player shoots by entering a number.
-
The computer tells us if our shot was too short, too long or if we hit the target.
-
If we hit the target the game is over. We are told how many shots did we fire. We are asked if we would like to play again or quit.
-
During the game we can press "c" (that stands for cheat) and the computer will reeal the distance of the spaceship.
-
We can also press "q" and we will quite the game.
-
We can also press "n" and we start a new game, giving up on the current fight.