farben
This commit is contained in:
@ -9,6 +9,11 @@ const state = {
|
|||||||
|
|
||||||
const el = (id) => document.getElementById(id);
|
const el = (id) => document.getElementById(id);
|
||||||
|
|
||||||
|
const CAP_COLORS = ["#c0392b", "#2980b9", "#27ae60", "#8e44ad", "#d35400", "#16a085", "#f1c40f", "#c2185b"];
|
||||||
|
function capColorFor(row, col) {
|
||||||
|
return CAP_COLORS[(row * 7 + col * 3) % CAP_COLORS.length];
|
||||||
|
}
|
||||||
|
|
||||||
async function api(path, options) {
|
async function api(path, options) {
|
||||||
const res = await fetch(path, {
|
const res = await fetch(path, {
|
||||||
method: options?.method || "GET",
|
method: options?.method || "GET",
|
||||||
@ -96,8 +101,7 @@ function renderPlacementBoard(data) {
|
|||||||
cell.innerHTML = "";
|
cell.innerHTML = "";
|
||||||
const shipId = data.player_board[r][c];
|
const shipId = data.player_board[r][c];
|
||||||
if (shipId) {
|
if (shipId) {
|
||||||
const ship = data.fleet_def.find((s) => s.id === shipId);
|
cell.appendChild(wapplerSprite(capColorFor(r, c)));
|
||||||
cell.appendChild(wapplerSprite(ship.hat));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +141,7 @@ function renderBattle(data) {
|
|||||||
own.innerHTML = "";
|
own.innerHTML = "";
|
||||||
const shipId = data.player_board[r][c];
|
const shipId = data.player_board[r][c];
|
||||||
const receivedShot = data.player_shots_received[r][c];
|
const receivedShot = data.player_shots_received[r][c];
|
||||||
if (shipId) own.appendChild(wapplerSprite(data.fleet_def.find((s) => s.id === shipId).hat));
|
if (shipId) own.appendChild(wapplerSprite(capColorFor(r, c)));
|
||||||
if (receivedShot) own.classList.add(receivedShot);
|
if (receivedShot) own.classList.add(receivedShot);
|
||||||
|
|
||||||
const enemy = enemyCells[r][c];
|
const enemy = enemyCells[r][c];
|
||||||
|
|||||||
Reference in New Issue
Block a user