Exemple #1
0
    def handle_user_input(self):
        direction = None
        key_pressed = self.window.getch()
        if key_pressed in (ord('j'), ord('J'), curses.KEY_LEFT):
            direction = Direction.Left
        elif key_pressed in (ord('l'), ord('L'), curses.KEY_RIGHT):
            direction = Direction.Right
        elif key_pressed in (ord('i'), ord('I'), curses.KEY_UP):
            direction = Direction.CCW
        elif key_pressed in (ord('k'), ord('K'), curses.KEY_DOWN):
            direction = Direction.CW
        elif key_pressed in (ord('q'), ord('Q')):
            self.view_modified = True
            game.switch_to_state("paused")
        elif key_pressed == ord(' '):
            self.drop_current_piece()

        if direction is not None:
            if direction == Direction.CCW or direction == Direction.CW:
                if self.board.are_valid_coordinates(
                        self.current_piece.rotate_result(direction)):
                    renderer.clear_tetromino(self.current_piece,
                                             self.board_window)
                    self.view_modified = True
                    self.current_piece.rotate(direction)
            else:
                if self.board.are_valid_coordinates(
                        self.current_piece.move_result(direction)):
                    renderer.clear_tetromino(self.current_piece,
                                             self.board_window)
                    self.view_modified = True
                    self.current_piece.move(direction)
Exemple #2
0
 def __init__(self, window):
     super().__init__(window)
     self.choices = (("New Game", lambda: game.switch_to_state("game", "restart")),
                     ("Help", lambda: game.add_state_and_switch(
                         "help", HelpState(self.window, "paused"))),
                     ("Quit", lambda: game.switch_to_state("finished")))
     self.lines_to_skip = 4
     self.line_to_start = 9
Exemple #3
0
    def __init__(self, window, score):
        super(GameOverState, self).__init__(window)
        self.score = score

        def start_new_game():
            game.remove_state("game over")
            game.switch_to_state("game", "restart")

        self.choices = (("New Game", start_new_game),
                        ("Quit", lambda: game.switch_to_state("finished")))
        self.lines_to_skip = 3
        self.line_to_start = 15
Exemple #4
0
 def start_new_game():
     game.remove_state("game over")
     game.switch_to_state("game", "restart")
Exemple #5
0
 def go_back():
     game.remove_state("help")
     game.switch_to_state(self.state_identifier)