Handle finishing game

This commit is contained in:
0880
2026-01-18 19:06:03 +03:30
parent 4f6a45cbc7
commit 56a01ac5a7

View File

@@ -241,7 +241,7 @@
mouse = [x, y]; mouse = [x, y];
i = Math.floor((x / width) * 8); i = Math.floor((x / width) * 8);
j = Math.floor((y / height) * 8); j = Math.floor((y / height) * 8);
if (ready) { if (ready && state == -1) {
canvas.style.cursor = 'default'; canvas.style.cursor = 'default';
if (board) { if (board) {
if (color == 0) { if (color == 0) {
@@ -267,7 +267,7 @@
canvas.addEventListener('mouseup', (e) => { canvas.addEventListener('mouseup', (e) => {
i = mHouse[0]; i = mHouse[0];
j = mHouse[1]; j = mHouse[1];
if (ready && board) { if (state == -1 && ready && board) {
if (board[j][i] !== "E" && (board[j][i] === board[j][i].toUpperCase() ? 0 : 1) === color && turn == color) { if (board[j][i] !== "E" && (board[j][i] === board[j][i].toUpperCase() ? 0 : 1) === color && turn == color) {
selected = [i, j]; selected = [i, j];
@@ -302,6 +302,7 @@
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
board = data.board.grid; board = data.board.grid;
boardOnChange();
console.log(data); console.log(data);
selected = undefined; selected = undefined;
moves = []; moves = [];
@@ -326,6 +327,11 @@
ready = data.ready; ready = data.ready;
turn = data.turn; turn = data.turn;
board = data.board.grid; board = data.board.grid;
boardOnChange();
state = data.state;
start_time = new Date(data.start_time);
setUI();
}) })
.catch((error) => console.error('Error:', error)); .catch((error) => console.error('Error:', error));
} }
@@ -362,11 +368,14 @@
color = data.color; color = data.color;
ready = data.ready; ready = data.ready;
turn = data.turn; turn = data.turn;
state = data.state;
start_time = new Date(data.start_time);
} }
ROOM_ID = rid; ROOM_ID = rid;
board = data.board.grid; board = data.board.grid;
numberMap = "12345678"; numberMap = "12345678";
letterMap = "abcdefgh"; letterMap = "abcdefgh";
setUI();
document.getElementById('join-menu').outerHTML = ''; document.getElementById('join-menu').outerHTML = '';
const urlID = extractIdFromPath(); const urlID = extractIdFromPath();
if (urlID == null) { if (urlID == null) {