Disclaimer: This is currently under active development, so changes may occur at any moment without prior notice. Many features are not yet complete. Use at your own risk!
MultiTurn is a turn-based multiplayer game framework. Its design goals are that it should abstract away redundant networking/user management code that would be present in turn-based multiplayer games, so that the developer can focus on developing the game, not the endge. It is intended to be used with some other game engine that deals with the other aspects of creating a game, such as game logic and graphics.
Check out the Online Chess Demo (requires more than one browser/computer to play)!
See the specification document for more details.
Install yarn
Installing the dependencies:
yarn
Building the client:
yarn build-client
Building the server:
yarn build-server
Running the server:
yarn server
The server can now be accessed on http://localhost:8080.
The turn-based multiplayer networking logic for the game is abstracted away by
library functions, with the help of Promises
, async
, and await
. The
following excerpt demonstrates usage of the MultiTurn framework to eliminate
networking code:
async function runner(game: Server<Remote, Board>) {
const board = game.getState();
const player = game.getCurrentPlayer();
const color = numToColor(player.num);
if (board.getAllValidMoves(color).length === 0) {
if (board.isInCheck(color)) {
game.gameOver(opponentNum(player.num).toString());
}
else {
game.gameOver((0).toString());
}
return;
}
const validator = (possibleMove: Move) =>
board.tryMove(numToColor(player.num),
start(possibleMove),
end(possibleMove));
let move: Move;
do {
move = await player.remote.getMove();
} while (!validator(move));
}
- The above is a slightly modifed version of the server-side multiplayer networking logic in the game class. The logic to set up the networking interface is present in the server class.
- The client-side multiplayer networking logic resides in the remote class.
- Most of the logic for the Chess game itself is in the board class and the rules class.
- The cache for storing previously computed moves is found in the cache class.
- The client user interface is spread among the HTML/CSS files in the public directory and the client class.
- The serialized move object is found in the move class.
- The MultiTurn framework is found in the multiturn directory.
For the complete Chess sample, see here.
For the online Chess demo, see here.
Tic-tac-toe involves similar multiplayer logic to the chess example above. The following excerpt demonstrates usage of the MultiTurn framework to eliminate networking code:
async function runner(game: Server<Remote, Board>): Promise<void> {
const player = game.getCurrentPlayer();
const board = state;
const validator = (possibleMove: Move) => !board.occupied(possibleMove);
let move: Move;
do {
move = await player.remote.getMove();
} while (!validator(move));
board.occupy(move, player.num);
const win = board.checkVictory();
if (win > 0) {
game.gameOver(player.num.toString());
return;
}
const full = board.checkFull();
if (full) {
game.gameOver((0).toString());
}
}
For the complete Tic-Tac-Toe sample, see here.
The Chess assets present here created by Wikimedia commons user en:User:Cburnett can be found here and are licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.