logs and cleaner
parent
83531757e9
commit
6ec195d2ac
|
|
@ -27,7 +27,8 @@ player > * {
|
|||
flex-grow: 1;
|
||||
}
|
||||
|
||||
player[participating] {
|
||||
player:not([participating]) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
player:not([active]) {
|
||||
|
|
|
|||
|
|
@ -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 += "<br>" + 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 `<br>${value} of ${suit}`;
|
||||
}
|
||||
|
|
@ -202,6 +202,7 @@ class UI {
|
|||
this.ts = this.now();
|
||||
var state = `
|
||||
<pot>${this.formatCurrency(game.Pot)}</pot>
|
||||
<log>${game.Log.split("<br>").slice(-15).join("<br>")}</log>
|
||||
<players>
|
||||
`;
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ type Game struct {
|
|||
Pot Currency
|
||||
Turn int
|
||||
Players Players
|
||||
Log string
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
|
|
|
|||
Loading…
Reference in New Issue