예제 #1
0
파일: states.py 프로젝트: hubrys/tytrys
 def _restart(self):
     """Restart game with default values"""
     self.board = Board(10, 22)
     self.next_piece = random_tetromino(0, 0)
     self.current_piece = random_tetromino(5, 20)
     self.drop_time = .5
     self.current_key = -1
     self.lines_to_next_level = 15
     self.level = 1
     self.score = 0
     self.view_modified = True
예제 #2
0
파일: states.py 프로젝트: hubrys/tytrys
    def update(self, delta):
        self.elapsed_time += delta
        self.handle_user_input()

        if self.elapsed_time >= self.drop_time:
            if self.board.are_valid_coordinates(
                    self.current_piece.move_result(Direction.Down)):
                renderer.clear_tetromino(self.current_piece, self.board_window)
                self.current_piece.move(Direction.Down)
            else:
                renderer.clear_tetromino(self.next_piece, self.info_window)
                try:
                    self.board.lock_tetromino(self.current_piece)
                    self.current_piece = self.next_piece
                    self.current_piece.set_location(5, 20)
                    self.next_piece = random_tetromino(0, 0)

                    rows_removed = self.board.clear_full_rows()
                    if rows_removed:
                        self.lines_to_next_level -= rows_removed
                        self.score += sum(range(rows_removed + 1)) * 100
                        if self.lines_to_next_level <= 0:
                            self.score += 1000 * self.level
                            self.lines_to_next_level = 15
                            self.level += 1
                            self.drop_time *= .75
                except RuntimeError:
                    game.add_state_and_switch("game over",
                                              GameOverState(self.window,
                                                            self.score))

            self.view_modified = True
            self.elapsed_time -= self.drop_time
예제 #3
0
파일: states.py 프로젝트: hubrys/tytrys
    def __init__(self, window):
        super(GameState, self).__init__(window)
        # These lines are so that I don't have to stare at warnings
        # restart sets these to the right values
        self.board = Board(10, 22)
        self.next_piece = random_tetromino(0, 0)
        self.current_piece = random_tetromino(5, 20)
        self.drop_time = .5
        self.current_key = -1
        self.lines_to_next_level = 15
        self.level = 1
        self.score = 0
        self.view_modified = True

        self._restart()
        self.board_window = window.derwin(
            self.board.height, self.board.width + 2, 0, 0)
        self.info_window = window.derwin(
            self.board.height, 8, 0, self.board.width + 2)