Ex.43 Issues getting Simple Skeleton to run

Currently trying to bridge the concept of classes calling on one another and how they interact. After struggling to understand their relationships I decided to make a simple skeleton of the game Zed made (check below). Currently getting an AtrributeError for current_scene.enter(), and im not sure how. Can anyone help me run this so I can step it out fully? Also if anyone has a resource that can elaborate more on how the class methods are being called to one another that would be greatly appreciated.

class Scene(object):

def enter(self):
	print('This scene is not yet configured')
	exit(1)

class Engine(object):

def __init__(self, scene_map):
	self.scene_map = scene_map

def play(self):
	current_scene = self.scene_map.opening_scene()
	last_scene = self.scene_map.next_scene('finished')

	while current_scene != last_scene:
		next_scene_name = current_scene.enter()
		current_scene = self.scene_map.next_scene(next_scene_name)

	current_scene.enter()

class Death(Scene):

quips = [
'You died haha']

def enter(self):
	print(Death.quips[randint(0, len(self.quips)-1)])
	exit(1)

class CentralArea(Scene):

def enter(self):
	print('The is the game start')

	action = ('> ')

	if action == 'Die':
		print('You died')
		return 'death'
	elif action == 'Die Again':
		print('You died another way')
		return 'death'
	elif action == 'Forward':
		print('Moving to next')
		return 'Escapepod'

	else:
		print('Doesnt make sense')
		return 'CentralArea'

class EscapePod(Scene):

def enter(self):
	print('This is escaped pod room')
	guess = input('Type number 5 to win, or anything else to die')

	if guess == '5':
		print('You win good job')
		return 'finished'

	if guess != '5':
		print('You died')
		return 'death'

class Finished(Scene):

def enter(self):
	print('You win good job')
	return 'finished'

class Map(object):

scenes = {
	'CentralArea': CentralArea(),
	'death': Death(),
	'Escapepod': EscapePod(),
	'finished': Finished()
}


def __init__(self, start_scene):
	self.start_scene = start_scene

def next_scene(self, scene_name):
	val = Map.scenes.get(scene_name)

def opening_scene(self):
	return self.next_scene(self.start_scene)

a_map = Map(‘CentralArea’)
a_game = Engine(a_map)
a_game.play()

In Map.next_scene() you need to return val. Otherwise it will return None and that doesn’t have the enter method.

2 Likes