We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,055 Members — Technology Publication meets Social Media

How to make this class runnable

``````#################################
#   Learning to make a game     #
#################################

# An attempt to make a game
# Each room will be described by a class, whose base class will be Room
# The user will be prompted to enter a number, each number will be assigned with a Room in return

from sys import exit

print '-' * 50

print "You are a lone traveller on this earth"
print "who is just roaming and roaming."
print "finally you encounter 5 doors."
print "Each door has some stuff in store for you except one,"
print "which has death in store for you."
print "So choose your doors with cool mind."

print '-' * 50

print "why, Good Job!"
exit(0)

#class Room(object):  #the other room will be derived of this
#   pass

class Room(object):
pass

class GoldRoom(Room):

def gold_room(self):

# here the user will be asked with question on how much Gold he wants
print"This room is full of gold. How much do you take!"
print next

if next.isdigit():
how_much = int(next)

else:
dead("Man, learn to type some number")

if how_much < 50:
print "Nice, you are not greedy, you win!"
exit(0)
else:

class KoiPondRoom(Room):

# in this room, the user will be made to relax
def koi_pond_room(self):
print "You have entered a room where you can relaz!"
next = raw_input("> ")

if next == "Sleeping":
print "SLEEP WELL!"
elif next == "Television Watching":
print "WOHOO! WATCH AMAZING SPIDERMAN!"
elif next == "EATING":
print "COOL! NPOW HOG!"
else:
print "GO TO HELL!"

class Cthulhu_Room(Room):

# sort of puzzle to get out
def cthulhu_room(self):
print "Here's how see the great evil Cthulhu"
print "He,it, whatever stares at you and you go insane."
next = raw_input("> ")

if "flee" in next:
goldroom = GoldRoom()
goldroom.gold_room()
else:
cthulhu_room = Cthulhu_Room()
cthulhu_room.cthulhu_room()

class Bear_Room(Room):

# bear room
def bear_room(self):
print "There's a bear here"
print "The bear has a bunch of honey."
print "The fat bear is in front of another door."
print "How are you going to move the bear."
bear_moved = False

while True:
next = raw_input("> ")

if next == "take honey":
elif next == "taunt bear" and not bear_moved:
print "The bear has moved from the door. You can go through it now."
bear_moved = True
elif next == "taunt bear" and bear_moved:
elif next == "open door" and bear_moved:
goldroom = GoldRoom()
goldroom.gold_room()
else:
print "I got no idea what it means."

class Dark_Room(Room):

def dark_room(self):
print "You have entered a dark room."
print "If you want to escape, then guess the correct password!"
print "But you have only three chances,"
print "failing which you will be locked here forever."

guesses = 0
while guess != password and guesses < 2:
print "Try again!"
guesses += 1

else:
print "YOU HAVE BEEN LOCKED HERE FOREVER,"
print "NOW SUFFER"

print "You MORON!"
print "why did you chose this?"

if room_chosen == 1:
goldroom = GoldRoom()
goldroom.gold_room()

elif room_chosen == 2:
koipondroom = KoiPondRoom()
koipondroom.koi_pond_room()

elif room_chosen == 3:
cthulhu_room = Cthulhu_Room()
cthulhu_room.cthulhu_room()

elif room_chosen == 4:
bear_room = Bear_Room()
bear_room.bear_room()

elif room_chosen == 5:
dark_room = Dark_Room()
dark_room.dark_room()

elif room_chosen == 6:

else:
print "YOU SUCK!"
``````
2
Contributors
3
Replies
1 Day
Discussion Span
10 Months Ago
Last Updated
4
Views
peterparker
Light Poster
29 posts since Jul 2012
Reputation Points: 0
Skill Endorsements: 0

I have written this code. I would like to make a runnable script for the same.

peterparker
Light Poster
29 posts since Jul 2012
Reputation Points: 0
Skill Endorsements: 0

I run the code without problem, but it did crash when given empty string as response.

pyTony
pyMod
Moderator
6,306 posts since Apr 2010
Reputation Points: 879
Skill Endorsements: 26

"I run the code without problem, but it did crash when given empty string as response."

oh no, by runnable i meant

a python script will be used to run the classes

i mean, a python runner

peterparker
Light Poster
29 posts since Jul 2012
Reputation Points: 0