summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-06-27 15:37:56 +0200
committerOlivier Gayot <duskcoder@gmail.com>2015-06-27 16:43:42 +0200
commit8e06063d55d16207eed11ceaeb6a5f32bf4e7b4c (patch)
tree9887760596e43b476484c5ef286d09d487362a2a
parent34f3ab900a9cac78acb7a10d1ed60555d98ff822 (diff)
handle the disconnection of the judge
in case the judge disconnects, we give back the played cards to the players and they are demanded to elect a new one Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--CAO/Client.py2
-rw-r--r--CAO/Game.py31
-rw-r--r--webapp/cao-mobile.js2
3 files changed, 33 insertions, 2 deletions
diff --git a/CAO/Client.py b/CAO/Client.py
index 03bb68d..2d0bbac 100644
--- a/CAO/Client.py
+++ b/CAO/Client.py
@@ -70,4 +70,4 @@ class Client():
def disconnect(self):
if self.player is not None:
- self.player.client = None
+ self.game.disconnect(self.player)
diff --git a/CAO/Game.py b/CAO/Game.py
index 917c055..63f52eb 100644
--- a/CAO/Game.py
+++ b/CAO/Game.py
@@ -165,7 +165,7 @@ class Game():
p.set_has_played(False)
self.board.recycle_black_card()
- self.judge = None # useful or not ...
+ self.judge = None
for p in self.players:
if p is not player:
@@ -204,3 +204,32 @@ class Game():
return cao_success(self.black_desc[card])
return cao_error('The black card has not been revealed yet')
+
+ def disconnect(self, player):
+ player.client = None
+
+ if self.judge is player:
+ self.board.recycle_black_card()
+ self.judge = None
+
+ for p in self.players:
+ p.send_notification({'op': 'judge_needed'})
+
+ for card, p in self.board.played_cards:
+ idx = p.receive_card(card)
+ card_idx = p.cards[idx]
+ card_desc = self.white_desc[card_idx]
+
+ p.send_notification({
+ 'op': 'received_card',
+ 'content': {
+ 'card': {
+ 'id': idx,
+ 'desc': card_desc,
+ },
+ },
+ })
+ p.set_has_played(False)
+
+ self.board.played_cards = []
+ self.state = self.WAITING_NEW_JUDGE
diff --git a/webapp/cao-mobile.js b/webapp/cao-mobile.js
index c733df8..acac68e 100644
--- a/webapp/cao-mobile.js
+++ b/webapp/cao-mobile.js
@@ -51,6 +51,8 @@ $(document).ready(function() {
switch (state) {
case 'waiting_judge':
$become_judge.show();
+ $white_cards.attr('disabled', true);
+ $white_cards.addClass('read-only');
break;
case 'waiting_designation':
if (cao.is_judge()) {