Hi all,
I’m going through the ex 43 in LPTHW and was wondering why do we need an engine at all ?
Mainly because I’m not able to completely comprehend the engine code.
I tried to do it without the engine and it works…
from sys import exit
from random import randint
from textwrap import dedent
class Scene(object):
def enter(self):
print("This scene is not yet configured.")
print("Subclass it and implement enter().")
exit(1)
class Death():
def enter(self):
quips = [
"Taunt1: You died. You kinda suck at this.",
"Taunt2: Your mom would be proud... if she were smarter.",
"Taunt3: hdh"
]
print(quips[randint(0, len(quips)-1)])
exit(1)
class CentralCorridor(Scene):
def enter(self):
print(dedent("""
The Gothons of Planet Percal #25 have invaded your ship and
destroyed your entire crew. You are th last surviving member and your last
mission is to get the neutron destruct bomb from the Weapons Armory,
put it in the bridge, and blow the ship after getting into the
escape pod.
You're running down the central corridor to the Weapons
Armory when a Gothon jumps out, red scaly skin, dark grimy
teeth, and evil clown costume flowing around his hate filled body.
He's blocking the door to the Armory and about to pull a weapon to
blast you!!!.
"""))
action = input("> ")
if action == "shoot!":
print(dedent("""
You're dead
"""))
return Death.enter(self)
elif action == "dodge":
print(dedent("""
you dodge, you die
"""))
return Death.enter(self)
elif action == 'tell a joke':
print(dedent("""
Joke: Good one!
jump through the weapon aromory door.
"""))
return LaserWeaponArmory.enter(self)
else:
print("Does not Compute")
return CentralCorridor.enter(self)
class LaserWeaponArmory(Scene):
def enter(self):
print(dedent("""
You do a dive and get in.
There's a keypad lock on th box ad you need the code to
get the bomb out. If you get the code wrong ten times then
the lock closes forever and you can't get the bomb. The
code is 3 digits
"""))
code = f"{randint(1,9)}{randint(1,9)}{randint(1,9)}"
guess = input("[keypad]>")
guesses = 0
while (guess != code and int(guess) != 999) and guesses < 10:
print("BZZZZZEDDD!")
guesses += 1
guess = input("[keypad]>")
if guess == code or int(guess) == 999:
print(dedent("""
You guessed right code you advance to bridge
"""))
return TheBridge.enter(self)
else:
print(dedent("""
the lock buzzes last time and you die
"""))
return Death.enter(self)
class TheBridge(Scene):
def enter(self):
print(dedent("""
On bridge there are 5 more gothons
"""))
action = input("What do you do > ")
if action == "throw the bomb":
print(dedent("""
You failed your mission
"""))
return Death.enter(self)
elif action == "slowly place the bomb":
print(dedent("""
You get into stealth mode and place the bomb safely!!
"""))
return EscapePod.enter(self)
else:
print("Does not Compute")
return TheBridge.enter(self)
class EscapePod(Scene):
def enter(self):
print(dedent("""
There are 5 pods....
Which one do you take??
"""))
good_pod = randint(1,5)
guess = input("[pod # ]> ")
if guess != good_pod and int(guess) != 9:
print(dedent("""
wrong pod..... you die
"""))
return Death.enter(self)
else:
print(dedent("""
You chose the right . You won!!!
"""))
return Finished.enter(self)
class Finished(Scene):
def enter(self):
print("You won!!!!. Good job!!.")
game = CentralCorridor()
game.enter()