Skip to content

Instantly share code, notes, and snippets.

@Insood
Created Aug 10, 2017
Embed
What would you like to do?
class GameState:
def __init__(self):
self.handlers = {}
def default_handler(self,sw_number):
print( "Switch %s pushed!"%sw_number)
def on_switch(self,sw_number):
if sw_number in self.handlers:
self.handlers[sw_number]()
else:
self.default_handler(sw_number)
def my_special_handler():
print( "Special handler ^_~")
g = GameState()
g.handlers[12] = my_special_handler
g.on_switch(1)
g.on_switch(12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment