Exemplo n.º 1
0
    def keyPressEvent(self, event):
        key = event.key()

        if key == Qt.Key_Escape:
            self.closeEvent(QCloseEvent())

        elif key == Qt.Key_R:
            self.logic_model.field.clear_field()
            self.logic_model.next_figure = None
            self.logic_model.next_color = None
            self.logic_model.current_figure = None
            self.logic_model.current_color = None
            self.logic_model.falling_figure = falling_figure.FallingFigure(
                self.logic_model)
            self.logic_model.fell_flag = False
            self.color_mode_button.setEnabled(True)
            self.current_rating_position = -1
            self.current_scores = 0
            self._record_panel_update()
            self.timer.start()

        elif key == Qt.Key_P:
            if self.timer.isActive():
                self.status_bar.showMessage('Pause')
                self.timer.stop()
            elif not self.logic_model.end_of_the_game():
                self.timer.start()

        elif self.timer.isActive():
            if key == Qt.Key_Left:
                self.logic_model.falling_figure.try_move(Direction.LEFT)

            elif key == Qt.Key_Right:
                self.logic_model.falling_figure.try_move(Direction.RIGHT)

            elif key == Qt.Key_Down:
                self.logic_model.falling_figure.try_move(Direction.DOWN)

            elif key == Qt.Key_Up:
                self.logic_model.falling_figure.try_rotate_left()

            elif key == Qt.Key_Space:
                self.logic_model.falling_figure.drop_figure()
                self.logic_model.falling_figure = \
                    falling_figure.FallingFigure(self.logic_model)
                self.logic_model.field.remove_completed_rectangle(
                    self.logic_model.falling_figure)
                self.logic_model.fell_flag = True

        self._grid_update()
Exemplo n.º 2
0
 def update(self):
     if self.falling_figure.check_move(Direction.DOWN):
         self.falling_figure.try_move(Direction.DOWN)
     else:
         self.falling_figure = falling_figure.FallingFigure(self.field)
         self.falling_figure.try_move(Direction.DOWN)
         self.field.remove_completed_line(self.falling_figure)
Exemplo n.º 3
0
 def update(self):
     if self.falling_figure.check_move(Direction.DOWN):
         self.falling_figure.try_move(Direction.DOWN)
     else:
         self.fell_flag = True
         self.falling_figure = falling_figure.FallingFigure(self)
         self.falling_figure.try_move(Direction.DOWN)
         self.field.remove_completed_rectangle(self.falling_figure)
Exemplo n.º 4
0
    def __init__(self, width=__FIELD_WIDTH, height=__FIELD_HEIGHT):
        self.current_figure = None
        self.current_color = None
        self.next_figure = None
        self.next_color = None

        self.field = field.Field(width, height)
        self.falling_figure = falling_figure.FallingFigure(self)
        self.fell_flag = False
Exemplo n.º 5
0
 def __init__(self, width=__FIELD_WIDTH, height=__FIELD_HEIGHT):
     self.field = field.Field(width, height)
     self.falling_figure = falling_figure.FallingFigure(self.field)