Skip to content

Instantly share code, notes, and snippets.

@benjjo
Last active December 25, 2016 12:57
Show Gist options
  • Select an option

  • Save benjjo/38f10d4ae4f0c9548a36bcfecefd6173 to your computer and use it in GitHub Desktop.

Select an option

Save benjjo/38f10d4ae4f0c9548a36bcfecefd6173 to your computer and use it in GitHub Desktop.
LPTHW ex43
#!/usr/bin/python
from random import randrange
global laser_gun
laser_gun = 'fists'
global laser_power
laser_power = 0
class Scene(object):
def enter(self):
print("This is confusing AF")
exit(1)
class Engine(object):
def __init__(self, scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
last_scene = self.scene_map.next_scene('finished')
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
# Be sure to print out the last scene
current_scene.enter()
class Death(Scene):
death_quotes = [
"It's not that I'm afraid to die, I just don't want to be there when it happens.",
"Always Look On The Bright Side Of Life",
"One day can make your life. One day can ruin your life. All life is, is four or five days that change "
"everything.",
"Dying is a very dull, dreary affair. And my advice to you is to have nothing whatever to do with it.",
"Immortality: a fate worse than death.",
"Life does not cease to be funny when people die any more than it ceases to be serious when people laugh.",
"The annoying thing about being an atheist is that you'll never have the satisfaction of saying to believers, "
"'I told you so.'",
"Life is pleasant. Death is peaceful. It's the transition that's troublesome",
"The idea is to die young as late as possible",
"The living are just the dead on holiday",
"Death: A fate worse than life."]
def enter(self):
print("\n\n******** You died ********\n\n")
print(Death.death_quotes[randrange(0, len(Death.death_quotes))])
exit(1)
class CentralCorridor(Scene):
def enter(self):
print("Well here you are.... in a corridor, presumably on some kind of spaceship.")
print("Not much going on in this room..... there's two doors though.")
print("Looks like you have two options, go through the door on the left or right.")
print("So, what will it be?")
print("-Left")
print("-Right\n")
user = raw_input("-> ")
if user in ('L', 'Left', 'l', 'left'):
return 'laser_weapon_armory'
elif user in ('R', 'Right', 'r', 'right'):
return 'the_bridge'
else:
print("Invalid option, try again.")
return 'central_corridor'
class LaserArsenal(object):
def __init__(self, ):
# List of lasers available with their relative power.
self.weapons_dic = {
'Steampunk Blaster': 0,
'Star Trek Laser Pistol': 1,
'Goliathon 83': 2,
'Pulse Pistol': 5,
'Sandman DS': 5,
'Klingon Disruptor': 10,
'Atomic Disintegrator ': 15,
'Blade Runner Blaster': 20,
'DL-44': 25,
'Arc Gun': 100}
# List of weapons in LaserWeaponArmory
self.weapons_list = self.weapons_dic.keys()
# Print out the lasers
def list_lasers(self):
for line in self.weapons_list:
print line
class LaserWeaponArmory(object):
# Call this to get the selection from the user.
def laser_selection(self):
# Instantiate the LaserArsenal class
lasers = LaserArsenal()
print("\nYou enter what appears to be... THE ARMORY!!")
print("OOOOOH YEEEEEAH! GUNS BABY!!\n\n"
"You look around the room and see:\n")
# Print out the lasers
lasers.list_lasers()
weapon_select = raw_input("\n Choose: ")
return weapon_select
# the initial def to call to start the scene.
def enter(self):
global laser_gun
global laser_power
# A try statement to make sure valid user input is passed.
try:
lwa = LaserWeaponArmory()
laser_gun = lwa.laser_selection()
lasers = LaserArsenal()
laser_power = lasers.weapons_dic[laser_gun]
except:
# return to start
print("Your choice is not valid. Like I even gave you the example to cut and paste.")
return 'laser_weapon_armory'
if laser_gun in lasers.weapons_list:
if laser_power == 0:
print("\nTrekkies... There's just no hope for you.\n")
elif laser_power < 10:
print("\nYou have chosen... poorly\n")
elif laser_power < 25:
print("\nYou are a gallant warrior.\n")
elif laser_power < 100:
print("\nNice! Who cares who shoots first! \n")
elif laser_power == 100:
print("\nHolly shit! Luckily your arm has mutated with Alien DNA.\n")
# Now you have a weapon, go back to the corridor.
print("You head back into the corridor.")
return 'central_corridor'
else:
# return to start
return 'laser_weapon_armory'
class TheBridge(Scene):
def enter(self):
global laser_gun
global laser_power
print("Entering the bridge, a shiver runs down your spine.")
print("The door shuts behind you. You are confronted by a mutant Strandbeest")
print("blocking the entrance to the only means of escape, the escape pod.")
print("What do you do?\n")
print("-Shoot?")
print("-Negotiate?\n\n")
user = raw_input("-> ")
if user in ('Shoot', 'S', 's', 'shoot'):
print("You pull out your sweet %s and begin to battle." % laser_gun)
return 'the_battle'
elif user in ('Negotiate', 'N', 'negotiate', 'n'):
print("There is no negotiation without Theo.")
return 'death'
else:
print("Invalid response. You have upset the Strandbeest.")
return 'death'
class TheBattle(Scene):
def enter(self):
player_health = 100
strandbeest_health = 100
global laser_gun
global laser_power
print("You lay vengence upon the innocent ")
print("Strandbeest doing %d damage." % laser_power)
print("The Strandbeest lashes back at you with a heafty 25 damage.")
strandbeest_health -= laser_power
player_health -= 25
while strandbeest_health > 0:
print("Your health is: %d" % player_health)
print("The Strandbeest: %d" % strandbeest_health)
user = raw_input("Will you shoot again... Yes, No?")
if user in ('Yes', 'Y', 'yes', 'y'):
print("\nPEW PEW!! You do %d more damage!" % laser_power)
elif user in ('No', 'N', 'no', 'n'):
return 'death'
else:
strandbeest_health += laser_power
strandbeest_health -= laser_power
player_health -= 25
if player_health <1:
return 'death'
return 'escape_pod'
class TheEscapePod(Scene):
def enter(self):
print("\nThe Strandbeest is dead and you enter the pod.")
print("You are now challenged to enter the escape pod passcode (1-10)")
print("to exit to safety. A note on the pad reads:")
print("\n ******** 5 attempts to set off anti-theft device ********\n")
code = randrange(1,10)
user = 0
counter = 5
while user != code and counter > 1:
user = int(raw_input("[keypad] -> "))
counter -= 1
#print("code is %d" % code)
if counter == 0:
return 'death'
else:
return 'finished'
class Finished(Scene):
def enter(self):
print("\nThe Strandbeest is dead and you escaped to safety.")
print("Can you live with yourself after taking the life")
print("of such a beautiful anomaly? Is this really living?\n")
class Map(object):
scenes = {
'central_corridor': CentralCorridor(),
'laser_weapon_armory': LaserWeaponArmory(),
'the_bridge': TheBridge(),
'the_battle': TheBattle(),
'escape_pod': TheEscapePod(),
'death': Death(),
'finished': Finished()
}
def __init__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
val = Map.scenes.get(scene_name)
return val
def opening_scene(self):
return self.next_scene(self.start_scene)
a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment