Beispiel #1
0
    def check_levels_full(self):
        global screen
        boundary_list, blocks = tuple(get_lists())
        full_levels = []
        full_levels.sort()  #So that the lower levels are deleted first
        
        for n  in range(0,15):
            if self.level_list[n] >= 10:
                full_levels.append(n)
        if not(full_levels):
            return None

        delete_level_animation(full_levels)       
        def move_levels(full_level_list):
            level = full_level_list[0]
            blokk_count = 0
            while blokk_count < 10:
                for blokk in blocks:
                    if int(blokk.midpoint[1]) == (29*15)-30*(level):#Use of algebra from the definition of level above
                        boundaries_found = 0
                        while boundaries_found <= 4:  #For some reason the program manages to find 5 boundaries for each block, despite it having 4 sides
                            for boundary1 in blokk.boundaries:                        
                                if boundary1 in boundary_list:
                                    del boundary_list[boundary_list.index(boundary1)]
                                    boundaries_found += 1
                                    break
                        del blocks[blocks.index(blokk)]
                        blokk_count += 1
                        print blokk_count
                        break

        
            for blokk in blocks:
                if int(blokk.midpoint[1]) < (29*15)-30*(level):              
                    blokk.move((0,30))
                    for boundary in blokk.boundaries:
                        boundary.update((0,BLOCK_SIZE))
            if len(full_level_list) > 1:
                full_level_list = full_level_list[1:]
                for lvl in enumerate(full_level_list):
                    full_level_list[lvl[0]] -= 1      #Since blocks are brought down a level
                return move_levels(full_level_list)
            
        move_levels(full_levels)
        
        draw_screen(screen)
        pygame.display.flip()
        set_lists(boundary_list,blocks)
Beispiel #2
0
import pygame
import math
from utilities import Block, Boundary, Grid
from tetronimoes import *
import game_controls
from globals_and_constants import *
import random


floor = Boundary((EDGES,screen_size[1]-EDGES),(screen_size[0]-EDGES,screen_size[1]-EDGES)) #Note: unlike the others above, which are constants, this is a global variable
boundary_list.append(Boundary( (EDGES,screen_size[1]-EDGES),(EDGES,0) ))
boundary_list.append(Boundary((screen_size[0]-EDGES,screen_size[1]-EDGES),(screen_size[0]-EDGES,0)))
boundary_list.append(floor)

game_controls.draw_screen(screen)
pygame.display.flip()            

#Setting main boundaries at the edge of the screen
startpos = [85,-5]
tetrominoes = ["O","I","J","L","T","S","Z"]
grid = Grid()
while True: #Randomly chooses a tetrominoe and then passes it to the main method of the game_controls 
    blocks = get_lists()[1]
    index = random.randint(0,6)  
    letter = tetrominoes[index]
    string = [letter,"(",str(startpos),")"]
    string = ''.join(string)
    argument = eval(string)    
    game_controls.main(argument)  #Check that blocks and boundary_list are passed correctly around the program
    max_level = grid.update()
    grid.check_levels_full()