Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now with cancel support

  • Loading branch information...
commit af5929a43397d2285dd02133378921a7536aa9ec 1 parent 1312760
coryondrejka authored
View
21 chess/board.js
@@ -234,6 +234,26 @@ var Board = (function() {
return move;
}
+ function undoMove() {
+ var board = [];
+ var last = state[state.length - 1].board;
+ var x,y;
+ for (var i=0;i<last.length;i += 2) {
+ var pos = last[i];
+ x = pos % 8;
+ y = (pos / 8) | 0;
+ var ct = last[i+1];
+ var type = (ct / 6) | 0;
+ var color = ct % 6;
+ board.push([type,color,x,y]);
+ }
+ state.pop();
+ move--;
+ tomove = !tomove;
+ initState(board, tomove);
+ Chess.newGameState('playing');
+ }
+
var Board = {};
Board.init = init;
Board.tick = tick;
@@ -253,5 +273,6 @@ var Board = (function() {
Board.initState = initState;
Board.inCheck = inCheck;
Board.setCheck = setCheck;
+ Board.undoMove = undoMove;
return Board;
})();
View
17 chess/chess.js
@@ -99,21 +99,8 @@ var Chess = (function() {
Input.mouse.buttons[0] = 0;
var dx = Input.mouse.x;
var dy = Input.mouse.y;
- if (move == Board.getMove()) {
- Pieces.select(dx,dy);
- move = Board.getMove();
- }
- } else if (Input.key_state[32]) {
- Input.key_state[32] = 0;
- startPlayback();
- } else if (Input.key_state[Key.LEFT]) {
- Input.key_state[Key.LEFT] = 0;
- move > 0 ? --move : 0;
- Board.setState(move);
- } else if (Input.key_state[Key.RIGHT]) {
- Input.key_state[Key.RIGHT] = 0;
- move < Board.getMove() ? move++ : move;
- Board.setState(move);
+ Pieces.select(dx,dy);
+ move = Board.getMove();
}
}
} else {
View
2  chess/pieces.js
@@ -395,7 +395,7 @@ var Pieces = (function() {
selected = false;
setMoveTarget(selsquare, square, 1000);
setAnimatingCB(Publish.sendMove);
-// Chess.newGameState('moved');
+ Chess.newGameState('moved');
}
}
}
View
14 chess/publish.js
@@ -171,12 +171,14 @@ var Publish = (function() {
cmd.to = req.from.id;
}
FB.ui(cmd, function(response) {
- if (response && !response.error) {
- player.active_req = 0;
- removeRequest(req);
- Chess.newGameState('menu');
- }
- });
+ if (response && !response.error) {
+ player.active_req = 0;
+ removeRequest(req);
+ Chess.newGameState('menu');
+ } else {
+ Board.undoMove();
+ }
+ });
}
function sendMove() {
Please sign in to comment.
Something went wrong with that request. Please try again.