✨ Created Hook separated file
This commit is contained in:
1 parent
65a66a9f35
commit
7413a5f6a1
4 files changed
+133
-97
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user