changeset 444:f26c8ab57257

Use a simple for loop to determine the power level of the player; fixes a traceback when the SHT has no shot at all.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 Aug 2013 14:16:08 +0200
parents cae83b963695
children b0abb05811f7
files pytouhou/game/player.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/player.py
+++ b/pytouhou/game/player.py
@@ -114,7 +114,12 @@ class Player(Element):
 
     def fire(self):
         sht = self.focused_sht if self.state.focused else self.sht
-        power = min(power for power in sht.shots if self.state.power < power)
+
+        # Don’t use min() since sht.shots could be an empty dict.
+        power = 999
+        for shot_power in sht.shots:
+            if self.state.power < shot_power:
+                power = power if power < shot_power else shot_power
 
         bullets = self._game.players_bullets
         lasers = self._game.players_lasers