Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored mark_score() and apply_powerup()

  • Loading branch information...
commit 60fd1e751b3b72f0cd98a7c812d8d4e25ad2a93e 1 parent 63baedb
@asweigart authored
Showing with 15 additions and 18 deletions.
  1. +15 −18 square-shooter/square-shooter_makeover.py
View
33 square-shooter/square-shooter_makeover.py
@@ -114,10 +114,10 @@ def collides_with(self, other):
class Bubble(ObjectOnMap):
- # (size, speed)
- kinds = {'big': (0.1, 0.1),
- 'medium': (0.075, 0.15),
- 'small': (0.05, 0.25)}
+ # (size, speed)
+ kinds = {'big': (0.1, 0.1),
+ 'medium': (0.075, 0.15),
+ 'small': (0.05, 0.25)}
colors = [pygame.Color('#ffffcc'),
pygame.Color('#ffccff'),
@@ -391,25 +391,22 @@ def spawn_explosion(self, bubble):
self.explosions.append(explosion)
def mark_score(self, bubble):
- if bubble.kind == "small":
- self.score += 5
- elif bubble.kind == "medium":
- self.score += 2
- elif bubble.kind == "big":
- self.score += 1
+ # score
+ kinds = {'big': 1,
+ 'medium': 2,
+ 'small': 5}
+ self.score += kinds[bubble.kind]
if self.score > self.high_score:
self.high_score = self.score
def apply_powerup(self, powerup):
- if powerup.kind == "shield":
- self.ship.add_shield()
- elif powerup.kind == "bullet":
- self.ship.add_super_bullets()
- elif powerup.kind == "freeze":
- self.ship.add_freeze()
- else:
- raise "Bad powerup type"
+ # function to call
+ kinds = {'shield': self.ship.add_shield,
+ 'bullet': self.ship.add_super_bullets,
+ 'freeze': self.ship.add_freeze}
+ kinds[powerup.kind]()
+
self.score += self.level * 10
if self.score > self.high_score:
Please sign in to comment.
Something went wrong with that request. Please try again.