本文整理汇总了Python中screen.Screen.remove_cell方法的典型用法代码示例。如果您正苦于以下问题:Python Screen.remove_cell方法的具体用法?Python Screen.remove_cell怎么用?Python Screen.remove_cell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类screen.Screen
的用法示例。
在下文中一共展示了Screen.remove_cell方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import remove_cell [as 别名]
class GameOfLife:
"""
An instance of the game of life.
"""
SAVE_FILENAME = "saved_game.gol"
RECORD_FILENAME = "recorded_game.gol"
REPLAY_FILENAME = "replay_game.gol"
def __init__(self, stdscr):
self.mode = Mode.NORMAL
self.screen = Screen(stdscr)
self.board = Board()
self.start()
@property
def mode(self):
return self._mode.get_code()
@mode.setter
def mode(self, value):
if value == Mode.INSERT:
self._mode = InsertMode()
elif value == Mode.NORMAL:
self._mode = NormalMode()
elif value == Mode.PAN:
self._mode = PanMode()
elif value == Mode.RECORD:
self._mode = RecordMode()
elif value == Mode.REPLAY:
self._mode = ReplayMode()
def start(self):
"""
Starts the Game of Life
"""
self.refresh_screen()
continue_execution = True
while continue_execution:
input_key = self.screen.get_input_key()
continue_execution = self.dispatch_user_command(input_key)
def dispatch_user_command(self, input_key):
"""
Takes a user input and decides what to do about it
"""
# Dispatch command to the current mode
self._mode.dispatch_user_command(self, input_key)
# Common commands for all Modes
if input_key == Command.QUIT:
return False
elif input_key == Command.INSERT_MODE:
self.mode = Mode.INSERT
elif input_key == Command.NORMAL_MODE:
self.mode = Mode.NORMAL
elif input_key == Command.PAN_MODE:
self.mode = Mode.PAN
elif input_key == Command.RECORD_MODE:
self.mode = Mode.RECORD
elif input_key == Command.REPLAY_MODE:
self.mode = Mode.REPLAY
elif input_key == Command.INSERT_CELL:
self.add_cell(self.screen.cursor_position)
elif input_key == Command.DELETE_CELL:
self.remove_cell(self.screen.cursor_position)
elif input_key == Command.SAVE_BOARD:
self.save()
elif input_key == Command.LOAD_BOARD:
self.load()
return True
def add_cell(self, position):
self.board.add_cell(position)
self.screen.add_cell(position)
def remove_cell(self, position):
self.board.remove_cell(position)
self.screen.remove_cell(position)
def refresh_screen(self):
self.screen.save_cursor()
self.screen.clear()
for point in self.board.cells:
self.screen.add_cell(point)
self.screen.restore_cursor()
def step(self):
self.board.step()
self.refresh_screen()
def replay_step(self):
if not hasattr(self, "replay_fhandle"):
self.replay_fhandle = open(self.REPLAY_FILENAME)
try:
serialized_board_state = self.replay_fhandle.readline()
self.board.load_serialized_board(serialized_board_state)
self.refresh_screen()
except:
return
def save(self):
#.........这里部分代码省略.........