state pattern import curses import time class state(object)def __init__(selfstate_machine)self state_machine state_machine def switch(selfin_key)if in_key in self state_machine mappingself state_machine state self state_machine mapping[in_keyelseself state_machine state self state_machine mapping["default"class standing(state)def __str__(self)return "standingclass runningleft(state)def __str__(self)return "running leftclass runningright(state)def __str__(self)return "running rightclass jumping(state)def __str__(self)return "jumpingclass crouching(state)def __str__(self)return "crouchingclass statemachine(object)def __init__(self)self standing standing(selfself running_left runningleft(selfself running_right runningright(self