OK so I want to learn python. Witch leads to me buying a book and I have gone about half way when I ran into trouble. I have coded a game (80' text) sample but it wont run and I have given it a good try to solve it my self, but no luck I DONT GET IT I have noticed that my dicts in the book use [ ] but on pythonAnywere its not working like that but it dose work with { } so theres one issue but the big one is it wont run. It runs with no errors as a skeliton but as soon as I feed it a scene it starts giveing errors I have twiked it a few ways .. pls help
from sys import exit from random import randint
class Scene(object):
def enter(self):
print "This scene is not yet configured. Subclass it and implement enter."
exit(1)
Now the engine
class Engine(object):
def __init__(self, scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
while True:
print "\n----------"
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
make Class Death
class death(Scene):
quips = ["\nYou died. You kinda suck at this.", "\nYour mom would be so proud...IF she were smarter.", "\nLa-HAY LU-hoo ZAHER", "\nMy Grandma is better then this."]
def enter(self):
print death.quips[randint(0, len(self.quips)-1)]
exit(1)
Class Scenes
class central_corridor(Scene):
def enter(self):
print "The Gothons of planet melmac 7 have invaded your ship and destroyed"
print "your entire crew. You are the only surviving member of your team"
print "and your last orders were to get the BIGFUCKINGBOMB or the BFB for"
print "short, and put it on the bridge then get the hell out and blow this"
print "bitch up"
print "\n"
print "Your running down the central corridor th the wepons room when"
print "a Gothon jumps out at you, red scaly skin, dark grimy teeth and an"
print " evil clown costume flowing around his hate filld body. He's"
print " blocking the door to the weapons room and is about to pull his blaster"
print "\n----------\n"
print "You can::shoot::dodge::tell a joke"
print "\n---------\n"
action = raw_input(";@|>")
if action == "shoot":
print "Quick on the draw you pull your blaster and fire it at the Gothon."
print "His clown costume is flowing and moving around his body, witch"
print " throws off your aim. Your laser hits the wall behind the clown"
print " and bounces back to hit you in the face. You've Died."
return 'death'
elif action == "dodge!":
print "You think back on those days when you were a rug rat and think I'll "
print " just jump out of the way so you try this but as your OLDER body jerks"
print " its self in a febal atempt to jump you tork your back and fall to the"
print " ground cring \"OH! my back\" as you lay there like a limp dick the Gothon"
print " steps on your head and you die."
return 'death'
elif action == "tell a joke":
print "You look the Gothon in his stupid face and say \"A Man and a Geraff walk into"
print " a Bar the both get drunk, when the Geraff falls to the floor out cold the Man"
print " gets up and walk out, as he dose this the Bar Tender Yells YOU CANT LEVE THAT LIEING THERE"
print " The Man looks at him and says thats no Lion its a Geraff\" at that point the Gothon hits the floor"
print " and befor he can react you brake his stupid face"
return 'WeponsRoom'
else:
print "WHAT???"
return 'central_corridor'
class WeponsRoom(Scene):
def enter(self):
print "As you Enter the Wepons room you scan to see if there are any more Gothons hiding, once you find the BFB"
print " you see that there is a key pad lock on it. You will need the code to get the BFB out. If you get the code"
print " wrong 10 times the thermite safty switch will egnite melting the lock to a perma chunk of titainium then"
print " will never get the Big Fucking Bomb The code is 3 digits."
code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
guess = raw_input("[{KEYPAD PASS CODE}]::")
guesses = 0
while guess != code and guesses <10:
print "Like that Asian guy in the cubical next to me you sir are Jimmy WONG"
guesses += 1
guess = raw_input("[{KEYPAD PASS CODE}]::")
if guess == code:
print "YES! I had the same passcode on my locker at the gym.\n"
print "Ok you grab the BFB and start heading to the Bridge were you will put the BFB and blow these SHIT HOLE CLOWNS"
print " TO HELL!!!"
return 'the_bridge'
else:
print "Thats it you idiot it was %s . As you try to think of what to do next your mommy calls and says "
print " its time to come home so you blast your self in the face and die"
return 'death'
class the_bridge(Scene): def enter(self): print "You get to the bridge like the flash and as you start to arm the BFB SUPRISE! there are 5 Gothons" print "\n What do you do?"
print "\n----------\n"
print "You can::Throw the Big Fucking Bomb::Place it slowly on the ground"
print "\n---------\n"
action = raw_input(";@|>")
if action == "Throw the Big Fucking Bomb":
print "You throw the BFB .... THE BFB.... REALLY your stupid so BOOM GOSE THE BOMB and now you are dead too GOOD JOB!"
return 'death'
elif action == "Place it slowly on the ground":
print "Just then you pull your blaster and scream \"I'LL FUCKING DO IT MAN!\" as you point your blaster at the BFB"
print " like little bitches they all step back and stay very still, you arm it and then step out shuting the door you blast the electro lock"
print " making it spark and lock the door then you run to the escape pod"
return 'escape_pod'
else:
print "What?"
return 'the_bridge'
class escape_pod(Scene):
def enter(self):
print "You get to the pod but for some reason theres a sighn that says only one works. What?"
print "Well pick one and hope for the best. There are 5 pods"
good_pod = randint(1,5)
print "\n----------\n"
print "You can pick::1::2::3::4::5"
print "\n---------\n"
guess = raw_input(";@|>")
if guess != good_pod:
print "You jump on to pod %s and as the doors shut you see the sighn on the back of the door that says OUT OF ORDER, Have a nice day :)" % guess
print " The pod shoots out half way locking you in the pod. you think to your self well at lest I got those bas...just then you see the 5 Gothons jump onto their ship and fly off"
print " SHIT!"
return 'death'
else:
print "You jump on to pod %s and as the doors shut you hit the go switch and blast off to the vast emptyness of space I guess at lest I killd those bastards just then you see them jump onto their" % guess
print " as they fly away your ship blows up and you think SHIT!"
print "\n Game Over You win"
return 'finished'
class map(object):
scenes = {
'central_corridor': central_corridor() ,
'WeponsRoom': WeponsRoom(),
'the_bridge': the_bridge(),
'escape_pod': escape_pod(),
'death': death()
}
def __inti__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
return map.scenes.get(scene_name)
def opening_scene(self):
return self.next_scene(self.start_scene)
scene_map = map('central_corridor') scene_game = Engine(scene_map) scene_game.play()
WHAT IS WRONG??? IS IT IN THE CODE OR THE PyA??? like the [ ] - { } ???