Created Hook separated file

This commit is contained in:
2024-02-18 17:15:10 +01:00
parent 65a66a9f35
commit 7413a5f6a1
4 changed files with 133 additions and 97 deletions
+27
View File
@@ -1,5 +1,7 @@
import { Difficulty, CellValue, GridType } from '../types/game';
import { getRandomArbitrary } from './generics';
import Bomb from '../assets/bomb.png';
import Flag from '../assets/flag.png';
export const genGrid = (size: number): GridType => {
let grid: GridType = Array.apply(null, Array(size)).map(() => {
@@ -175,3 +177,28 @@ export const startGame = (grid: GridType, difficulty: Difficulty, needEmpty: boo
return { grid, bombsCount };
};
export const getCellContent = (cell: { hidden: boolean; flag: boolean; value: CellValue }) => {
if (cell.hidden && cell.flag) {
return (
<img
src={Flag}
alt='flag'
/>
);
}
if (!cell.hidden) {
if (cell.value === 'bomb') {
return (
<img
src={Bomb}
alt='bomb'
/>
);
}
if (cell.value !== 'empty') {
return cell.value;
}
}
};