예제 #1
0
 def draw_ghost(self, screen, board):
     temp_origin = self.origin
     reached_bottom = False
     while not reached_bottom:
         for cell in self.shapes[self.orientation]:
             if not board.is_free(utils.add_coordinates(temp_origin, cell)):
                 reached_bottom = True
         if reached_bottom:
             temp_origin = utils.add_coordinates(
                 temp_origin, (0, 1))  # this is stupid and hacky
             break
         temp_origin = utils.add_coordinates(temp_origin, (0, -1))
     for offset in self.shapes[self.orientation]:
         mino = utils.make_mino(utils.add_coordinates(temp_origin, offset))
         color = (100, 100, 100)
         pygame.draw.rect(screen, color, mino)
예제 #2
0
 def rotate(self, amount, board):
     for check in CHECKS:
         new_orientation = (self.orientation + amount) % 4
         new_origin = utils.add_coordinates(self.origin, check)
         if self.valid_position(new_origin, new_orientation, board):
             self.orientation = new_orientation
             self.origin = new_origin
             return
예제 #3
0
 def valid_position(self, point, orientation, board):
     for cell in self.shapes[orientation]:
         coordinate = utils.add_coordinates(point, cell)
         if coordinate[1] >= HEIGHT or coordinate[1] < 0:
             return False
         elif coordinate[0] >= WIDTH or coordinate[0] < 0:
             return False
         elif board.matrix[coordinate[1]][coordinate[0]] != 'x':
             return False
     return True
예제 #4
0
 def hard_drop(self, board):
     while self.valid_position(utils.add_coordinates(self.origin, (0, -1)),
                               self.orientation, board):
         self.origin = utils.add_coordinates(self.origin, (0, -1))
예제 #5
0
 def move(self, offset, board, ignore_das=False):
     if self.valid_position(utils.add_coordinates(self.origin, offset),
                            self.orientation, board):
         self.origin = utils.add_coordinates(self.origin, offset)
예제 #6
0
 def draw(self, screen):
     for offset in self.shapes[self.orientation]:
         mino = utils.make_mino(utils.add_coordinates(self.origin, offset))
         color = utils.get_color(self.id)
         pygame.draw.rect(screen, color, mino)