-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestroyWall.ts
25 lines (24 loc) · 895 Bytes
/
destroyWall.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { SPEEDS, TILE_STYLE } from "./constants";
import { sleep } from "./helpers";
import { GridType, SpeedType } from "./types";
export const destroyWall = async (
grid: GridType,
row: number,
col: number,
isRight: number,
speed: SpeedType
) => {
if (isRight && grid[row][col + 1]) {
grid[row][col + 1].isWall = false;
document.getElementById(`${row}-${col + 1}`)!.className = TILE_STYLE;
await sleep(20 * SPEEDS.find((s) => s.value === speed)!.value - 5);
} else if (grid[row + 1]) {
grid[row + 1][col].isWall = false;
document.getElementById(`${row + 1}-${col}`)!.className = TILE_STYLE;
await sleep(20 * SPEEDS.find((s) => s.value === speed)!.value - 5);
} else {
grid[row][col].isWall = false;
document.getElementById(`${row}-${col}`)!.className = TILE_STYLE;
await sleep(20 * SPEEDS.find((s) => s.value === speed)!.value - 5);
}
};