Private
Public Access
1
0
Files
MineSeeker/assets/js/mine-seeker/constants.js

64 lines
2.1 KiB
JavaScript
Raw Normal View History

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 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: IMG + WAVES[Math.floor(Math.random() * 3) + 1],
currentObj: 'w',
active: false,
lastClickedRed: false,
lastClickedBlue: false,
bombTargetArea: null,
})),
);