本文整理汇总了Python中timer.Timer.resume方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.resume方法的具体用法?Python Timer.resume怎么用?Python Timer.resume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.resume方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PyTetrisModel
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import resume [as 别名]
class PyTetrisModel(object):
blockList = {"I": Block([[1, 1, 1, 1]]),
"J": Block([[1, 0, 0],
[1, 1, 1]]),
"L": Block([[0, 0, 1],
[1, 1, 1]]),
"O": Block([[1, 1],
[1, 1]]),
"S": Block([[0, 1, 1],
[1, 1, 0]]),
"T": Block([[0, 1, 0],
[1, 1, 1]]),
"Z": Block([[1, 1, 0],
[0, 1, 1]])}
blockColorList = [(0, 0, 0),
(194, 54, 33),
(37, 188, 36),
(173, 173, 39),
(73, 46, 255),
(211, 56, 211),
(51, 187, 200),
(203, 204, 205)]
def __init__(self):
self._state = "initialized"
self._difficulty = 'crazy'
# map 以左上角为原点,从左往右是 x 正方向,从上往下是 y 正方向。
#
# (0, 0) (1, 0) (2, 0) ... (9, 0)
# (0, 1) (1, 1) (2, 1) ... (9, 1)
# ... ... ... ... ...
# (0, 19) (1, 19) (2, 19) ... (9, 19)
#
self.map = Block([[None]*10 for i in range(20)])
self.timer = None
self.next_block = Block([[]])
self.active_block = Block([[]])
self.active_block_position = (0, 0)
self.gameover_callback = None
# 在按左右方向键时,可能会和正在对自身进行访问的 tick 函数造成的冲突。
# 所以这儿准备一个 Lock 。
self.lock = Lock()
self.score = 0
@property
def difficulty(self):
return self._difficulty
@difficulty.setter
def difficulty(self, value):
if self.state == "initialized":
if value in DIFFICULTY.keys():
self.difficulty = value
else:
raise NoSuchDifficulty
else:
raise WrongState
@property
def state(self):
return self._state
@state.setter
def state(self, value):
stderr.write("model: set state to " + str(value) + "\n")
self._state = value
def start(self):
if self.state == "initialized":
self.state = "start"
self.timer = Timer(target=self.tick,
interval=DIFFICULTY[self.difficulty]['interval'])
self.timer.run()
else:
stderr.write("model: the state is not initialized, can not start the game")
def pause(self):
self.timer.pause()
def resume(self):
self.timer.resume()
def press_arrow_key(self, direction):
if self.state == "falling":
with self.lock:
#.........这里部分代码省略.........