Esempio n. 1
0
    def play(self):
        clock = pygame.time.Clock()
        move_down = pygame.USEREVENT + 1
        pygame.time.set_timer(move_down, 1000)
        current = None
        move_right = False
        move_left = False

        while not self.done:
            clock.tick(50)
            if self.spawn:
                self.pieces.append(T(self.current_id))
                self.current_id += 1
                current = self.pieces[-1]
                self.spawn = False

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.done = True
                if event.type == move_down:
                    if self.legal_move(0, 1, current):
                        current.move(0, 1)
                if event.type == pygame.KEYUP:
                    if event.key == pygame.K_RIGHT:
                        move_right = False
                    if event.key == pygame.K_LEFT:
                        move_left = False

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_LEFT:
                        if self.legal_move(-1, 0, current):
                            current.move(-1, 0)
                        #move_left = True
                    if event.key == pygame.K_RIGHT:
                        if self.legal_move(1, 0, current):
                            current.move(1, 0)
                        #move_right = True
                    if event.key == pygame.K_DOWN:
                        if self.legal_move(0, 1, current):
                            current.move(0, 1)
                    if event.key == pygame.K_UP:
                        current.rotate()
                    if event.key == pygame.K_SPACE:
                        while self.legal_move(0, 1, current):
                            current.move(0, 1)

            for i in range(10):
                for j in range(20):
                    self.display_background(i * self.block_size,
                                            j * self.block_size)

            if move_left:
                if self.legal_move(-1, 0, current):
                    current.move(-1, 0)
            if move_right:
                if self.legal_move(1, 0, current):
                    current.move(1, 0)
            self.display_pieces()

            pygame.display.flip()
Esempio n. 2
0
        sleep(espaceLettre)

    elif x.upper() == 'Q':
        Q()
        sleep(espaceLettre)

    elif x.upper() == 'R':
        R()
        sleep(espaceLettre)

    elif x.upper() == 'S':
        S()
        sleep(espaceLettre)

    elif x.upper() == 'T':
        T()
        sleep(espaceLettre)

    elif x.upper() == 'U':
        U()
        sleep(espaceLettre)

    elif x.upper() == 'V':
        V()
        sleep(espaceLettre)

    elif x.upper() == 'W':
        W()
        sleep(espaceLettre)

    elif x.upper() == 'X':