Skip to content

Commit

Permalink
Added stubs for Computer Space Games.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Dec 30, 2017
1 parent 9854ce2 commit 6e38866
Show file tree
Hide file tree
Showing 27 changed files with 188 additions and 0 deletions.
Empty file.
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.
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.
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.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
evil-alien


The code
========

.. literalinclude:: game.py
:language: python
16 changes: 16 additions & 0 deletions docs/books/computer-games/computer-space-games/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ Computer Space Games

`Download the original book <https://drive.google.com/a/semantic.co.uk/file/d/0Bxv0SsvibDMTNlMwTi1PTlVxc2M/view>`__


.. toctree::

starship-takeoff/index
intergalactic-games/index
evil-alien/index
beat-the-bug-eyes/index
moonlander/index
monsters-of-galacticon/index
alien-snipers/index
asteroid-belt/index
trip-into-the-future/index
death-valley/index
space-mines/index
space-rescue/index
touchdown/index
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
monsters-of-galacticon


The code
========

.. literalinclude:: game.py
:language: python
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
moonlander


The code
========

.. literalinclude:: game.py
:language: python
Empty file.
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.
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.
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.


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')
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
touchdown

The code
========

.. literalinclude:: game.py
:language: python
Empty file.
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.

0 comments on commit 6e38866

Please sign in to comment.