Get started with boardgame-io CDN
MIT licensed
Online platform: Boardgame.io. Real-time board game hosting and play.
Tags:- board games
- card games
- tabletop games
- game engine
Stable version
Copied!
How to start using boardgame-io CDN
const game = {
setup: function(board, next) {
this.board = board;
this.next = next;
this.turn = 1;
for (let i = 0; i < 9; i++) {
if (!this.board.getCell(i).content) {
this.board.setCell(i, { value: this.turn % 2 === 0 ? "X" : "O" });
}
}
},
update: function() {
const cell = this.board.clickedCell;
if (cell && !cell.content) {
this.board.setCell(cell.index, { value: this.turn % 2 === 0 ? "X" : "O" });
this.turn++;
}
this.next();
},
winCondition: function() {
return (
this.checkRows() ||
this.checkColumns() ||
this.checkDiagonals()
);
},
checkRows: function() {
for (let i = 0; i < 3; i++) {
if (this.board.getRow(i).every((cell) => cell.content)) {
return true;
}
}
return false;
},
checkColumns: function() {
for (let i = 0; i < 3; i++) {
if (this.board.getColumn(i).every((cell) => cell.content)) {
return true;
}
}
return false;
},
checkDiagonals: function() {
return (
(this.board.getCells([0, 4, 8]).every((cell) => cell.content) &&
this.turn % 2 !== 0) ||
(this.board.getCells([2, 4, 6]).every((cell) => cell.content) &&
this.turn % 2 === 0)
);
},
end: function() {
if (this.winCondition()) {
alert(`Player ${this.turn % 2 + 1} wins!`);
} else if (this.board.emptyCellsCount() === 0) {
alert("It's a draw!");
}
boardgame.runWithActions(game, ["end"]);
},
};
boardgame.runWithActions(game, ["setup"]);
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
All versions
0.39.10
0.39.11
0.39.12
0.39.13
0.39.14
0.39.15
0.39.16
0.39.2
0.39.3
0.39.4
0.39.5
0.39.6
0.39.7
0.39.8
0.39.9
0.40.0
0.40.0-alpha
0.41.1
0.42.0
0.42.1
0.42.2
0.43.0
0.43.1
0.43.2
0.43.3
0.44.0
0.44.1
0.44.2
0.44.3
0.44.4
0.45.0
0.45.1
0.45.2
0.46.0
0.46.1
0.46.2
0.47.0
0.47.1
0.47.10
0.47.2
0.47.3
0.47.4
0.47.5
0.47.6
0.47.7
0.47.8
0.47.9
0.48.0
0.49.0
0.49.1
0.49.10
0.49.11
0.49.12
0.49.13
0.49.2
0.49.3
0.49.4
0.49.5
0.49.6
0.49.7
0.49.8
0.49.9
0.50.0
0.50.0-alpha.0
0.50.0-alpha.1
0.50.0-alpha.2
0.50.1
*** 0.50.2