-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added stubs for Computer Space Games.
- Loading branch information
1 parent
9854ce2
commit 6e38866
Showing
27 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
9 changes: 9 additions & 0 deletions
9
docs/books/computer-games/computer-space-games/alien-snipers/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
============= | ||
Alien Snipers | ||
============= | ||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/asteroid-belt/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
asteroid-belt | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/beat-the-bug-eyes/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
beat-the-bug-eyes | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/death-valley/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
death-valley | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/evil-alien/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
evil-alien | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/intergalactic-games/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
intergalactic-games | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/monsters-of-galacticon/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
monsters-of-galacticon | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/moonlander/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
moonlander | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/space-mines/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
space-mines | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/space-rescue/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
space-rescue | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
24 changes: 24 additions & 0 deletions
24
docs/books/computer-games/computer-space-games/starship-takeoff/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
================ | ||
Starship Takeoff | ||
================ | ||
|
||
You are a starship captain. You have crashed your ship on a strange planet and must take off again quickly in the alien ship you have captured. The ship's computer tells you the gravity on the planet. You must guess the force required for a successful take off. If you guess too low, the ship will not lift off the ground. If you guess too high, the ship's fail-safe mechanism comes into operation to prevent it from being burnt up. If you are still on the planet after ten tries, the aliens will capture you. | ||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: starship_takeoff.py | ||
:language: python | ||
|
||
|
||
How to make the game harder | ||
--------------------------- | ||
|
||
You can change to the program to give you less than 10 goes. Do this by altering the number on lines 24 and 42 (They must be the same). | ||
|
||
Puzzle corner | ||
------------- | ||
|
||
You could change the range of possible forces. See if you can work out how. | ||
|
||
|
52 changes: 52 additions & 0 deletions
52
docs/books/computer-games/computer-space-games/starship-takeoff/starship_takeoff.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Import the 'random' module, so you can generate random numbers | ||
import random | ||
|
||
print('Starship Take-off') | ||
print('-----------------') | ||
print() | ||
|
||
# Select 2 random numbers. `random.randrange(X)` picks a number | ||
# between 0 and X, *including* 0, but *not* including X. Adding | ||
# 1 means we get a number between 1 and X, *inclusive*. | ||
gravity = random.randrange(20) + 1 | ||
weight = random.randrange(40) + 1 | ||
|
||
# Compute the required launch force. | ||
required = gravity * weight | ||
|
||
# Print the gravity for the planet | ||
print('Gravity =', gravity) | ||
|
||
# Start a loop that will run until either there have been | ||
# 10 attempts, or the user entered the correct force. | ||
success = False | ||
c = 0 | ||
while c < 10 and not success: | ||
# On each loop, increment the count of attempts, | ||
# and prompt the user for a value | ||
c = c + 1 | ||
force = int(input("Force:")) | ||
|
||
# Compare the value entered with the required value. | ||
# If they match, set the success flag; otherwise, | ||
# print an error | ||
if force > required: | ||
print('Too high!') | ||
elif force < required: | ||
print('Too low!') | ||
else: | ||
success = True | ||
|
||
# As long as this isn't the last loop, | ||
# we can try again | ||
if c < 10: | ||
print('Try again.') | ||
|
||
print() | ||
|
||
# We've either been successful, or we've done 10 loops. | ||
# Tell the user if they've been successful. | ||
if success: | ||
print('Good take off!!') | ||
else: | ||
print('You failed - the aliens got you') |
7 changes: 7 additions & 0 deletions
7
docs/books/computer-games/computer-space-games/touchdown/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
touchdown | ||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.
8 changes: 8 additions & 0 deletions
8
docs/books/computer-games/computer-space-games/trip-into-the-future/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
trip-into-the-future | ||
|
||
|
||
The code | ||
======== | ||
|
||
.. literalinclude:: game.py | ||
:language: python |
Empty file.