Created
August 10, 2017 16:53
-
-
Save Insood/3941aaabb84c4a6a5a5bc7de48287e59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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