Permalink
Browse files

Corrected score handling.

  • Loading branch information...
1 parent fbbc93e commit 57b73424c9b5efed1e885fe6da2be5e8244439d3 Nameless committed Oct 6, 2012
Showing with 11 additions and 12 deletions.
  1. +4 −5 levelui.py
  2. +7 −7 main.py
View
@@ -56,8 +56,6 @@ def run(self):
if not hasattr(self, "score_text"):
self.score_text = StringVar()
self.score_text.set("Score: %d" % self.starting_score)
- else:
- print self.score_text.get()
score_label = Label(self.status_panel, textvariable=self.score_text)
score_label.pack(side="right")
@@ -108,13 +106,14 @@ def check_input(self):
self.set_score(int(m.group(1)))
except ValueError:
logger.error("Received new score with invalid value: '%s'" % m.group(1))
- elif re.match(r'start (\d+)', event):
- m = re.match(r'start (\d+)', event)
+ elif re.match(r'start (\d+) (\d+)', event):
+ m = re.match(r'start (\d+) (\d+)', event)
try:
self.level_number = int(m.group(1))
+ self.set_score(int(m.group(2)))
self.run()
except ValueError:
- logger.error("Received request to start invalid level: '%s'" % m.group(1))
+ logger.error("Received invalid request to start: '%s'" % event)
elif event == "complete":
self.completed = True
except Empty:
View
14 main.py
@@ -55,7 +55,7 @@ def current_transitions(self):
return self._transitions[self._current_state_name]
def build_ui(self):
- self._current_state.display()
+ self._current_state.display(self.total_score)
def run(self):
quit = False
@@ -68,8 +68,9 @@ def run(self):
logger.debug("Received event: %s" % str(event))
if event in self.current_transitions():
- self.total_score += self._current_state.score
+ self.total_score = self._current_state.score
self.change_state(event)
+
if isinstance(self._current_state, Exit):
break
@@ -95,7 +96,7 @@ def cleanup(self):
pass
class Level(State):
- def __init__(self, level_number, in_queue, out_queue):
+ def __init__(self, level_number, in_queue, out_queue, score=0):
self.level_number = level_number
self.in_queue = in_queue
self.out_queue = out_queue
@@ -106,7 +107,7 @@ def __init__(self, level_number, in_queue, out_queue):
self.ship_timer = Timer(-math.log(random.random())/self.ship_rate, self.ship_appearance, ())
self.number_of_ships = 0
self.max_number_of_ships = 2
- self.score = 0
+ self.score = score
self.score_per_ship = 50*self.level_number
logger.debug("Level %d created." % level_number)
@@ -119,9 +120,8 @@ def cleanup(self):
logger.debug("Cleaning up level %d" % self.level_number)
self.ship_timer.cancel()
- def display(self):
- self.update_score()
- self.out_queue.put("start %d" % self.level_number)
+ def display(self, score):
+ self.out_queue.put("start %d %d" % (self.level_number, score))
logger.debug("UI built for level %d" % self.level_number)

0 comments on commit 57b7342

Please sign in to comment.