Skip to content

Commit

Permalink
polishing, slider reset behavior, enhance notification system
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed Jan 22, 2013
1 parent dfca214 commit 2d4170f
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 37 deletions.
4 changes: 2 additions & 2 deletions client/css/game.css
Expand Up @@ -45,7 +45,7 @@
top: 27px; }
#game .card .suit {
bottom: -4px;
font-size: 40px;
font-size: 36px;
position: absolute;
right: 0; }
#game .card .black {
Expand Down Expand Up @@ -126,7 +126,7 @@
#game .pkr-button#opponent-button {
margin-top: 2px; }
#game .pkr-button#player-button {
margin-top: 259px; }
margin-top: 262px; }
#game .pkr-button span {
font-size: 14px;
font-weight: bold;
Expand Down
4 changes: 2 additions & 2 deletions client/css/game.scss
Expand Up @@ -50,7 +50,7 @@
}
.suit {
bottom: -4px;
font-size: 40px;
font-size: 36px;
position: absolute;
right: 0;
}
Expand Down Expand Up @@ -158,7 +158,7 @@
margin-top: 2px;
}
&#player-button {
margin-top: 259px;
margin-top: 262px;
}
span {
font-size: 14px;
Expand Down
2 changes: 1 addition & 1 deletion client/index.html
Expand Up @@ -24,7 +24,7 @@

<body ng-app="poker-app">
<div id='wrap'>
<div id='not-bar'>{{ notification }}</div>
<div id='not-bar'>{{ notify }}</div>
<div id='loading'>VERSUS POKER</div>
<div ng-switch on="view">
<div ng-switch-default ng-include="'partials/lobby.html'"></div>
Expand Down
18 changes: 14 additions & 4 deletions client/js/controllers.js
@@ -1,5 +1,7 @@
function LobbyCtrl($scope, $rootScope, gameHolder) {
notify("Welcome to Versus Poker!");
$rootScope.notify = 'Welcome to Versus Poker!'

// Animation stuff.
setTimeout(function() {
if ($rootScope.firstGame) {
$('#lobby').addClass('transition-off');
Expand All @@ -20,7 +22,7 @@ function LobbyCtrl($scope, $rootScope, gameHolder) {
}

$('#find-game').text('Finding game...').addClass('inactive');
notify('Searching for an opponent...');
$rootScope.notify = 'Searching for an opponent...';
$rootScope.enableFindGame = false;

socket = io.connect('http://localhost:4001/matchmaking',
Expand All @@ -29,7 +31,7 @@ function LobbyCtrl($scope, $rootScope, gameHolder) {
socket.on('connect_failed', function() {
// Could not connect to server.
$('#find-game').text('Find Game').removeClass('inactive');
notify('Sorry, the server seems to be down.');
$rootScope.notify = 'Sorry, the server seems to be down.';
$rootScope.enableFindGame = true;
});

Expand All @@ -40,12 +42,17 @@ function LobbyCtrl($scope, $rootScope, gameHolder) {

// Match found, start a game.
socket.on('match-found', function(data) {
$rootScope.$apply(function() {
$rootScope.notify = 'Cards in the air!';
});

gameHolder.newGame(data);
setTimeout(function() {
$rootScope.view = 'game';
$rootScope.$apply();
}, 500);

// Animation stuff.
$rootScope.firstGame = false;
$('#lobby').css('right', '320px');
$('#loading').css('opacity', '1');
Expand Down Expand Up @@ -85,7 +92,8 @@ function PokerCtrl($scope, $rootScope, Socket, gameHolder) {
for (var i = 0; i < gs.players.length; i++) {
if (gs.players[i].roundPIP > 0) {
return 'Raise to';
} }
}
}
return 'Bet';
};

Expand Down Expand Up @@ -113,6 +121,8 @@ function PokerCtrl($scope, $rootScope, Socket, gameHolder) {
amount: $scope.raiseAmount};
break;
}
resetSlider(gs, seat, true);
$('#slider-fill').attr('value', '');
Socket.emit('action', {action: action, gs: gs});
};

Expand Down
20 changes: 10 additions & 10 deletions client/js/sockets.js
Expand Up @@ -12,7 +12,7 @@ function sockets($scope, $rootScope, Socket) {
.on('change', function() {
$scope.raiseAmount = $('.bet-slider').attr('value');
$scope.$apply();
});
})
setTimeout(function() {
$('.bet-slider').trigger('change');
});
Expand All @@ -22,15 +22,14 @@ function sockets($scope, $rootScope, Socket) {
$scope.gs = gs;
var hole1 = gs.players[$scope.seat].hole[0];
var hole2 = gs.players[$scope.seat].hole[1];
notify('Dealt ' + strCard(hole1) + strCard(hole2));
$rootScope.notify = 'Dealt ' + strCard(hole1) + strCard(hole2);
resetSlider(gs, $scope.seat, false);
});

Socket.on('next-turn', function(gs) {
$scope.gs = gs;
});

Socket.on('next-round', function(gs) {
$scope.gs = gs;
$rootScope.notify = prettyLastAction(gs.history, $scope.seat);
resetSlider(gs, $scope.seat, false);
});

Socket.on('all-in', function(gs) {
Expand Down Expand Up @@ -79,13 +78,14 @@ function sockets($scope, $rootScope, Socket) {
if (gs.winner !== null) {
setTimeout(function() {
if (gs.winner == $scope.seat) {
notify('You won the hand and earned ' + gs.pot + ' chips.');
$rootScope.notify = 'You won the hand and earned ' + gs.pot + ' chips.';
} else if (gs.winner !== -1) {
notify('You lost the hand. Opponent won ' + gs.pot + ' chips.');
$rootScope.notify = 'You lost the hand. Opponent won ' + gs.pot + ' chips.';
} else {
notify('You both tied the hand. Split pot.');
$rootScope.notify = 'You both tied the hand. Split pot.';
}
}, delay);
$rootScope.$apply();
}, delay || 0);
}

setTimeout(function() {
Expand Down
43 changes: 39 additions & 4 deletions client/js/utils.js
Expand Up @@ -8,7 +8,7 @@ function gameOver($scope, $rootScope, disconnect) {
} else {
msg += 'You lost.';
}
notify(msg);
$rootScope.notify = msg;

// Animation.
setTimeout(function() {
Expand Down Expand Up @@ -74,7 +74,42 @@ function strCard(card) {
}


var notBar = $('#not-bar');
function notify(msg) {
notBar.text(msg);
function resetSlider(gs, seat, zero) {
setTimeout(function() {
if (gs.actionOn == seat) {
$('.bet-slider').attr('value', zero ? gs.minRaiseTo : 0);
$('.bet-slider').trigger('change');
} else {
$('#slider-fill').attr('value', '');
}
});
}


function prettyLastAction(history, seat) {
var highestRound = '0';
for (var round in history) {
if (history.hasOwnProperty(round)) {
if (history[round].length > 0 && round > highestRound) {
highestRound = round;
}
}
}
var round = highestRound;
var lastAction = history[round][history[round].length - 1];

var msg = '';
if (lastAction.seat == seat) {
msg += 'You ';
} else {
msg += 'Opponent ';
}

msg += c.actions[lastAction.action.action];

if (lastAction.action.action == c.ACTION_RAISE) {
msg += ' ' + lastAction.action.amount;
}
msg += '.';
return msg;
}
9 changes: 5 additions & 4 deletions client/partials/game.html
Expand Up @@ -51,7 +51,6 @@
name="slider-fill" data-highlight="true"
value="{{ gs.bigBlind * 2 }}" step="10"
min="{{ gs.minRaiseTo }}" max="{{ gs.players[seat].chips + gs.players[seat].roundPIP}}">

</div>

<div id="actions">
Expand All @@ -65,13 +64,15 @@
(gs.availableActions.indexOf(1) == -1 &&
gs.availableActions.indexOf(2) == -1)}">
<span class="action c">{{ checkCallText() }}</span>
<span class="inner-button">{{ gs.toCall }}</span>
<span class="inner-button">{{ gs.actionOn == seat && gs.toCall || '' }}</span>
</span>
<span class="button" ng-click="doAction('raise')"
ng-class="{inactive: gs.actionOn != seat ||
gs.availableActions.indexOf(3) == -1}">
<span class="action c">{{ betRaiseText() }}</span>
<span class="inner-button">{{ raiseAmount }}</span>
<span class="action c">
{{ raiseAmount >= gs.players[seat].chips + gs.players[seat].roundPIP && 'All-in' || betRaiseText() }}
</span>
<span class="inner-button">{{ gs.actionOn == seat && raiseAmount || '' }}</span>
</span>
</div>
</div>
8 changes: 4 additions & 4 deletions lib/constants.js
Expand Up @@ -6,10 +6,10 @@
exports.ACTION_RAISE = 3;

exports.actions = {};
exports.actions[exports.ACTION_FOLD] = 'fold';
exports.actions[exports.ACTION_CHECK] = 'check';
exports.actions[exports.ACTION_CALL] = 'call';
exports.actions[exports.ACTION_RAISE] = 'raise';
exports.actions[exports.ACTION_FOLD] = 'folded';
exports.actions[exports.ACTION_CHECK] = 'checked';
exports.actions[exports.ACTION_CALL] = 'called';
exports.actions[exports.ACTION_RAISE] = 'raised to';

// Round constants.
exports.ROUND_PREFLOP = 0;
Expand Down
2 changes: 0 additions & 2 deletions lib/game.js
Expand Up @@ -52,8 +52,6 @@ exports.game = function(socket) {
var handStatus = gs.applyAction(data.action);
if ('next-turn' in handStatus) {
emitGsAll('next-turn');
} else if ('next-round' in handStatus) {
emitGsAll('next-round');
} else if ('hand-complete' in handStatus) {
emitGsAll('hand-complete');
} else if ('all-in' in handStatus) {
Expand Down
9 changes: 5 additions & 4 deletions lib/holdem.js
Expand Up @@ -215,7 +215,7 @@ Gs.prototype.nextRound = function() {
if (this.currentRound != c.ROUND_FLOP) {
this.nextTurn();
}
return {'next-round': true}
return {'next-turn': true}
};

Gs.prototype.calcGameWinner = function() {
Expand All @@ -235,7 +235,7 @@ Gs.prototype.applyAction = function(action) {
var player = this.players[seat];
var opponent = this.players[this.getNextPlayer(seat)];

this.history[this.currentRound].push(action);
this.history[this.currentRound].push({seat: seat, action: action});
if (this.availableActions.indexOf(action.action) < 0) {
return {'error': true}
}
Expand Down Expand Up @@ -274,6 +274,7 @@ Gs.prototype.applyAction = function(action) {
case c.ACTION_CALL:
// Add the call to the pot. Store players' VPIP for the current
// round to calculate how much to call a raise.
this.toCall = null;
var toCall = this.currentBet - player.roundPIP;

if (toCall < player.chips || opponent.chips > 0) {
Expand All @@ -284,7 +285,7 @@ Gs.prototype.applyAction = function(action) {
} else {
// Call all-in.
this.pot += player.chips;
player.roundPIP += player.chips
player.roundPIP += player.chips;

// Refund other player.
var refund = toCall - player.chips;
Expand Down Expand Up @@ -312,7 +313,7 @@ Gs.prototype.applyAction = function(action) {
break;

case c.ACTION_RAISE:
var raiseTo = action.amount;
var raiseTo = parseInt(action.amount, 10);
if (raiseTo - player.roundPIP >= player.chips) {
// Bet amount validation for overbetting chip stack.
raiseTo = player.chips + player.roundPIP;
Expand Down

0 comments on commit 2d4170f

Please sign in to comment.