diff --git a/js/pacosako_ui.js b/js/pacosako_ui.js index f21134e..660d270 100644 --- a/js/pacosako_ui.js +++ b/js/pacosako_ui.js @@ -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 || '';