TartanLlama TartanLlama - 5 months ago 44
Python Question

Python User-Defined Data Type

I am writing a rogue-like game in Python and am defining my

class. A tile can either be blocked, wall or floor. I would like to be able to write something along the lines of

self.state = Blocked

similar to how you would use a boolean (but with three values).

Is there a nice way for me to define a data type to enable me to do this?



For three constants, I would use the unpacking version of the enum 'pattern':

Blocked, Wall, Floor = range(3)

If it gets more complex than that though, I would have a look at other enum types in python.