Skip to content
Browse files

ajustes

  • Loading branch information...
1 parent dd50021 commit 8dfb5c010e73f03bab48019e5e0b4df848123c27 @wpjunior committed Dec 24, 2011
Showing with 64 additions and 16 deletions.
  1. +45 −14 controller.js
  2. +1 −1 static/css/style.css
  3. +13 −0 static/js/game.js
  4. +5 −1 views/index.jade
View
59 controller.js
@@ -59,7 +59,6 @@ Player.prototype._init = function(socket) {
}
Player.prototype.sendCards = function () {
- var i = 0;
var namedCards = [];
this.cards.forEach(function (cardId) {
@@ -95,6 +94,10 @@ Player.prototype.join = function (gameId) {
this.socket.emit('join', gameId);
}
+Player.prototype.getTime = function () {
+ return this.num % 2;
+}
+
var Game = function (mainSocket) {
events.EventEmitter.call(this);
@@ -106,21 +109,32 @@ var Game = function (mainSocket) {
this.table = [];
this.mainSocket = mainSocket;
+ this.rounds = [];
+
lastGameId++;
this.id = lastGameId;
};
util.inherits(Game, events.EventEmitter);
Game.prototype.pushCard = function (cardNum, pNum) {
- this.table.push([cardNum, pNum]);
+ if (this.table.length == 4)
+ this.table = [];
+
+ this.table.push([cardNum, pNum]);
this.table.sort(function (c1, c2) {
var v1 = cards.getCardValue(c1[0]);
var v2 = cards.getCardValue(c2[0]);
return v2 - v1;
});
+
+ if (this.table.length == 4)
+ this.nextRound();
+ else
+ this.nextCoup();
+
};
Game.prototype.addPlayer = function (p) {
@@ -139,15 +153,7 @@ Game.prototype.addPlayer = function (p) {
});
p.on('coup', function (cardNum) {
- if (me.table.length == 4)
- me.finishCoup()
- if (me.playerCoup == 0)
- me.playerCoup = 3;
- else
- me.playerCoup -= 1;
-
me.pushCard(cardNum, p.num);
-
me.sendPlayerCoups();
});
@@ -162,17 +168,42 @@ Game.prototype.addPlayer = function (p) {
}
};
-Game.prototype.finishCoup = function () {
- console.info('finishCoup');
- this.table = [];
+Game.prototype.nextCoup = function () {
+ if (this.playerCoup == 0)
+ this.playerCoup = 3;
+ else
+ this.playerCoup -= 1;
+};
+
+Game.prototype.nextRound = function () {
+ var _this = this;
+
+ var maxCard = this.table[0][0];
+ var maxCardPlayer = this.table[0][1];
+ var maxCardValue = cards.getCardValue(this.table[0][0]);
+ var maxCardTime = this.players[maxCardPlayer].getTime();
+
+ // empate de cartas
+ if ((maxCardValue==cards.getCardValue(this.table[1][0]))&&
+ (maxCardTime!=this.players[this.table[1][1]].getTime())) {
+
+ this.rounds.push(-1);
+ this.nextCoup();
+ } else {
+ this.rounds.push(maxCardTime);
+ this.playerCoup = maxCardPlayer;
+ }
+
+ var b = this.getBroadcast();
+ b.emit('setRounds', this.rounds);
};
Game.prototype.getBroadcast = function() {
return this.mainSocket.sockets.in(this.id.toString());
};
Game.prototype.sendPlayerCoups = function () {
- var b = this.getBroadcast()
+ var b = this.getBroadcast();
var playerCardsLength = [];
var verboseTable = [];
View
2 static/css/style.css
@@ -69,4 +69,4 @@ div#game_table div.card[rel="3"] {left: 150px; z-index: 3001;}
div#menu {margin: auto; width: 860px; height: 30px; background-color: rgba(255, 255,255, 0.5); padding: 5px; border: 1px solid #2e3436; }
p#table_tooltip {display: none; z-index: 3010; position: absolute; color: white; background-color: #2e3436; -moz-border-radius: 0.4em; border-radius: 0.4em; padding: 5px; border: 1px solid white; background-color: rgba(46, 52, 54, 0.8); font-weight: bold;}
div#status {font-size: 16px;}
-.rounds, .beans {display: inline;}
+span.round {display: inline-block; width: 20px; height: 30px;}
View
13 static/js/game.js
@@ -70,6 +70,19 @@
socket.on('endGame', function (reason) {
console.info(reason);
});
+
+ socket.on('setRounds', function (rounds) {
+ $('td.rounds').empty();
+ for (var i=0; i<rounds.length; i++) {
+ var r = rounds[i];
+
+ if (r>-1)
+ $('<span class="round time'+r+'">&nbsp</p>').appendTo('td.rounds');
+ else
+ $('<span class="round null">&nbsp</span>').appendTo('td.rounds');
+ }
+ console.info(rounds);
+ });
socket.on('setPlayerCoup', function (num, cardsLength, tableCards) {
me.setCardsLength(cardsLength);
View
6 views/index.jade
@@ -5,7 +5,7 @@ html(lang="en")
div#game
div#waiting.blockdisplay Esperando Jogadores
div#connecting.blockdisplay Conectando
- div#disconnected.blockdisplay Disconectado
+ div#disconnected.blockdisplay Desconectado
p algum jogador se desconectou.
a(href="/") Reconectar
@@ -22,6 +22,10 @@ html(lang="en")
tr
td.label_points.time1 Time 02:
td.points.time1
+
+ tr
+ td.label_rounds Jogadas:
+ td.rounds
div#table-top
div#player_0.player.time0

0 comments on commit 8dfb5c0

Please sign in to comment.
Something went wrong with that request. Please try again.