Repository navigation
Expand file tree
/
Copy pathtestfov.js
More file actions
53 lines (43 loc) · 1.57 KB
/
Copy pathtestfov.js
File metadata and controls
53 lines (43 loc) · 1.57 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
49
50
51
52
53
"use strict";
const fovResults = document.getElementById("testresults");//unique name so it doesn't clash with results in testgrid.js
fovResults.innerText += test(testMaskOpenRoom);
fovResults.innerText += test(testMaskPillar);
fovResults.innerText += test(canSeeCorrectTiles);
//turn a boolean mask grid into a picture (# = visible, space = hidden)
function readable(mask) {
return mask.toString().split("true").join("#").split("false").join(" ");
}
function testMaskOpenRoom() {
const map = new Grid(5, 5, " ");
assertEqual(readable(whereVisible(map, 2, 2, 2)),//player at 2,2 with a 2 view radius
" \n ### \n ### \n ### \n ");
//
//
// ###
// ###
// ###
//
//
}
function testMaskPillar() {
const map = new Grid(3, 5, " ");
map.set(1, 2, "O");//pillar directly above the player 1,2
assertEqual(readable(whereVisible(map, 1, 3, 3)),//player at 1,3 with a 3 view radius
" \n \n # \n###\n###");
// blank
// blank
// #
// ###
// ###
}
function canSeeCorrectTiles() {
const map = new Grid(5, 5, " ");
map.set(0, 0, "┌"); map.set(1, 0, "─"); map.set(2, 0, "┐");
map.set(0, 1, "│"); map.set(2, 1, "│");
map.set(0, 2, "└"); map.set(1, 2, "─"); map.set(2, 2, "┘");
assertEqual(readable(whereVisible(map, 1, 1, 2)),
"### \n### \n### \n \n ");
// ###
// ###
// ###
}