19.1k views
3 votes
You need to implement a class that represents the state of a room or game section. The class will contain a room_id, a description, and possibly a choice1 and a choice 2. You will need to implement the __str__ override to output the state of the room. You should also implement a method called game_over. If the room does have a choice 1 and choice2 then the game is over and it should return True.

User Hizzy
by
4.6k points

1 Answer

5 votes

Answer:

class Home(object):

def __int__(self):

room1()

# room1 is the bedroom, you could either sleep or leave the room

def room1(self):

print("Room 1")

choices = ['sleep', 'leave']

for _ in iter(list, 0):

mychoice = input("What do you want to do here sleep/leave: ")

if mychoice == choice[0]:

print("You are sleeping")

elif mychoice == choice[1]:

self. room2()

else:

self. game_over()

# room2 is the living room for fun and recreation

def room2(self):

print("Room 2")

choices = ['watch a movie', 'dance', 'call a friend', 'leave']

mychoice = input("What do you want to do here: ")

for _ in iter(list,0):

if mychoice == choice[0]:

print("I love this movie")

elif mychoice == choice[1]:

print("You are a good dancer.")

elif mychoice == choice[2]:

self. room1()

else:

self. game_over()

# this method ends the program

def game_over(self):

quit()

Step-by-step explanation:

The simple python object oriented program defines class with three methods room1, room2 and game_over which are all linked from the __init__ method from where the room1 is call first.

User Malcolm Smith
by
4.8k points