factor the code for the status message out of renderBoard()
This commit is contained in:
parent
6f6600c6f4
commit
21214dd5df
|
|
@ -36,6 +36,28 @@ $(function (){
|
|||
let visibleGame = new PS.Game(currentGame);
|
||||
let cancelGameCallback = function() {};
|
||||
|
||||
function gameMessage(game) {
|
||||
let msg = '';
|
||||
const winner = game.winner;
|
||||
if (winner) {
|
||||
const lastMove = game.lastMove;
|
||||
if (game.status === PS.CHECKMATE) {
|
||||
msg += 'Checkmate! ';
|
||||
} else if (lastMove && lastMove.resign) {
|
||||
msg += (lastMove.side === PS.LIGHT ? 'Light' : 'Dark') + ' player resigned. ';
|
||||
}
|
||||
msg += (winner === PS.LIGHT ? 'Light' : 'Dark') + ' player won!';
|
||||
} else if (game.status === PS.PLAYING) {
|
||||
if (game.isInCheck()) {
|
||||
msg += 'Check! ';
|
||||
}
|
||||
msg += (game.player === PS.LIGHT ? 'Light' : 'Dark') + ' player\'s turn.';
|
||||
} else {
|
||||
msg += 'Game ended in a draw.';
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
function pieceTypeClass(type) {
|
||||
if (type === PS.KING) {
|
||||
return 'cb-king';
|
||||
|
|
@ -325,27 +347,12 @@ $(function (){
|
|||
}
|
||||
|
||||
let msg = '';
|
||||
let winner = game.winner;
|
||||
|
||||
if (!liveView) {
|
||||
msg += '(Move ' + String(game.moves.length) + ' of ' + String(currentGame.moves.length) + ') ';
|
||||
}
|
||||
|
||||
if (winner) {
|
||||
if (game.status === PS.CHECKMATE) {
|
||||
msg += 'Checkmate! ';
|
||||
} else if (lastMove && lastMove.resign) {
|
||||
msg += (lastMove.side === PS.LIGHT ? 'Light' : 'Dark') + ' player resigned. ';
|
||||
}
|
||||
msg += (winner === PS.LIGHT ? 'Light' : 'Dark') + ' player won!';
|
||||
} else if (playing) {
|
||||
if (game.isInCheck()) {
|
||||
msg += 'Check! ';
|
||||
}
|
||||
msg += (game.player === PS.LIGHT ? 'Light' : 'Dark') + ' player\'s turn.';
|
||||
} else {
|
||||
msg += 'Game ended in a draw.';
|
||||
}
|
||||
msg += gameMessage(game);
|
||||
$('#cb_message').text(msg);
|
||||
|
||||
const viewHistory = game.history || '';
|
||||
|
|
|
|||
Loading…
Reference in New Issue