Studying python and in the lesson it says to modify anc change the program. I thought I'd make the game more interactive. I know it requires the program to use inheritance and I've read everything and Ive tried everything. Ive run out of ideas and would appreciate any and all help. trying to make the game loop from the main class to the subclass where the player will fight against the aliens. When I try to make it loop to the submenu I keep getting the following error message.
This is the error I keep getting.
Traceback (most recent call last):
in <module>
Game().run()
line 13, in run
start = self.Scenes.get(start).enter()
AttributeError: 'NoneType' object has no attribute 'enter'
This is the program.
It stops right when I try and make it go to the submenu of the game.
import random
class Game(object):
def __init__(self):
self.Scenes={"Intro":Intro(),"CorridorRoom":CorridorRoom(),"EngineRoom":EngineRoom(),
"ArmouryRoom":ArmouryRoom(),"EscapePod":EscapePod(),
"Bridge":Bridge(),"scene":dead()}
def run(self):
start="Intro"
while True:
start = self.Scenes.get(start).enter()
class Scene(object):
def enter(self):
pass
exit(0)
class State(Scene):
def state(self):
pass
exit(0)
class state(Game):
def __init__(self):
self.player_hp = 10
self.chicken_hp = 10
def scene_intro(state):
print "Player vs chicken...."
print "Fight!!! "
return "scene_initiative"
def scene_initiative(state):
print"Lets see who attacks first "
chicken, player = roll(6),roll(6)
print "Chickens rolls",chicken
print "Player rolls",player
if chicken<player:
print "Player wins initiative "
raw_input()
return scene_player
elif player<chicken:
print "Chicken wins initiative "
raw_input()
return scene_chicken
else:
print"Even numbers, lets start again..."
raw_input()
return scene_initiative
def scene_player(state):
damage = roll(10)
print "The chicken takes", damage, "points of damage"
state.chicken_hp -= damage
if state.chicken_hp <=0:
print "Looks like we're having chicken tonight "
return None
print"You have",str(state.player_hp),"health left"
return scene_initiative
def scene_chicken(state):
damage = roll(10)
print "You took", damage, "damage"
state.player_hp -= damage
if state.player_hp <=0:
print "That hurt."
return scene_dead
print"You have",str(Game.player_hp),"health left"
return scene_initiative
def scene_dead(state):
print "You died, I bet you're so smart you have a pet zebra and call him spot"
print"Do you want to play again? <yes/no>"
exitgame=raw_input()
if exitgame in ("no","n"):
return "Intro"
elif exitgame in ("yes","ys"):
exit(0)
class dead(Scene):
def enter(self):
print "You died, I bet you're so smart you have a pet zebra and call him spot"
print"Do you want to play again? <yes/no>"
exitgame=raw_input()
if exitgame in ("no","n"):
return "Intro"
elif exitgame in ("yes","ys"):
exit(0)
class Intro(Scene):
def enter(self):
print intro
choice=raw_input()
choice=choice.lower()
if choice in ("yes","ys","y"):
return "CorridorRoom"
elif choice in ("no","n"):
exit(0)
else:
print "Choose one of the options "
return"Intro"
class CorridorRoom(Scene):
def enter(self):
print a
opts=raw_input()
if opts in ('1','armoury','armouryroom','armoryroom'):
return "ArmouryRoom"
elif opts in ('2','engine room'):
return "EngineRoom"
elif opts in ('3','escape','escape pod'):
print "Silly rabbit, trix are for kids, you need to blow the ship up before you leave. \n"
return "CorridorRoom"
else:
print"Uh oh looks like someone doesn't know how to read.\
Do we need to send you back to elementry school to teach you how?\n\
Choose one of the options\n "
return "CorridorRoom"
class EngineRoom(Scene):
def enter(self):
print engineroom
er=raw_input()
if er =='1':
return scene_intro
elif er =='2':
print "You sneek up to a Gothon, shoot and kill the first one,"
print "just as the second one attacks you "
return "scene_intro"
elif er =='3':
print "You sneek around the engine room avoiding the Gothons."
print "Arriving at the engine rooms main computer you start downloading the self destruct code "
print "When suddenly the computer makes a beeping noise then says 'down load complete' "
print "1.Do you grab the chip?\n2.Hide\n3.attack the Gothons"
a=raw_input()
if a =='1':
print "You grab the chip and at the same time the Gothons see you and attack "
return "scene_intro"
elif a =='2':
print "you quickly duck behind the computer and the Gothon doesn't see you "
return "CorridorRoom"
elif a =='3':
return "scene_intro"
elif er =='4':
return "ArmouryRoom"
else:
print "Select one of the options"
return "EngineRoom"
class ArmouryRoom(Scene):
def enter(self):
pass
class EscapePod(Scene):
def enter(self):
pass
class Bridge(Scene):
def enter(self):
pass
engineroom="""You enter the engine room and you see two alien chickens.
will you:
1.Attack the Gothons?
2.Sneek up and shoot them?
3.Sneek around the room and grab the self destruct code from the engine room computer?
4.Grab a weapon from the armoury and come back armed?.
"""
intro="""Alien chickens known as Gothons have invaded your spaceship led by the evil Col
Sanders and our hero has to go through a maze of rooms defeating
them so he can escape into an escape pod to the planet below.
Let's play Gothons From Planet Percal #25.
<yes/no>\n """
a="""You're in a large corridor with two doors on either side of corridor
you are currently inside...
what do you want to do?:
1.Go to the armoury to grab a weapon?\n2.Go to the engine room to get the self destruct code?
3.Go to the escape pod?
"""
"""
for i in range(len(a)):
stdout.write(a[i])
stdout.flush()
sleep(.1)
for i in range(len(engineroom)):
stdout.write(engineroom[i])
stdout.flush()
sleep(.1)
for i in range(len(intro)):
stdout.write(intro[i])
stdout.flush()
sleep(.1)
"""
Game().run()