2026-04-10 21:53:50 +02:00
|
|
|
/**
|
|
|
|
|
* This file is part of the SplendidBear Websites' projects.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-04-10 17:57:26 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
export const ROWS = 16;
|
|
|
|
|
export const COLS = 16;
|
|
|
|
|
export const IMG = '/images/';
|
|
|
|
|
|
|
|
|
|
export const WAVES = {
|
|
|
|
|
1: 'bg-wave-1-outbg.png',
|
|
|
|
|
2: 'bg-wave-1-outbg.png',
|
|
|
|
|
3: 'bg-wave-2-outbg.png',
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-10 19:09:05 +02:00
|
|
|
export const IMAGES = {
|
|
|
|
|
target: `${IMG}bg-target-outbg.png`,
|
|
|
|
|
bomb: `${IMG}bg-bomb-outbg.png`,
|
|
|
|
|
bombDisabled: `${IMG}bg-bomb-disabled-outbg.png`,
|
|
|
|
|
bombExploded: `${IMG}bg-bomb-exploded-outbg.png`,
|
|
|
|
|
bombEmpty: `${IMG}bg-bomb-empty-outbg.png`,
|
|
|
|
|
leftMine: `${IMG}bg-left-mine-outbg.png`,
|
|
|
|
|
cursor: color => `${IMG}bg-cursor-${color}-outbg.png`,
|
|
|
|
|
figure: color => `${IMG}bg-figure-${color}-outbg.png`,
|
|
|
|
|
flag: player => `${IMG}bg-flag-${player}-outbg.png`,
|
|
|
|
|
last: color => `${IMG}bg-last-${color}-outbg.png`,
|
|
|
|
|
wave: n => `${IMG}${WAVES[n]}`,
|
|
|
|
|
bombPos: (hor, vert) => `${IMG}bg-bomb-${hor}-${vert}-outbg.png`,
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-10 17:57:26 +02:00
|
|
|
export const PLAYER_DEF = {
|
|
|
|
|
name: '...', desc: '', active: false, mines: 0, haveBomb: true, enabledBomb: true,
|
2026-04-13 21:09:27 +02:00
|
|
|
registered: false, avatar: null,
|
2026-04-10 17:57:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const DESC = {
|
|
|
|
|
buddy: <div>Your buddy is <br />making a <br />move.</div>,
|
|
|
|
|
you: <div>It is your turn! <br />Make a move.</div>,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const BOMB_SYMBOLS = [
|
|
|
|
|
[null, null], [0, 0], [1, 0], [2, 0], [0, 1], [2, 1], [0, 2], [1, 2], [2, 2],
|
|
|
|
|
[null, null], [null, null], [null, null], [null, null], [null, null], [null, null], [null, null],
|
|
|
|
|
[null, null], [null, null], [null, null], [null, null], [null, null], [null, null], [null, null],
|
|
|
|
|
[null, null], [null, null],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const bombRadius = (row, col, rows, cols) => {
|
|
|
|
|
const centre = 1 < row && row < rows - 2 && 1 < col && col < cols - 2;
|
|
|
|
|
if (!centre) {
|
|
|
|
|
col = Math.max(2, Math.min(col, cols - 3));
|
|
|
|
|
row = Math.max(2, Math.min(row, rows - 3));
|
|
|
|
|
}
|
|
|
|
|
return [
|
|
|
|
|
[row, col], [row - 2, col - 2], [row - 2, col], [row - 2, col + 2],
|
|
|
|
|
[row, col - 2], [row, col + 2], [row + 2, col - 2], [row + 2, col],
|
|
|
|
|
[row + 2, col + 2], [row - 2, col + 1], [row - 2, col - 1],
|
|
|
|
|
[row - 1, col - 2], [row - 1, col - 1], [row - 1, col], [row - 1, col + 1], [row - 1, col + 2],
|
|
|
|
|
[row, col - 1], [row, col + 1], [row + 1, col - 2], [row + 1, col - 1], [row + 1, col],
|
|
|
|
|
[row + 1, col + 1], [row + 1, col + 2], [row + 2, col - 1], [row + 2, col + 1],
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const patchCells = (prev, patches) => {
|
|
|
|
|
const next = prev.map(r => [...r]);
|
|
|
|
|
for (const { row, col, ...rest } of patches) {
|
|
|
|
|
next[row][col] = { ...next[row][col], ...rest };
|
|
|
|
|
}
|
|
|
|
|
return next;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const initCells = () =>
|
|
|
|
|
Array.from({ length: ROWS }, () =>
|
|
|
|
|
Array.from({ length: COLS }, () => ({
|
2026-04-10 19:09:05 +02:00
|
|
|
currentImage: IMAGES.wave(Math.floor(Math.random() * 3) + 1),
|
2026-04-10 17:57:26 +02:00
|
|
|
currentObj: 'w',
|
|
|
|
|
active: false,
|
|
|
|
|
lastClickedRed: false,
|
|
|
|
|
lastClickedBlue: false,
|
|
|
|
|
bombTargetArea: null,
|
|
|
|
|
})),
|
|
|
|
|
);
|