forked from AlexNisnevich/untrusted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19_documentObjectMadness.jsx
164 lines (151 loc) · 6.19 KB
/
19_documentObjectMadness.jsx
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#BEGIN_PROPERTIES#
{
"version": "1.3",
"commandsIntroduced":
["global.objective", "map.getDOM", "map.createFromDOM",
"map.updateDOM", "map.overrideKey", "global.$",
"jQuery.find", "jQuery.addClass", "jQuery.hasClass",
"jQuery.removeClass", "jQuery.parent", "jQuery.length",
"jQuery.children", "jQuery.first", "jQuery.next",
"jQuery.prev"],
"music": "BossLoop",
"mapProperties": {
"showDummyDom": true
}
}
#END_PROPERTIES#
/****************************
* documentObjectMadness.js *
****************************
*
* I can't believe it! I can't believe you made it onto
* Department of Theoretical Computation's web server!
* YOU SHOULD HAVE BEEN DELETED! This shouldn't even be
* possible! What the hell were the IT folks thinking?
*
* No matter. I still have the Algorithm. That's the
* important part. The rest is just implementation, and
* how hard could that be?
*
* Anyway you're not going to catch me now, my good Doctor.
* After all, you're a tenured professor with a well-respected
* history of research - you probably don't know jQuery!
*/
function objective(map) {
return map.getDOM().find('.adversary').hasClass('drEval');
}
function startLevel(map) {
#START_OF_START_LEVEL#
var html = "<div class='container'>" +
"<div style='width: 600px; height: 500px; background-color: white; font-size: 10px;'>" +
"<center><h1>Department of Theoretical Computation</h1></center>" +
"<hr />" +
"<table border='0'><tr valign='top'>" +
"<td><div id='face' /></td>" +
"<td>" +
"<h2 class=facultyName>Cornelius Eval</h2>" +
"<h3>Associate Professor of Computer Science</h3>" +
"<ul>" +
"<li>BS, Mathematics, University of Manitoba</li>" +
"<li>PhD, Theoretical Computation, <a href='http://www.mit.edu'>MIT</a></li>" +
"</ul>" +
"<h4>About me</h4>" +
"<p>I am an associate professor of computer science, attached to the Department of " +
"Theoretical Computation. My current research interests include the human-machine " +
"interface, NP complete problems, and parallelized mesh mathematics.</p>" +
"<p>I am also the current faculty advisor to the <a href=''>undergraduate Super Smash Bros. team</a>. " +
"In my spare time I enjoy polka and dirtbiking. </p>" +
"</td>" +
"</tr></table>" +
"<div id='class_schedule'>" +
"<h4>Class Schedule</h4>" +
"<table>" +
"<tr>" +
"<th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th>" +
"</tr>" +
"<tr>" +
"<td>CS145 - Semicolons</td><td>Nothing Planned</td><td>CS145 - Semicolons</td><td>CS199 - Practical Theorycrafting </td><td>CS145 - Semicolons</td>" +
"</tr>" +
"</table>" +
"</div>" +
"<div id='loremIpsum'>" +
"<h4>Lorem Ipsum</h4>" +
"<blockquote>" +
"<code>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci " +
"velit, sed quia nonnumquam eiusmodi tempora incidunt ut labore et dolore magnam aliquam quaerat " +
"voluptatem.</code>" +
"<footer>— " +
"<cite>Cicero, De Finibus Bonorum et Malorum</cite>" +
"</footer>" +
"</blockquote>" +
"</div>" +
"</div></div>";
var $dom = $(html);
$dom.find('.facultyName').addClass('drEval');
$dom.find('cite').addClass('adversary');
function moveToParent(className) {
var currentPosition = $dom.find('.' + className);
if (currentPosition.parent().length > 0) {
if (currentPosition.parent().hasClass('container')) {
if (className === 'drEval') {
map.getPlayer().killedBy('moving off the edge of the DOM');
} else {
return false;
}
} else {
currentPosition.parent().addClass(className);
currentPosition.removeClass(className);
map.updateDOM($dom);
}
}
}
function moveToFirstChild(className) {
var currentPosition = $dom.find('.' + className);
if (currentPosition.children().length > 0) {
currentPosition.children().first().addClass(className);
currentPosition.removeClass(className);
map.updateDOM($dom);
}
}
function moveToPreviousSibling(className) {
var currentPosition = $dom.find('.' + className);
if (currentPosition.prev().length > 0) {
currentPosition.prev().addClass(className);
currentPosition.removeClass(className);
map.updateDOM($dom);
}
}
function moveToNextSibling(className) {
var currentPosition = $dom.find('.' + className);
if (currentPosition.next().length > 0) {
currentPosition.next().addClass(className);
currentPosition.removeClass(className);
map.updateDOM($dom);
}
}
map.overrideKey('up', function () { moveToParent('drEval'); });
map.overrideKey('down', function () { moveToFirstChild('drEval'); });
map.overrideKey('left', function () { moveToPreviousSibling('drEval'); });
map.overrideKey('right', function () { moveToNextSibling('drEval'); });
map.defineObject('adversary', {
'type': 'dynamic',
'symbol': '@',
'color': 'red',
'behavior': function (me) {
var move = Math.floor(Math.random() * 4) + 1; // 1, 2, 3, or 4
if (move == 1) {
moveToParent('adversary');
} else if (move == 2) {
moveToFirstChild('adversary');
} else if (move == 3) {
moveToPreviousSibling('adversary');
} else if (move == 4) {
moveToNextSibling('adversary');
}
}
});
map.placePlayer(1, 1);
map.placeObject(map.getWidth() - 2, map.getHeight() - 2, 'adversary');
map.createFromDOM($dom);
#END_OF_START_LEVEL#
}