Ejemplo n.º 1
0
    def checkForFullRow(self, background, occupied_blocks, screen, piece):
        #check occupied_blocks for full row
        block_positions = piece.getCurrentCoordinates()
        #min_position is the top of the highest sub_block in the piece that was just placed
        min_position = min([x['y'] for x in block_positions])

        y = Globals.screen_height
        while y >= min_position:  #todo: >= here?

            if len([x for x in occupied_blocks if x['y'] == y]) == 10:
                self.rows_eliminated += 1
                self.to_next_level += 1
                if self.to_next_level >= 10:
                    self.time_delay -= 20
                    self.to_next_level = 0
                    self.level += 1
                #at this point a row has been filled and I need to delete it
                occupied_blocks[:] = [
                    x for x in occupied_blocks if x['y'] != y
                ]  #using a slice to modify list in place
                #now move the blocks ABOVE the deleted row down a notch
                for block in occupied_blocks:
                    if block['y'] < y: block['y'] += Globals.block_height

                #the items have been deleted from occupied_blocks....now redraw everything
                background.fill(self.game_screen_color)
                screen.blit(background, (0, 0))
                for block in occupied_blocks:
                    Globals.drawBlock(screen, block['color'], block)
                self.level_label = self.font.render(
                    "Level: " + str(self.level), 1, (255, 255, 255))
                self.rows_eliminated_label = self.font.render(
                    "Rows Eliminated: " + str(self.rows_eliminated), 1,
                    (255, 255, 255))
                self.window_screen.fill((0, 0, 0))
                self.window_screen.blit(self.level_label, (450, 80))
                self.window_screen.blit(self.rows_eliminated_label, (450, 100))
                self.window_screen.blit(screen, (self.game_screen_start_x, 0))
                pygame.display.update(
                )  #update this during the loop to give the effect of removing rows one at a time
                background = screen.copy()
                pygame.time.delay(250)
            else:
                y -= Globals.block_height
        return background
Ejemplo n.º 2
0
    def checkForFullRow(self, background, occupied_blocks, screen, piece):
        #check occupied_blocks for full row
        block_positions = piece.getCurrentCoordinates()
        #min_position is the top of the highest sub_block in the piece that was just placed
        min_position = min([x['y'] for x in block_positions])

        y = Globals.screen_height
        while y >= min_position: #todo: >= here?

            if len([x for x in occupied_blocks if x['y'] == y]) == 10:
                self.rows_eliminated += 1
                self.to_next_level += 1
                if self.to_next_level >= 10:
                    self.time_delay -= 20
                    self.to_next_level = 0
                    self.level += 1
                #at this point a row has been filled and I need to delete it
                occupied_blocks[:] = [x for x in occupied_blocks if x['y'] != y] #using a slice to modify list in place
                #now move the blocks ABOVE the deleted row down a notch
                for block in occupied_blocks:
                    if block['y'] < y: block['y'] += Globals.block_height

                #the items have been deleted from occupied_blocks....now redraw everything
                background.fill(self.game_screen_color)
                screen.blit(background, (0,0))
                for block in occupied_blocks:
                    Globals.drawBlock(screen, block['color'], block)
                self.level_label = self.font.render("Level: " + str(self.level), 1, (255,255,255))
                self.rows_eliminated_label = self.font.render("Rows Eliminated: " + str(self.rows_eliminated), 1, (255,255,255))
                self.window_screen.fill((0,0,0))
                self.window_screen.blit(self.level_label, (450, 80))
                self.window_screen.blit(self.rows_eliminated_label, (450, 100))
                self.window_screen.blit(screen, (self.game_screen_start_x,0))
                pygame.display.update() #update this during the loop to give the effect of removing rows one at a time
                background = screen.copy()
                pygame.time.delay(250)
            else: y -= Globals.block_height
        return background
Ejemplo n.º 3
0
 def draw(self, screen):
     for pair in self.block_coordinates:
         Globals.drawBlock(screen, self.color, pair)
     pygame.display.update()
Ejemplo n.º 4
0
 def draw(self, screen):
     for pair in self.block_coordinates:
         Globals.drawBlock(screen, self.color, pair)
     pygame.display.update()