本文整理汇总了Python中state.State.change_state方法的典型用法代码示例。如果您正苦于以下问题:Python State.change_state方法的具体用法?Python State.change_state怎么用?Python State.change_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.change_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Player
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import change_state [as 别名]
class Player(object):
_count = 0
def __init__(self, name=None):
Player._count += 1
self._count = Player._count
self.state = State(self)
if name is None:
self._name = 'Player#{}'.format(self._count)
self._isHuman = False
else:
self._name = name
self._isHuman = True
self._score = 0
self._wins = 0
def __str__(self):
return self._name
def __repr__(self):
return str(self)
def get_name(self):
return self._name
def get_score(self):
return self._score
def update_score(self,score):
if score <= 0:
raise ValueError
self._score += score
def ask_to_hold(self, dice):
if self._isHuman:
choice = raw_input(HOLD_SCREEN.format(dice))
else:
tmp = str(get_choice(dice))
choice = ' '
for i in tmp:
try:
int(i)
choice += str(i) + ' '
except:
pass
return choice
def change_player(self):
self.state.change_state()
def get_current(self):
return State.get_current()
示例2: __init__
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import change_state [as 别名]
class SampleObj:
STATE_STOPPED = 'Stopped'
STATE_STARTED = 'Started'
STATE_PAUSED = 'Paused'
def __init__(self):
self.log = logging.getLogger(self.__class__.__name__)
self.last_handler = None
self.state = State(self, self.STATE_STOPPED, {self.STATE_PAUSED : 30})
def identify_state(self, event):
return self.state.identify_state(event)
# Commands
@Dispatcher.event_handler
def Start(self, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
@Dispatcher.event_handler
def Stop(self, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
@Dispatcher.event_handler
def Pause(self, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
# Stopped
def inStopped_onStart(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
self.state.change_state(self.STATE_STARTED)
def inStopped_onEnter(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
def inStopped_onLeave(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
def inStopped_onDefault(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
# Started
def inStarted_onPause(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
self.state.change_state(self.STATE_PAUSED)
def inStarted_onStop(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
self.state.change_state(self.STATE_STOPPED)
def inStarted_onEnter(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
def inStarted_onLeave(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
def inStarted_onDefault(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
# Paused
def inPaused_onStart(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
self.state.change_state(self.STATE_STARTED)
def inPaused_onStop(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
self.state.change_state(self.STATE_STOPPED)
def inPaused_onEnter(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
def inPaused_onLeave(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
def inPaused_onDefault(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
# Default
def onEnter(self, event, *args, **kwargs):
self.last_handler = sys._getframe().f_code.co_name
self.log.debug(sys._getframe().f_code.co_name + '')
def onLeave(self, event, *args, **kwargs):
#.........这里部分代码省略.........