-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplementationIndex.ts
More file actions
48 lines (40 loc) · 1.19 KB
/
implementationIndex.ts
File metadata and controls
48 lines (40 loc) · 1.19 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { makeMap, MapNode } from "./implementation5.js";
const canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
let map = [];
let lastPosition: MapNode;
function showNewMap() {
const height = 8;
const width = 11;
const roomNumber = 20;
map = makeMap(roomNumber, height, width);
lastPosition = {x: height, y: width};
updateMap();
}
function updateMap() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
const cellSide = 10;
for (let i = 0; i < map.length; i++) {
for (let j = 0; j < map[i].length; j++) {
let x = j * cellSide;
let y = i * cellSide;
let cellColor;
switch(map[i][j]) {
case 0:
cellColor = 'rgb(30, 167, 225)';
break;
case 1:
cellColor = 'rgb(158, 164, 173)';
break;
}
if(map[i][j] !== null){
ctx.beginPath();
ctx.fillStyle = cellColor;
ctx.fillRect(x, y, cellSide, cellSide);
ctx.beginPath();
ctx.strokeStyle = 'black'
ctx.strokeRect(x, y, cellSide, cellSide);
}
}
}
}