chg: dev: more, massive refactor for front-end #4
This commit is contained in:
78
assets/js/mine-seeker/utils/constants.jsx
Normal file
78
assets/js/mine-seeker/utils/constants.jsx
Normal file
@@ -0,0 +1,78 @@
|
||||
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',
|
||||
};
|
||||
|
||||
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`,
|
||||
};
|
||||
|
||||
export const PLAYER_DEF = {
|
||||
name: '...', desc: '', active: false, mines: 0, haveBomb: true, enabledBomb: true,
|
||||
};
|
||||
|
||||
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 }, () => ({
|
||||
currentImage: IMAGES.wave(Math.floor(Math.random() * 3) + 1),
|
||||
currentObj: 'w',
|
||||
active: false,
|
||||
lastClickedRed: false,
|
||||
lastClickedBlue: false,
|
||||
bombTargetArea: null,
|
||||
})),
|
||||
);
|
||||
Reference in New Issue
Block a user