Last active
April 26, 2018 15:36
-
-
Save djm4686/fd98d09fd30f3e8d0528c6fbe86caaf2 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 Action: | |
MOVE = 0 | |
ATTACK = 1 | |
HOLD_POSITION = 2 | |
def get_attacked(thing) | |
thing.get_attacked() | |
def move(thing, position) | |
thing.move(position) | |
def hold_position(thing): | |
thing.hold_position() | |
table = {} | |
thing = SomeThingThatHasActions() | |
position = (0, 0) | |
table[Action.MOVE] = move, {"thing": thing, "position": position} | |
table[Action.ATTACK] = get_attacked, {"thing": thing} | |
table[Action.HOLD_POSITION] = hold_position, {"thing": thing} | |
table[thing.action][0](**table[thing.action][1]) # this is the money maker, no if statements, yet can do three different things based on thing's "action" property | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment