Skip to content

Instantly share code, notes, and snippets.

@djm4686
Last active April 26, 2018 15:36
Show Gist options
  • Save djm4686/fd98d09fd30f3e8d0528c6fbe86caaf2 to your computer and use it in GitHub Desktop.
Save djm4686/fd98d09fd30f3e8d0528c6fbe86caaf2 to your computer and use it in GitHub Desktop.
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