Skip to content

Commit

Permalink
Render all player opponent cards to show correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
ptwu committed Apr 17, 2020
1 parent 5f9c13e commit c7884a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/classes/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Game = function (name, host) {
}(this);

this.startNewRound = () => {
this.lastMoveParsed = { 'move': '', 'player': '' };
this.roundInProgress = true;
this.foldPot = 0;
this.bigBlindWent = false;
Expand Down Expand Up @@ -121,7 +122,8 @@ const Game = function (name, host) {
'myMoney': this.players[pn].getMoney(),
'myBet': this.getPlayerBetInStage(this.players[pn]),
'myStatus': this.players[pn].getStatus(),
'myBlind': this.players[pn].getBlind()
'myBlind': this.players[pn].getBlind(),
'roundInProgress': this.roundInProgress
});
}
}
Expand Down Expand Up @@ -298,6 +300,7 @@ const Game = function (name, host) {
} else {
let currTurnIndex = 0;
//check if move just made was a fold
console.log(this.players);
if (this.lastMoveParsed.move == 'Fold') {
for (let i = 0; i < this.players.length; i++) {
if (this.players[i].username == this.lastMoveParsed.player.username) {
Expand Down
14 changes: 11 additions & 3 deletions src/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ socket.on("hostRoom", function (data) {

socket.on("joinRoom", function (data) {
if (data == undefined) {
$('#joinModal').closeModal();
Materialize.toast('Enter a valid name/code! (max length of name is 12 characters & cannot be the same as someone else\'s)', 4000);
$("#hostButton").removeClass("disabled");
} else {
Expand Down Expand Up @@ -61,8 +62,15 @@ socket.on("rerender", function (data) {
else $('#communityCards').html('<p></p>');
if (data.currBet == undefined) data.currBet = 0;
$('#table-title').text('Round ' + data.round + " | " + data.stage + " | Current Top Bet: $" + data.topBet + " | Pot: $" + data.pot);
$('#opponentCards').html(data.players.map(function (p) { return (p.username != data.username ? renderOpponent(p.username, { 'text': p.status, 'money': p.money, 'blind': p.blind, 'bets': data.bets }) : '&nbsp;') }));
$('#opponentCards').html(data.players.map(function (p) { return renderOpponent(p.username, { 'text': p.status, 'money': p.money, 'blind': p.blind, 'bets': data.bets }) }));
renderSelf({ 'money': data.myMoney, 'text': data.myStatus, 'blind': data.myBlind, 'bets': data.bets });
if (!data.roundInProgress) {
$("#usernameFold").hide();
$("#usernameCheck").hide();
$("#usernameBet").hide();
$("#usernameCall").hide();
$("#usernameRaise").hide();
}
});

socket.on("gameBegin", function (data) {
Expand Down Expand Up @@ -94,7 +102,7 @@ socket.on("reveal", function (data) {
}
}
$('#table-title').text('Hand Winner(s): ' + data.winners);
$('#playNext').html('<button onClick=playNext() id="playNextButton" class="btn white black-text menuButtons">Play Next Round</button>');
$('#playNext').html('<button onClick=playNext() id="playNextButton" class="btn white black-text menuButtons">Start Next Game</button>');
$('#blindStatus').text(data.hand);
$('#usernamesMoney').text('$' + data.money);
$('#opponentCards').html(data.cards.map(function (p) { return ((p.username != data.username) ? renderOpponentCards(p.username, { 'cards': p.cards, 'folded': p.folded, 'money': p.money, 'endHand': p.hand }) : '&nbsp;') }));
Expand All @@ -107,7 +115,7 @@ socket.on("endHand", function (data) {
$("#usernameCall").hide();
$("#usernameRaise").hide();
$('#table-title').text(data.winner + ' takes the pot of $' + data.pot);
$('#playNext').html('<button onClick=playNext() id="playNextButton" class="btn white black-text menuButtons">Play Next Round</button>');
$('#playNext').html('<button onClick=playNext() id="playNextButton" class="btn white black-text menuButtons">Start Next Game</button>');
$('#blindStatus').text('');
if (data.folded == 'Fold') {
$("#status").text('You Folded');
Expand Down

0 comments on commit c7884a1

Please sign in to comment.