| 218 | |
| 219 | |
| 220 | class BrickWall(pygame.sprite.Group): |
| 221 | def __init__(self, screen, x, y, width, height): |
| 222 | self.__screen = screen |
| 223 | self._x = x |
| 224 | self._y = y |
| 225 | self._width = width |
| 226 | self._height = height |
| 227 | self._bricks = [] |
| 228 | |
| 229 | X = x |
| 230 | Y = y |
| 231 | for i in range(3): |
| 232 | for j in range(4): |
| 233 | self._bricks.append(Brick(screen, width, height, X, Y)) |
| 234 | X += width + (width / 7.0) |
| 235 | Y += height + (height / 7.0) |
| 236 | X = x |
| 237 | |
| 238 | def add(self, brick): |
| 239 | """ |
| 240 | adds a brick to this BrickWall (group) |
| 241 | """ |
| 242 | self._bricks.append(brick) |
| 243 | |
| 244 | def remove(self, brick): |
| 245 | """ |
| 246 | removes a brick from this BrickWall (group) |
| 247 | """ |
| 248 | self._bricks.remove(brick) |
| 249 | |
| 250 | def draw(self): |
| 251 | """ |
| 252 | draws all bricks onto screen. |
| 253 | """ |
| 254 | for brick in self._bricks: |
| 255 | if brick != None: |
| 256 | brick.draw() |
| 257 | |
| 258 | def update(self, ball): |
| 259 | """ |
| 260 | checks collision between ball and bricks. |
| 261 | """ |
| 262 | for i in range(len(self._bricks)): |
| 263 | if (self._bricks[i] != None) and self._bricks[i].collide(ball): |
| 264 | self._bricks[i] = None |
| 265 | |
| 266 | # removes the None-elements from the brick list. |
| 267 | for brick in self._bricks: |
| 268 | if brick is None: |
| 269 | self._bricks.remove(brick) |
| 270 | |
| 271 | def hasWin(self): |
| 272 | """ |
| 273 | Has player win the game? |
| 274 | """ |
| 275 | return len(self._bricks) == 0 |
| 276 | |
| 277 | def collide(self, ball): |