-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuntrusted-lvl14-solution.js
121 lines (113 loc) · 3.26 KB
/
untrusted-lvl14-solution.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/********************
* crispsContest.js *
********************
*
* The Algorithm is almost in our grasp!
* At long last, we will definitively establish
* that 3SAT is solvable in polynomial time. It's
* been a long, strange journey, but it will all be
* worth it.
*
* You have the red, green, and blue keys. Now you
* just need to figure out how to unlock this thing.
*/
function startLevel(map) {
map.defineObject('redLock', {
'symbol': String.fromCharCode(0x2297),
'color': 'red',
'impassable': function (player) {
if (player.hasItem('redKey')) {
player.removeItem('redKey');
return false;
} else {
return true;
}
}
});
map.defineObject('blueLock', {
'symbol': String.fromCharCode(0x2297),
'color': '#06f',
'impassable': function (player) {
if (player.hasItem('blueKey')) {
player.removeItem('blueKey');
return false;
} else {
return true;
}
}
});
map.defineObject('greenLock', {
'symbol': String.fromCharCode(0x2297),
'color': '#0f0',
'impassable': function (player) {
if (player.hasItem('greenKey')) {
player.removeItem('blueKey');
return false;
} else {
return true;
}
}
});
map.defineObject('yellowLock', {
'symbol': String.fromCharCode(0x2297),
'color': 'yellow',
'impassable': function (player) {
if (player.hasItem('yellowKey')) {
player.removeItem('yellowKey');
return false;
} else {
return true;
}
}
});
map.createFromGrid(
[' +++++ +++++ ',
' + b +++ r + ',
' + +E+ + ',
'+++G+B+ +R+G+++',
'+ y B R b +',
'+ + + +',
'+++++ @ +++++',
'+ + + +',
'+ y R B y +',
'++++++Y+Y++++++',
' + + + ',
' + ABy + ',
' +++++++ '],
{
'@': 'player',
'E': 'exit',
'A': 'theAlgorithm',
'+': 'block',
'R': 'redLock',
'G': 'greenLock',
'B': 'blueLock',
'Y': 'yellowLock',
'r': 'redKey',
'g': 'greenKey',
'b': 'blueKey',
'y': 'yellowKey'
}, 17, 6);
}
function validateLevel(map) {
map.validateExactlyXManyObjects(1, 'exit');
map.validateAtMostXObjects(1, 'theAlgorithm');
map.validateAtMostXObjects(4, 'yellowKey');
map.validateAtMostXObjects(2, 'blueKey');
map.validateAtMostXObjects(1, 'redKey');
}
function onExit(map) {
// make sure we have all the items we need!
if (!map.getPlayer().hasItem('theAlgorithm')) {
map.writeStatus("You must get that Algorithm!!");
return false;
} else if (!map.getPlayer().hasItem('computer')) {
map.writeStatus("You'll need your computer! [Ctrl-5 to restart]");
return false;
} else if (!map.getPlayer().hasItem('phone')) {
map.writeStatus("You'll need your phone! [Ctrl-5 to restart]");
return false;
} else {
return true;
}
}