Commits

Alexander Schremmer  committed 640e0f6

Introduce game runner states, remodel end of game rendering.

  • Participants
  • Parent commits 65fe5ae

Comments (0)

Files changed (2)

File domination/gameengine.py

                 + " " + reason, player.deck)
 
 
+FRESH = "fresh"
+RUNNING = "running"
+ENDED = "ended"
+
 class GameRunner(Thread):
     def __init__(self, game, owner):
         Thread.__init__(self)
         self.seqno_condition = Condition()
         self.waiting_for = None
         self.owner = owner
-        self.fresh = True
+        self.state = FRESH
 
     def startable(self, player):
-        return self.fresh and player is self.owner and not self.is_alive()\
+        return self.state is FRESH and player is self.owner and not self.is_alive()\
                 and len(self.game.players) > 1
 
     @property
     def joinable(self):
-        return self.fresh
+        return self.state is FRESH
 
     def run(self):
         try:
             pass
         except:
             self.owner.request_queue.append(DebugRequest(sys.exc_info()))
-            self.increment_seqno()
+        self.state = ENDED
+        self.increment_seqno()
 
     def increment_seqno(self):
         self.seqno_condition.acquire()
         self.seqno_condition.release()
 
     def _run(self):
-        self.fresh = False
+        self.state = RUNNING
         gen = self.game.play_game()
         reply = None
         while True:
         self.players = []
         self.supply = {}
         self.trash_pile = []
+        self.end_of_game_reason = "Aborted!"
         self.name = name
 
     def add_supply(self, cls, no):
                 player.prepare_hand()
             reason = self.check_end_of_game()
             if reason:
-                for req in self.end_of_game(reason):
-                    yield req
+                self.end_of_game_reason = reason
+                self.end_of_game()
 
     def play_game(self):
         self.deal_cards()
     def check_end_of_game(self):
         raise NotImplementedError
 
-    def end_of_game(game, reason):
-        for player in game.players:
+    def end_of_game(self):
+        for player in self.players:
             player.deck += player.discard_pile + player.hand
             player.discard_pile = []
             player.hand = []
-        for player in game.players:
-            yield EndOfGameRequest(game, player, reason)
         raise EndOfGameException
 
     def following_players(self, current_player):
             province_cards = 12
         curse_cards = (no_players - 1) * 10
 
+        province_cards = 0
         game.add_supply(Curse, curse_cards)
         game.add_supply(Estate, victory_cards)
         game.add_supply(Duchy, victory_cards)

File domination/templates/game.html

     </div>
   {% endif %}
   <div id="infosep"></div>
+
+  {% if runner.state == "ended" %}
+  <h3>The game has ended. {{ game.end_of_game_reason }}</h3>
+    <ul>
+    {% for player in game.players %}
+      <li>{{ player.name }}: {{ player.deck | count }} cards, {{ player.points(game) }} points</li>
+    {% endfor %}
+    </ul>
+    Your cards:
+    {% for card in player.deck %}
+      {{ macros.render_card(card) }}  
+    {% endfor %}
+  {% endif %}
+
   {% if player.info_queue %}
   <ul>
     {% for req in player.info_queue %}
       <li class="infoitem">
         <h3>{{ req.msg }}</h3>
-        {% if req.req_type == "EndOfGameRequest" %}
-          <ul>
-          {% for player in game.players %}
-            <li>{{ player.name }}: {{ player.deck | count }} cards, {{ player.points(game) }} points</li>
-          {% endfor %}
-          </ul>
-          Your cards:
-          {% for card in req.cards %}
-            {{ macros.render_card(card) }}  
-          {% endfor %}
-        {% else %}
-          {% for card in req.cards %}
-            {{ macros.render_card(card) }}  
-          {% endfor %}
-        {% endif %}
+        {% for card in req.cards %}
+          {{ macros.render_card(card) }}  
+        {% endfor %}
       </li>
     {% endfor %}
   </ul>