Skip to content

Commit

Permalink
Fixing round over bug
Browse files Browse the repository at this point in the history
  • Loading branch information
leondelee committed Sep 5, 2018
1 parent 6ed0a1f commit 46ffc78
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
15 changes: 6 additions & 9 deletions core/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def reset(self):
self.whose_turn = 0
self.last_shot_seat = 0
self.last_shot_poker = []
if self.room.allow_robot:
IOLoop.current().call_later(0.1, self.ai_join, nth=1)
restart_response = [Pt.RSP_RESTART]
self.players[0].send(restart_response)

def ai_join(self, nth=1):
size = self.size()
Expand All @@ -68,7 +68,6 @@ def sync_table(self):
ps.append((p.uid, p.name))
else:
ps.append((-1, ''))

response = [Pt.RSP_JOIN_TABLE, self.uid, ps]
for player in self.players:
if player:
Expand All @@ -95,12 +94,12 @@ def call_score_end(self):
self.whose_turn = self.max_call_score_turn
self.turn_player.role = 2
self.turn_player.hand_pokers += self.pokers
# winner = self.players[-1]
# self.on_game_over(winner)
response = [Pt.RSP_SHOW_POKER, self.turn_player.uid, self.pokers]
for p in self.players:
p.send(response)
logger.info('Player[%d] IS LANDLORD[%s]', self.turn_player.uid, str(self.pokers))
winner = self.players[-1]
self.on_game_over(winner)

def go_next_turn(self):
self.whose_turn += 1
Expand Down Expand Up @@ -133,8 +132,8 @@ def on_leave(self, player):
break

def on_game_over(self, winner):
# if winner.hand_pokers:
# return
if winner.hand_pokers:
return
coin = self.room.entrance_fee * self.call_score * self.multiple
for p in self.players:
response = [Pt.RSP_GAME_OVER, p.uid, coin if p != winner else coin * 2 - 100]
Expand All @@ -145,8 +144,6 @@ def on_game_over(self, winner):
# TODO deduct coin from database
# TODO store poker round to database
logger.info('Table[%d] GameOver[%d]', self.uid, self.uid)
self.reset()
self.sync_table()

def remove(self, player):
for i, p in enumerate(self.players):
Expand Down
5 changes: 4 additions & 1 deletion handlers/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ class Protocol(IntEnum):
RSP_GAME_OVER = 42

REQ_CHAT = 43
RSP_CHAT = 44
RSP_CHAT = 44

REQ_RESTART = 45
RSP_RESTART = 46
2 changes: 2 additions & 0 deletions handlers/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def on_message(self, message):
self.handle_chat(packet)
elif code == Pt.REQ_CHEAT:
self.handle_cheat(packet[1])
elif code == Pt.REQ_RESTART:
self.player.table.reset()
else:
logger.info('UNKNOWN PACKET: %s', code)

Expand Down
10 changes: 6 additions & 4 deletions static/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ PG.Game.prototype = {

function gameOver() {
alert(this.players[this.whoseTurn].isLandlord ? "地主赢" : "农民赢");

this.restart();
this.players[loserBSeat].cleanPokers();
this.players[loserASeat].cleanPokers();
PG.Socket.send([PG.Protocol.REQ_RESTART]);
}
this.game.time.events.add(1000, gameOver, this);
break;
Expand All @@ -138,13 +139,14 @@ PG.Game.prototype = {
this.players[seat].replacePoker(packet[2], 0);
this.players[seat].reDealPoker();
break;
case PG.Protocol.RSP_RESTART:
this.restart();
default:
console.log("UNKNOWN PACKET:", packet)
}
},

restart: function () {
this.roomId = 1;
this.players = [];
this.tableId = 0;
this.shotLayer = null;
Expand All @@ -161,7 +163,7 @@ PG.Game.prototype = {
this.players.push(PG.createPlay(1, this));
this.players.push(PG.createPlay(2, this));
this.players[0].updateInfo(PG.playerInfo.uid, PG.playerInfo.username);
PG.Socket.send([PG.Protocol.REQ_JOIN_ROOM, this.roomId]);
this.send_message([PG.Protocol.REQ_JOIN_ROOM, this.roomId]);
// PG.Socket.send([PG.Protocol.REQ_JOIN_ROOM, -1]);
},

Expand Down
5 changes: 4 additions & 1 deletion static/js/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ PG.Protocol = {
RSP_GAME_OVER : 42,

REQ_CHAT : 43,
RSP_CHAT : 44
RSP_CHAT : 44,

REQ_RESTART : 45,
RSP_RESTART : 46
};

PG.Socket = {
Expand Down
10 changes: 10 additions & 0 deletions static/js/player_net.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ PG.NetPlayer.prototype.reDealPoker = function () {
}
};

PG.NetPlayer.prototype.cleanPokers = function () {

var length = this.pokerInHand.length;
for (var i = 0; i < length; i++) {
var pid = this.pokerInHand[i];
var p = this.findAPoker(pid);
p.kill();
}
}

PG.NetPlayer.prototype.dealPokerAnim = function (p, i) {
var width = this.game.world.width;
if (p.id > 53) {
Expand Down

0 comments on commit 46ffc78

Please sign in to comment.