fix syntax
This commit is contained in:
@@ -28,26 +28,21 @@ var isMyTurn = false;
|
||||
|
||||
function updateTitle() {
|
||||
var title = "Misty Chess - ";
|
||||
|
||||
switch(gameState) {
|
||||
case 'waiting':
|
||||
title += "Press S to start server or J to join";
|
||||
break;
|
||||
case 'searching':
|
||||
title += "Searching for server...";
|
||||
break;
|
||||
case 'server_waiting':
|
||||
title += "Waiting for player to join...";
|
||||
break;
|
||||
case 'connected':
|
||||
if (myColor) {
|
||||
title += (mover.turn == myColor ? "Your turn (" + myColor + ")" : "Opponent's turn (" + mover.turn + ")");
|
||||
} else {
|
||||
title += mover.turn + " turn";
|
||||
}
|
||||
break;
|
||||
|
||||
if (gameState == 'waiting') {
|
||||
title += "Press S to start server or J to join";
|
||||
} else if (gameState == 'searching') {
|
||||
title += "Searching for server...";
|
||||
} else if (gameState == 'server_waiting') {
|
||||
title += "Waiting for player to join...";
|
||||
} else if (gameState == 'connected') {
|
||||
if (myColor) {
|
||||
title += (mover.turn == myColor ? "Your turn (" + myColor + ")" : "Opponent's turn (" + mover.turn + ")");
|
||||
} else {
|
||||
title += mover.turn + " turn";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log.console(title)
|
||||
}
|
||||
|
||||
@@ -179,13 +174,19 @@ var opponentMouseColor = [1.0, 0.0, 0.0, 1.0]; // Red for opponent mouse
|
||||
|
||||
/* ── draw one 8×8 chess board ──────────────────────────────────── */
|
||||
function drawBoard() {
|
||||
for (var y = 0; y < 8; ++y)
|
||||
for (var x = 0; x < 8; ++x) {
|
||||
var isMyHover = hoverPos && hoverPos[0] == x && hoverPos[1] == y;
|
||||
var isOpponentHover = opponentMousePos && opponentMousePos[0] == x && opponentMousePos[1] == y;
|
||||
var isValidMove = selectPos && holdingPiece && isValidMoveForTurn(selectPos, [x, y]);
|
||||
|
||||
var color = ((x+y)&1) ? dark : light;
|
||||
var y = 0;
|
||||
var x = 0;
|
||||
var isMyHover = null;
|
||||
var isOpponentHover = null;
|
||||
var isValidMove = null;
|
||||
var color = null;
|
||||
for (y = 0; y < 8; ++y)
|
||||
for (x = 0; x < 8; ++x) {
|
||||
isMyHover = hoverPos && hoverPos[0] == x && hoverPos[1] == y;
|
||||
isOpponentHover = opponentMousePos && opponentMousePos[0] == x && opponentMousePos[1] == y;
|
||||
isValidMove = selectPos && holdingPiece && isValidMoveForTurn(selectPos, [x, y]);
|
||||
|
||||
color = ((x+y)&1) ? dark : light;
|
||||
|
||||
if (isValidMove) {
|
||||
color = allowedColor; // Gold for allowed moves
|
||||
@@ -220,47 +221,51 @@ function isValidMoveForTurn(from, to) {
|
||||
|
||||
/* ── draw every live piece ─────────────────────────────────────── */
|
||||
function drawPieces() {
|
||||
grid.each(function (piece) {
|
||||
if (piece.captured) return;
|
||||
|
||||
var piece = null;
|
||||
var r = null;
|
||||
var opponentPiece = null;
|
||||
|
||||
grid.each(function (p) {
|
||||
if (p.captured) return;
|
||||
|
||||
// Skip drawing the piece being held (by me or opponent)
|
||||
if (holdingPiece && selectPos &&
|
||||
piece.coord[0] == selectPos[0] &&
|
||||
piece.coord[1] == selectPos[1]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip drawing the piece being held by opponent
|
||||
if (opponentHoldingPiece && opponentSelectPos &&
|
||||
piece.coord[0] == opponentSelectPos[0] &&
|
||||
piece.coord[1] == opponentSelectPos[1]) {
|
||||
if (holdingPiece && selectPos &&
|
||||
p.coord[0] == selectPos[0] &&
|
||||
p.coord[1] == selectPos[1]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var r = { x: piece.coord[0]*S, y: piece.coord[1]*S,
|
||||
// Skip drawing the piece being held by opponent
|
||||
if (opponentHoldingPiece && opponentSelectPos &&
|
||||
p.coord[0] == opponentSelectPos[0] &&
|
||||
p.coord[1] == opponentSelectPos[1]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pr = { x: p.coord[0]*S, y: p.coord[1]*S,
|
||||
width:S, height:S };
|
||||
|
||||
draw2d.image(piece.sprite, r);
|
||||
draw2d.image(p.sprite, pr);
|
||||
});
|
||||
|
||||
|
||||
// Draw the held piece at the mouse position if we're holding one
|
||||
if (holdingPiece && selectPos && hoverPos) {
|
||||
var piece = grid.at(selectPos)[0];
|
||||
piece = grid.at(selectPos)[0];
|
||||
if (piece) {
|
||||
var r = { x: hoverPos[0]*S, y: hoverPos[1]*S,
|
||||
r = { x: hoverPos[0]*S, y: hoverPos[1]*S,
|
||||
width:S, height:S };
|
||||
|
||||
|
||||
draw2d.image(piece.sprite, r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Draw opponent's held piece if they're dragging one
|
||||
if (opponentHoldingPiece && opponentSelectPos && opponentMousePos) {
|
||||
var opponentPiece = grid.at(opponentSelectPos)[0];
|
||||
opponentPiece = grid.at(opponentSelectPos)[0];
|
||||
if (opponentPiece) {
|
||||
var r = { x: opponentMousePos[0]*S, y: opponentMousePos[1]*S,
|
||||
r = { x: opponentMousePos[0]*S, y: opponentMousePos[1]*S,
|
||||
width:S, height:S };
|
||||
|
||||
|
||||
// Draw with slight transparency to show it's the opponent's piece
|
||||
draw2d.image(opponentPiece.sprite, r);
|
||||
}
|
||||
@@ -325,13 +330,16 @@ function joinServer() {
|
||||
}
|
||||
|
||||
$receiver(e => {
|
||||
var fromCell = null;
|
||||
var piece = null;
|
||||
|
||||
if (e.kind == 'update')
|
||||
send(e, update(e.dt))
|
||||
else if (e.kind == 'draw')
|
||||
send(e, draw())
|
||||
else if (e.type == 'game_start' || e.type == 'move' || e.type == 'greet')
|
||||
log.console("Receiver got message:", e.type, e);
|
||||
|
||||
|
||||
if (e.type == 'greet') {
|
||||
log.console("Server received greet from client");
|
||||
// Store the client's actor object for ongoing communication
|
||||
@@ -339,7 +347,7 @@ $receiver(e => {
|
||||
log.console("Stored client actor:", opponent);
|
||||
gameState = 'connected';
|
||||
updateTitle();
|
||||
|
||||
|
||||
// Send game_start to the client
|
||||
log.console("Sending game_start to client");
|
||||
send(opponent, {
|
||||
@@ -357,9 +365,9 @@ $receiver(e => {
|
||||
} else if (e.type == 'move') {
|
||||
log.console("Received move from opponent:", e.from, "to", e.to);
|
||||
// Apply opponent's move
|
||||
var fromCell = grid.at(e.from);
|
||||
fromCell = grid.at(e.from);
|
||||
if (length(fromCell)) {
|
||||
var piece = fromCell[0];
|
||||
piece = fromCell[0];
|
||||
if (mover.tryMove(piece, e.to)) {
|
||||
isMyTurn = true; // It's now our turn
|
||||
updateTitle();
|
||||
|
||||
Reference in New Issue
Block a user