diff --git a/src/client/css.css b/src/client/css.css
index 5add65c..56dc46e 100644
--- a/src/client/css.css
+++ b/src/client/css.css
@@ -27,7 +27,8 @@ player > * {
flex-grow: 1;
}
-player[participating] {
+player:not([participating]) {
+ display: none;
}
player:not([active]) {
diff --git a/src/client/js.js b/src/client/js.js
index 50c4d4a..3fc78bb 100644
--- a/src/client/js.js
+++ b/src/client/js.js
@@ -66,14 +66,14 @@ class Games {
});
}
- forGame(id, cb) {
+ forGame(id, cb, log) {
this.get(id, (game) => {
cb(game);
- games.update(id, game, (game) => {ui.drawGame(game)});
+ games.update(id, game, (game) => {ui.drawGame(game)}, console.log, log);
});
}
- forUser(id, uid, cb) {
+ forUser(id, uid, cb, log) {
this.get(id, (game) => {
var found = false;
game.Players.forEach((player, idx) => {
@@ -83,7 +83,7 @@ class Games {
}
});
if (found)
- games.update(id, game, (game) => {ui.drawGame(game)});
+ games.update(id, game, (game) => {ui.drawGame(game)}, console.log, log);
});
}
@@ -113,12 +113,12 @@ class Games {
});
}
- update(id, game, cb, catcher) {
- // TODO compute turn
+ update(id, game, cb, catcher, log) {
var n = 0;
var m = game.Players.length;
game.Players.forEach((player) => n += player.Participating ? 1 : 0);
game.Turn = game.Turn % (m || 1);
+ game.Log += "
" + log;
if (n)
while (m > 0 && (!game.Players[game.Turn].Active || !game.Players[game.Turn].Participating)) {
game.Turn = (game.Turn + 1) % game.Players.length;
@@ -175,10 +175,10 @@ class UI {
case 3 : suit = "clubs"; break;
}
switch (value) {
- case 10 : value = "jack"; break;
- case 11 : value = "queen"; break;
- case 12 : value = "king"; break;
- case 13 : value = "ace"; break;
+ case 11 : value = "jack"; break;
+ case 12 : value = "queen"; break;
+ case 13 : value = "king"; break;
+ case 14 : value = "ace"; break;
}
return `
${value} of ${suit}`;
}
@@ -202,6 +202,7 @@ class UI {
this.ts = this.now();
var state = `
${this.formatCurrency(game.Pot)}
+ ${game.Log.split("
").slice(-15).join("
")}
`;
var myseat = -1;
@@ -312,6 +313,7 @@ function init() {
{ID: id, Name: name},
],
}, (game) => ui.drawGame(game));
+ resetGame();
});
}
@@ -319,6 +321,7 @@ function start() {
var db = new DB();
var deck = new Deck()
var id = db.get("id");
+ var name = db.get("name");
games.get("id", (game) => {
var myturn = 0;
var n = 0;
@@ -334,11 +337,13 @@ function start() {
if (n == 0) {
throw new Error("will not start game with no participants");
}
+ game.Pot = 0;
+ game.Log = "start!";
game.Turn = myturn;
while (!game.Players[game.Turn].Participating) {
game.Turn = (game.Turn+1) % game.Players.length;
}
- games.update("id", game, (game) => {ui.drawGame(game)});
+ games.update("id", game, (game) => {ui.drawGame(game)}, console.log, `${name} started the game`);
});
}
@@ -367,24 +372,26 @@ function join() {
if (redundant) {
throw new Error("cannot take 2 seats");
}
- });
+ }, `${name} joined the game`);
}
function drop() {
var db = new DB();
var id = db.get("id");
+ var name = db.get("name");
games.forUser("id", id, (player) => {
player.Participating = false;
player.Active = false;
- });
+ }, `${name} dropped`);
}
function fold(ele) {
var db = new DB();
var id = db.get("id");
+ var name = db.get("name");
games.forUser("id", id, (player) => {
player.Active = false;
- });
+ }, `${name} folded`);
}
function check(ele) {
@@ -396,12 +403,13 @@ function check(ele) {
if (player.ID == id)
player.Checked = true;
});
- });
+ }, `${name} checked`);
}
function collect(ele) {
var db = new DB();
var id = db.get("id");
+ var name = db.get("name");
games.forGame("id", (game) => {
var found = false;
game.Players.forEach((player, idx) => {
@@ -414,31 +422,36 @@ function collect(ele) {
throw new Error("nil player cannot collect pot");
}
game.Pot = 0;
- });
+ }, `${name} collected the pot`);
}
function resetGame() {
console.log("resetting game");
+ var db = new DB();
+ var name = db.get("name");
games.forGame("id", (game) => {
game.Players = [];
game.Turn = 0;
game.Pot = 0;
- });
+ game.Log = "reset";
+ }, `${name} reset the game`);
}
function setWallet(ele) {
var db = new DB();
var id = db.get("id");
var balance = parseInt(ele.parentNode.getElementsByTagName("input")[0].value);
+ var name = db.get("name");
games.forUser("id", id, (player) => {
player.Balance = balance;
- });
+ }, `${name} set their wallet to ${balance}`);
}
function raise(ele) {
var db = new DB();
var id = db.get("id");
var bump = parseInt(ele.parentNode.getElementsByTagName("input")[0].value);
+ var name = db.get("name");
games.forGame("id", (game) => {
game.Turn += 1;
game.Players.forEach((player, idx) => {
@@ -451,7 +464,7 @@ function raise(ele) {
player.Checked = false;
}
});
- });
+ }, `${name} raises by ${bump}`);
}
var games = new Games();
diff --git a/src/server/game.go b/src/server/game.go
index 57aa615..c5b2643 100644
--- a/src/server/game.go
+++ b/src/server/game.go
@@ -6,6 +6,7 @@ type Game struct {
Pot Currency
Turn int
Players Players
+ Log string
}
type Player struct {