-
Notifications
You must be signed in to change notification settings - Fork 2
/
core.js
43 lines (37 loc) · 880 Bytes
/
core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var logic = require('./logic.js');
var move = function(game, req) {
if (game.error) {
return game;
}
var player = req.query.player;
var x = req.query.x;
var y = req.query.y;
if (!game.players[game.current_player]) {
game.error = game.current_player + " has not joined yet.";
return game;
}
if (player != game.current_player) {
game.error = "Not your turn";
return game;
}
//ensure within board bounds
var piece = logic.loadPiece(game, req);
var targetPiece = game.board[y][x];
var pieceFunction = game.pieces[targetPiece];
pieceFunction(game.board, piece, x, y, null);
if (game.board.error) {
game.error = game.board.error;
game.board.error = null;
}
if (game.error) {
return game;
} else {
logic.announceMove(game, req);
logic.evaluateResolution(game);
logic.cyclePlayers(game);
}
return game;
}
module.exports = {
"move": move
};