當前位置: 首頁>>代碼示例>>Python>>正文


Python StateMachine.set_current_state方法代碼示例

本文整理匯總了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
開發者ID:xiangxiaobaog3,項目名稱:codelab,代碼行數:35,代碼來源:miner.py

示例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)
開發者ID:xiangxiaobaog3,項目名稱:codelab,代碼行數:14,代碼來源:miner.py


注:本文中的statemachine.StateMachine.set_current_state方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。