本文整理汇总了Python中statemachine.StateMachine.set_current_state方法的典型用法代码示例。如果您正苦于以下问题:Python StateMachine.set_current_state方法的具体用法?Python StateMachine.set_current_state怎么用?Python StateMachine.set_current_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statemachine.StateMachine
的用法示例。
在下文中一共展示了StateMachine.set_current_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Miner
# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import set_current_state [as 别名]
class Miner(BaseGameEntity):
def __init__(self, name):
self.name = name
self.location = None
self.gold = 0
self.fatigue = 0
self.thirsty = 0
self.fsm = StateMachine(self)
self.fsm.set_current_state(states.GoHomeAndSleepTilRested())
self.pocket_limit = 10
self.thirsty_limit = 10
self.fatigue_limit = 10
def __repr__(self):
return '<Miner {0}>'.format(self.name)
def change_location(self, location):
self.location = location
def is_pocket_full(self):
return self.gold >= self.pocket_limit
def add_gold_carried(self, n):
self.gold += n
def increase_fatigue(self):
self.fatigue += 1
self.thirsty += 1
def is_thirsty(self):
return self.thirsty >= self.thirsty_limit
示例2: Wife
# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import set_current_state [as 别名]
class Wife(BaseGameEntity):
def __init__(self, name):
self.name = name
self.fsm = StateMachine(self)
self.fsm.set_current_state(states.DoHouseWork())
self.fsm.set_global_state(states.WifeGlobalState())
def update(self):
self.fsm.update()
def handle_msg(self, sender, msg):
return self.fsm.handle_message(sender, self, msg)