Commit 96a245f7 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Herp

parent 13271912
...@@ -91,6 +91,8 @@ set_turn_player = (id) -> ...@@ -91,6 +91,8 @@ set_turn_player = (id) ->
finish = (scores) -> finish = (scores) ->
console.log 'scores:', scores console.log 'scores:', scores
cancel = (reason) ->
ws = new WebSocket URL ws = new WebSocket URL
ws.send_msg = (mtype, args...) -> ws.send_msg = (mtype, args...) ->
...@@ -138,6 +140,8 @@ ws.onmessage = (msg) -> ...@@ -138,6 +140,8 @@ ws.onmessage = (msg) ->
set_turn_player args[0] set_turn_player args[0]
when 'finish' when 'finish'
finish (s.split(':').map parseInt for s in args) finish (s.split(':').map parseInt for s in args)
when 'cancel'
cancel args[0]
when 'error' when 'error'
error = args[0] error = args[0]
......
...@@ -36,7 +36,7 @@ class Msg: ...@@ -36,7 +36,7 @@ class Msg:
STATE_JOINING = 0 STATE_JOINING = 0
STATE_STARTED = 1 STATE_PLAYING = 1
STATE_FINISHED = 2 STATE_FINISHED = 2
...@@ -60,7 +60,7 @@ class Session: ...@@ -60,7 +60,7 @@ class Session:
def click_wall(self, client, x, y, direction): def click_wall(self, client, x, y, direction):
check(self.turn is client, 'not your turn') check(self.turn is client, 'not your turn')
check(self.state < STATE_FINISHED, 'already finished') check(self.state < STATE_FINISHED, 'already finished')
self.state = STATE_STARTED self.state = STATE_PLAYING
occupied = self.board.click_wall(x, y, direction, client.player) occupied = self.board.click_wall(x, y, direction, client.player)
self.bcast('clickwall', x, y, direction) self.bcast('clickwall', x, y, direction)
...@@ -110,6 +110,12 @@ class Session: ...@@ -110,6 +110,12 @@ class Session:
self.clients.remove(client) self.clients.remove(client)
self.bcast('leave', client.player) self.bcast('leave', client.player)
if self.state == STATE_PLAYING:
self.bcast('cancel', 'a player has quit before the game ended')
elif client is self.turn:
self.turn = self.clients[0]
self.bcast('turn', self.turn.player)
def is_dead(self): def is_dead(self):
return not self.clients return not self.clients
...@@ -144,7 +150,7 @@ class GameServer(AsyncServer): ...@@ -144,7 +150,7 @@ class GameServer(AsyncServer):
elif msg.mtype == 'clickwall': elif msg.mtype == 'clickwall':
check(len(msg.args) == 3) check(len(msg.args) == 3)
x, y, direction = msg.args x, y, direction = msg.args
check(client.session, 'no session associated with client') check(hasattr(client, 'session'), 'no session associated with client')
client.session.click_wall(client, x, y, direction) client.session.click_wall(client, x, y, direction)
if client.session.state == STATE_FINISHED: if client.session.state == STATE_FINISHED:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment