forked from jazzdan/CMPT120-Project-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject v0.4.html
302 lines (271 loc) · 9.68 KB
/
Project v0.4.html
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<html>
<!--Aaron Kippins
Project v0.4
Text Based Game-->
<head>
<meta charset="utf-8">
<title>Don't Worry Your To Blame</title>
<style>
h1{font-size:30pt; font-style:italic; font-family:times;}
body{background-color:Black; color:white;}
textarea{font-size:15pt; background-color:black; color:white; font-style:italic;}
input{background-color:black; color:white; font-style:italic;}
</style>
<script type="text/javascript">
var score=0;
var hasVisited_5=false;
var hasVisited_8=false;
var hasVisited_7=false;
var hasVisited_6=false;
var hasVisited_12=false;
//not being used yet var hasTakenNote=false;
var currentLocation=0
function showscore(){
alert(score);
}
/*This function regulates the movement control
1=North
2=West
3=East
4=South*/
function movement(direction) {
if(direction === 1) {
if (currentLocation === 8) {
currentLocation = 0;
} else if (currentLocation === 0) {
currentLocation = 5
}
} else if (direction === 2) {
if (currentLocation === 12) {
currentLocation = 6;
} else if (currentLocation === 6) {
currentLocation = 0
} else if (currentLocation === 0) {
currentLocation = 7
}
} else if (direction === 3) {
if (currentLocation === 7) {
currentLocation = 0;
} else if (currentLocation === 0) {
currentLocation = 6
} else if (currentLocation === 6) {
currentLocation = 12
}
} else if (direction === 4) {
if (currentLocation === 5) {
currentLocation = 0;
} else if (currentLocation === 0) {
currentLocation = 8
}
} else {
//var Doesn't work
var msg="Moving in that direction isn't an option."
//Didn't get this to work cannot_go_msg()
updateDisplay(msg);
}
updateLocation();
disable_button_north();
disable_button_west();
disable_button_east();
disable_button_south();
}
/*In this section the location is being monitored using the global
variable currentLocation*/
function updateLocation() {
//First room
if (currentLocation === 0) {
var msg = "You are in the middle of the room. There is a desk at the north wall of the room."
updateDisplay(msg);
} else if(currentLocation === 5) {
var msg = "You are at the northern part of the room, there there is a desk with a note on it. It looks like it could be important."
updateDisplay(msg);
if(!hasVisited_5){
score=score+10;
hasVisited_5=true;
}
} else if(currentLocation === 8) {
var msg = "You are at the southern part of the room, there is a wall here."
updateDisplay(msg);
if(!hasVisited_8){
score=score+10;
hasVisited_8=true;
}
} else if(currentLocation === 7) {
var msg = "You are at the western part of the room, there is a wall here."
updateDisplay(msg);
if(!hasVisited_7){
score=score+10;
hasVisited_7=true;
}
} else if(currentLocation === 6) {
var msg = "You are at the eastern part of the room, there is a wall here. This wall seems different from the others."
updateDisplay(msg);
if(!hasVisited_6){
score=score+10;
hasVisited_6=true;
}
} else if(currentLocation === 12) {
var msg = "The wall seems to have been some sort of illusion, this room seems similar to the previous one."
updateDisplay(msg);
if(!hasVisited_12){
score=score+10;
hasVisited_12=true;
}
}
}
function updateDisplay(msg){
var textarea = document.getElementById("tagame");
textarea.value = msg + "\n" + textarea.value;
}
function error_msg(){
var msg = "That Is Not A Command Type Help For Command List"
updateDisplay(msg);
}
function command_list_help(){
var msg = "Move North: N, n, North, or north \nMove West: W, w, West, or west\nMove East: E, e, East, or east\nMove South: S, s, South, or south"
updateDisplay(msg);
}
//disable button for extra credit
function disable_button_north(){
if (currentLocation === 5){
document.getElementById('btn1').disabled=true
} else if (currentLocation === 6){
document.getElementById('btn1').disabled=true
} else if (currentLocation === 7){
document.getElementById('btn1').disabled=true
} else if (currentLocation === 12){
document.getElementById('btn1').disabled=true
} else {
document.getElementById('btn1').disabled=false
}
}
function disable_button_west(){
if (currentLocation === 5){
document.getElementById('btn2').disabled=true
} else if (currentLocation === 7){
document.getElementById('btn2').disabled=true
} else if (currentLocation === 8){
document.getElementById('btn2').disabled=true
} else {
document.getElementById('btn2').disabled=false
}
}
function disable_button_east(){
if (currentLocation === 5){
document.getElementById('btn3').disabled=true
} else if (currentLocation === 8){
document.getElementById('btn3').disabled=true
} else if (currentLocation === 12){
document.getElementById('btn3').disabled=true
} else {
document.getElementById('btn3').disabled=false
}
}
function disable_button_south(){
if (currentLocation === 8){
document.getElementById('btn4').disabled=true
} else if (currentLocation === 6){
document.getElementById('btn4').disabled=true
} else if (currentLocation === 7){
document.getElementById('btn4').disabled=true
} else if (currentLocation === 12){
document.getElementById('btn4').disabled=true
} else {
document.getElementById('btn4').disabled=false
}
}
/*Didn't get this to work
function cannot_go_msg(){
if(currentLocation === 5 && movement(1)){
var msg = "Moving in that direction isn't an option."
updateDisplay();
}
}*/
function gettext(){
var prompt = document.getElementById("textprompt");
if(prompt.value === "N"){
movement(1);
} else if(prompt.value === "W"){
movement(2);
} else if(prompt.value === "E"){
movement(3);
} else if(prompt.value === "S"){
movement(4);
} else if(prompt.value === "n"){
movement(1);
} else if(prompt.value === "w"){
movement(2);
} else if(prompt.value === "e"){
movement(3);
} else if(prompt.value === "s"){
movement(4);
} else if(prompt.value === "North"){
movement(1);
} else if(prompt.value === "West"){
movement(2);
} else if(prompt.value === "East"){
movement(3);
} else if(prompt.value === "South"){
movement(4);
} else if(prompt.value === "north"){
movement(1);
} else if(prompt.value === "west"){
movement(2);
} else if(prompt.value === "east"){
movement(3);
} else if(prompt.value === "south"){
movement(4);
} else if(prompt.value === "Help"){
command_list_help();
} else if(prompt.value === "help"){
command_list_help();
} else {
error_msg();
}
}
</script>
</head>
<body>
<h1>
Welcome to Cerebro.
</h1>
<h2>
You're Gonna Be Here A While...
</h2>
<textarea id="tagame" name="Location" rows="5" cols="50">You wake up in a room with 4 walls and no door, you see a desk with a note on it. All that you have is a Compass.
</textarea>
<br>
<!--Found on keydown on the internet, 13 is the enter key also 13th key in it's row
that allows for enter to do the same as pressing the go button by calling the same function-->
<input type="text" id="textprompt" name="Enter Command" size="32" onKeydown="if(event.keyCode==13) gettext();">
<!--Have to figure out how to make button take whats there and
figure out if it is north, south, east, or west-->
<input type="button" value="Go" onclick="gettext();">
<br>
<input type="button"
value="North"
onclick="movement(1);"
id="btn1">
<br>
<input type="button"
value="West"
onclick="movement(2);"
id="btn2">
<input type="button"
value="East"
onclick="movement(3)"
id="btn3">
<br>
<input type="button"
value="South"
onclick="movement(4);"
id="btn4">
<br>
<input type="button"
value="Score"
onclick="showscore();">
<br>
<a href="mailto:[email protected]">Need Help?</a>
</body>
</html>