[Tutor] python game error

Alan Gauld alan.gauld at yahoo.co.uk
Mon Oct 15 05:02:33 EDT 2018

On 15/10/18 08:57, Peter Otten wrote:

> By the way, you do not need a map (dict) at all to implement a game like 
> this, you may return the next scene directly. A sketch:
> class Bridge:
>     def enter(self):
>         ...
>         action = ...
>         if action == "jump off the bridge":
>             return Death("You are eaten by the piranhas")
>         else:
>             ...

That was my initial thought when I saw this but thee is one
caveat. The original design creates a single instance of a
scene and returns that on each access. The suggestion above
creates a new instance on every call. So if it is important
to use the same instance each time then the map is a
better solution.

(Although you could instead create a class variable holding
the first instance of itself then use a class  constructor
to either create the instance or access the class variable...)

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list