Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactored mark_score() and apply_powerup()

  • Loading branch information...
commit 60fd1e751b3b72f0cd98a7c812d8d4e25ad2a93e 1 parent 63baedb
Al Sweigart authored August 09, 2012

Showing 1 changed file with 15 additions and 18 deletions. Show diff stats Hide diff stats

  1. 33  square-shooter/square-shooter_makeover.py
33  square-shooter/square-shooter_makeover.py
@@ -114,10 +114,10 @@ def collides_with(self, other):
114 114
 
115 115
 
116 116
 class Bubble(ObjectOnMap):
117  
-    #                   (size, speed)
118  
-    kinds  = {'big':    (0.1,   0.1),
119  
-              'medium': (0.075, 0.15),
120  
-              'small':  (0.05,  0.25)}
  117
+    #                  (size, speed)
  118
+    kinds = {'big':    (0.1,   0.1),
  119
+             'medium': (0.075, 0.15),
  120
+             'small':  (0.05,  0.25)}
121 121
 
122 122
     colors = [pygame.Color('#ffffcc'),
123 123
               pygame.Color('#ffccff'),
@@ -391,25 +391,22 @@ def spawn_explosion(self, bubble):
391 391
         self.explosions.append(explosion)
392 392
 
393 393
     def mark_score(self, bubble):
394  
-        if bubble.kind == "small":
395  
-            self.score += 5
396  
-        elif bubble.kind == "medium":
397  
-            self.score += 2
398  
-        elif bubble.kind == "big":
399  
-            self.score += 1
  394
+        #                  score
  395
+        kinds = {'big':    1,
  396
+                 'medium': 2,
  397
+                 'small':  5}
  398
+        self.score += kinds[bubble.kind]
400 399
 
401 400
         if self.score > self.high_score:
402 401
             self.high_score = self.score
403 402
 
404 403
     def apply_powerup(self, powerup):
405  
-        if powerup.kind == "shield":
406  
-            self.ship.add_shield()
407  
-        elif powerup.kind == "bullet":
408  
-            self.ship.add_super_bullets()
409  
-        elif powerup.kind == "freeze":
410  
-            self.ship.add_freeze()
411  
-        else:
412  
-            raise "Bad powerup type"
  404
+        #                  function to call
  405
+        kinds = {'shield': self.ship.add_shield,
  406
+                 'bullet': self.ship.add_super_bullets,
  407
+                 'freeze': self.ship.add_freeze}
  408
+        kinds[powerup.kind]()
  409
+
413 410
         self.score += self.level * 10
414 411
 
415 412
         if self.score > self.high_score:

0 notes on commit 60fd1e7

Please sign in to comment.
Something went wrong with that request. Please try again.