-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter5
More file actions
35 lines (27 loc) · 1.02 KB
/
Copy pathchapter5
File metadata and controls
35 lines (27 loc) · 1.02 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
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function startLevel(map) {
for (x = 0; x < map.getWidth(); x++) {
for (y = 0; y < map.getHeight(); y++) {
map.setSquareColor(x, y, '#f00');
}
}
map.placePlayer(map.getWidth() - 5, 5);
for (var i = 0; i < 75; i++) {
var x = getRandomInt(0, map.getWidth() - 1);
var y = getRandomInt(0, map.getHeight() - 1);
if (x != 2 || y != map.getHeight() - 1) {
// don't place mine over exit!
map.placeObject(x, y, 'mine', '#f00');
<SOLUTION>
map.setSquareColor(x,y,'#9f3'); // plz, take care of your eyes. This one will really hurt you.
<SOLUTION>
}
}
map.placeObject(2, map.getHeight() - 1, 'exit');
}
function validateLevel(map) {
map.validateAtLeastXObjects(40, 'mine');
map.validateExactlyXManyObjects(1, 'exit');
}