Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
now with cancel support
Browse files Browse the repository at this point in the history
  • Loading branch information
coryondrejka committed Mar 9, 2011
1 parent 1312760 commit af5929a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
21 changes: 21 additions & 0 deletions chess/board.js
Expand Up @@ -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;
Expand All @@ -253,5 +273,6 @@ var Board = (function() {
Board.initState = initState;
Board.inCheck = inCheck;
Board.setCheck = setCheck;
Board.undoMove = undoMove;
return Board;
})();
17 changes: 2 additions & 15 deletions chess/chess.js
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion chess/pieces.js
Expand Up @@ -395,7 +395,7 @@ var Pieces = (function() {
selected = false;
setMoveTarget(selsquare, square, 1000);
setAnimatingCB(Publish.sendMove);
// Chess.newGameState('moved');
Chess.newGameState('moved');
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions chess/publish.js
Expand Up @@ -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() {
Expand Down

0 comments on commit af5929a

Please sign in to comment.