-
Notifications
You must be signed in to change notification settings - Fork 0
/
Full game so far
557 lines (496 loc) · 21.4 KB
/
Full game so far
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<!DOCTYPE html>
<head>
<title>game</title>
<style> .button { background-color : #4CAF50 ; border : none ; color : white ; padding : 15px 32px ; text-align : center ; text-decoration : none ; display : inline-block ; font-size : 16px ; margin : 4px 2px ; cursor : pointer ; } </style>
</head>
<body>
<script type = "text/javascript" >
//"use strict";
var hp=30;
var d1edge=1001, d2edge=1001;
var f = new Array();
for (d1map=0;
d1map<d1edge;
++d1map) {
f[d1map]=new Array();
for (d2map=0;
d2map<d2edge;
++d2map) {
f[d1map][d2map]=0;
}
}
var d1=500, d2=500, action=0, start=0, num=0, mnhp2=0, mnhp3=0, yhc=75, end=0, hpns=1, hpmax=30, spells=0, mng=0, mndmg2=0, mndmg3=0, exp=0, mn="", mnh=0, nu="", gold=800, explvl=125, lvl=1;
var kmn1=0, kmn2=0, kmn3=0, kmn4=0;
function Weapon(name, dmg1, dmg2, price, cth, amount){
this.name=name;
this.dmg1=dmg1;
this.dmg2=dmg2;
this.price=price;
this.dmg=function(){return Math.floor((Math.random()*this.dmg1)+this.dmg2);}
this.cth=cth;
this.hit=function(){ var hit=Math.floor((Math.random()*100)+1);
if (hit<=this.cth) {return true;}
else {return false;};
};
this.amount=amount;
this.buy=function(){
//alert("working");
if (gold>=this.price) {gold=gold-this.price; this.amount+=1; alert("You buy one "+this.name);}
else if (gold<this.price) {alert("You do not have enough gold");};
buyshops();
};
this.buybutton='<button onclick="'+this.name+".buy()"+'">'+this.name+": "+this.price+" gold, 1d"+this.dmg1+"+"+(this.dmg2-1)+" dmg,"+'</button>';
this.equipfunc=function(){
equipped=this.name;
};
this.equip='<button onclick=" /*alert( \'\ working \'\ );*/ '+this.name+'.equipfunc(); characters();">equip?</button>';
};
var shortsword=new Weapon("shortsword", 5, 3, 60, 75, 0);
var dagger=new Weapon("dagger", 4, 1, 20, 60, 1);
equipped=dagger.name;
var mace=new Weapon("mace", 4, 6, 120, 50, 0);
var longsword=new Weapon("longsword", 9, 4, 250, 80, 0);
var spear=new Weapon("spear",7,4,180,65,0);
//runes
function rune(name, amount){
this.name=name;
this.amount=amount;
this.find=function(){alert("You gain a "+this.name);
changeText();
++this.amount;
this.get="<button onclick='"+this.num+".find()'>Get</button><p/>";
};
};
//scrolls
function scroll(name, amount, information){
this.name=name;
this.amount=amount;
this.information=information;
this.read=function(){
document . getElementById ( 'screen' ). innerHTML =back+"<p/>"+this.information ;
};
};
//enermies
function mndmgf(mn1, mn2){
v1=mn1, v2=mn2;
console.log(v1+", "+v2); return Math.floor((Math.random()*a[v1][v2].dmg1)+a[v1][v2].dmg2);
};
function hit(mnv1, mnv2){
var h=Math.random()*101;
if (h<=a[mnv1][mnv2].cth) {return true}
else {return false};
};
function Enermy(name, hp1, hp2, dmg1, dmg2, cth, lvl1, lvl2, exp, gold,
mv1, mv2, picture){
this.name=name
this.hp1=hp1;
this.hp2=hp2
this.hp=Math.floor((Math.random()*this.hp1)+this.hp2);
this.dmg1=dmg1;
this.dmg2=dmg2;
this.cth=cth;
this.lvl1=lvl1;
this.lvl2=lvl2;
this.exp=exp;
this.gold=gold;
this.m1=m1;
this.m2=m2;
this.battle=function(){
if (eval(equipped+".hit()")==true) {eval("ydmg="+equipped+".dmg()"); this.hp-=ydmg; ya="You attack the "+this.name+" for "+ydmg+" damage<p/>";}
else {ya="You attack the "+this.name+" but miss<p/>";};
if(this.hp<=0){ alert("You kill "+this.name+", You gain "+this.gold+" gold and "+this.exp+" experience" ); window.gold=window.gold+this.gold; window.exp=window.exp+this.exp; a[this.m1][this.m2]=0;};
mna="", ymna="";
for(mn1=0;mn1<5;mn1++){
for(mn2=0;mn2<5;mn2++){
hito=hit(mn1, mn2);
if (a[mn1][mn2]!=0&&hito==true) {mndmg=mndmgf(mn1, mn2); mna=mna+a[mn1][mn2].name+" attacks for "+mndmg+" damage,<p/>"; hp=hp-mndmg;}
else if (a[mn1][mn2]!=0&&hito==false) {mna=mna+a[mn1][mn2].name+" attacks but misses<p/>";};
if (a[mn1][mn2]!=0) {ymna=ymna+a[mn1][mn2].name+": "+a[mn1][mn2].hp+"hp"+a[mn1][mn2].attackbtn+"<p/>";}}
}
ftext=f[d1][d2]+"<p/>"+ya+mna+"<p/>You have "+hp+" health,<p/>"+ymna;
if (ymna=="") {++hpns; alert("You have killed all the attackers, you gain a health potion"); changeText(); fight=false; return 0;};
document . getElementById ( 'screen' ). innerHTML =ftext;
};
this.attackbtn="<button onclick='a["+m1+"]["+m2+"].battle()'>Attack, "+equipped+"?</button>";
};
var fight=false;
function battleStart(){
//alert("working1");
ftext="You are attacked by:";
mn="a";
a=new Array();
for(m1=0;m1<5;m1++){
a[m1]=new Array();
for(m2=0;m2<5;m2++){
a[m1][m2]=0;
if (Math.floor(Math.random()*2)!=0&&m2==0) {a[m1][0]=0;a[m1][1]=0;a[m1][2]=0;a[m1][3]=0;a[m1][4]=0; break;};
if (m1==0&&Math.floor(Math.random()*2)==0) {//alert("working2");
a[m1][m2]=new Enermy("LargeRat", 5, 1, 3, 1, 50, 1, 4, 20, 5, ""); mn=m1;
//alert("working3");
};
if (typeof mn!="number"&&m1==1&&Math.floor(Math.random()*5)<2) {a[m1][m2]=new Enermy("untrained goblin",5,5,4,2,55,1,6,40,10,""); mn=m1;};
if (typeof mn!="number"&&m1==2&&Math.floor(Math.random()*7)<3) {a[m1][m2]=new Enermy("enormous bug",7,6,5,3,50,2,7,65,15,""); mn=m1;};
if (typeof mn!="number"&&m1==3&&Math.floor(Math.random()*11)<5) {a[m1][m2]=new Enermy("low level imp",8,9,7,6,70,2,10,90,25,""); mn=m1;}
if (typeof mn!="number"&&m1==4&&Math.floor(Math.random()*13)<7) {a[m1][m2]=new Enermy("dark elf priestess",15,20,15,10,80,4,15,150,50,""); mn=m1;}
if (lvl>a[m1][m2].lvl2||lvl<a[m1][m2].lvl1) {a[m1][m2]=0; continue;};
//alert("working4");
if (a[m1][m2]!=0) {ftext=ftext+"</p>A "+a[m1][m2].name+" with "+a[m1][m2].hp+" hp,"+a[m1][m2].attackbtn;};
}
}
if (ftext!="You are attacked by:") { alert("You are attacked!");
document . getElementById ( 'screen' ). innerHTML = ftext; fight=true;};
numName();
//alert("working6");
};
function numName(){
for(mf1=0;mf1<5;mf1++){
mnnum=0;
for(mf2=0;mf2<5;mf2++){
if (a[mf1][mf2]!=0) {++mnnum; a[mf1][mf2].name=a[mf1][mf2].name+mnnum;};
}};
};
var button1="<button onclick='";
var button2="</button>";
var heal="<button onclick='hp=hp+10, --hpns, changeText();'>Drink a potion</button>";
// general movement
var north='<input type = "button" value = "North" onclick = " ++d1, changeText (); " /><p/>';
var east='<input type = "button" value = "East" onclick = " ++d2, changeText (); " /><p/>';
var west='<input type = "button" value ="West" onclick = " --d2, changeText (); " /><p/>';
var south='<input type = "button" value = "South" onclick = " --d1, changeText (); " /><p/>';
var move=north+west+south+east;
var attack='<p/><button type = "button" class = "button" onclick = " battle();"/>Attack</button>';
var enter='<p/><button type="button" onclick="inshops();">Enter shop,'+button2;
var backshops='<p/><button type="button" onclick="inshops();">Back</button>';
// boss tower
var btl, btr=1;
var btl1="You stand on the bottom level of the Arch Mage Merlin's tower.<p/>You can see a set of spiral stone stairs leading up to the next floor.<p/><input type='button' value='climb the stairs' onclick='btl=2; btr=1; tower();'/>";
var btl2r1="You are standing on the second floor of the arch mage Merlin's tower.<p/>Shelves line the walls with strange skeletons upon them.<p/>A door leads east.<p/><input type='button' value='East' onclick='btr=2; tower();'/>";
var btl2r2='You stand in a room with mirrors on every surface.<p/>The door you came in through is gone leaving a shimmering pain of glass in its place<p/>';
btl2r2=btl2r2+'You are drawn towards the east mirror.<p/> <button onclick="alert( \'\ You feel as though you are being squeezed to a point before reappearing back in the bottem level of the tower \'\ ); changeText();">Go to the west mirror</button>';
var btl2r2=btl2r2+'<button onclick=" if (spells==0){alert( \'\ You feel like you are being tested for cirtain knolage before being squeezed to a point and reappearing on the bottem level of the tower \'\ ); changeText();};">Go to the eastt mirror</button>';
var btd1=Math.floor((Math.random()*50)+476), btd2=Math.floor((Math.random()*50)+476);
f[btd1][btd2]=btl1;
function tower(){
if (btl==2&&btr==1) { document . getElementById ( 'screen' ). innerHTML = btl2r1; };
if (btl==2&&btr==2) { document . getElementById ( 'screen' ). innerHTML =btl2r2 ; };
};
// Places
var city="You stand in a small city";
var forest1='You stand in a forest<img src="http://www.bigfoto.com/themes/nature/forest/green-trees.jpg" height="100" width="100"><p/>';
var mountains1="You stand on a mountain<p/>";
var mountains2="You stand high upon a cliff, the wind is strong up here";
var plains1='You stand on a field of green grass<img src="https://static.pexels.com/photos/128637/pexels-photo-128637.jpeg" alt="green grass" height="40" width="100"><p/>';
var plains2="You stand on a strech of barren dirt, nothing grows here";
var hills1 ="You stand on a small hill";
var hills2="You stand on a low plateau, the sides slope gentally away in all directions";
var shops1="You stand before a well set up blacksmith's workshop,"+enter;
//inside shops
var inshops1='You stand in a small but well used smithy.<p/>The owner, a short, thick armed dwarf with a white bierd, pauses their work to introduce themself as "Handrerlig Graybraid" \
\ and to ask about what they may do to help you.<p/><button onclick ="/*trainsmith*/ alert( \'\ To be implimented soon \'\ );">Ask to be trained in the ways of metal,</button> \
\ <p/><button onclick="/*forge*/ alert( \'\ To be implimented later \'\ );">work in shop</button><p/><button onclick="buyshops();">Buy items</button><p/><button onclick="changeText();">Leave workshop</button><p/>';
// roads
var roads1="You stand on a road leading east and west";
var roads2="You stand on a road leading north and south";
var roads3="You stand in the centre of a crossroads";
// Enermy names
/*var mn1="large rat";
var mn2='troll <img src="http://www.santharia.com/pictures/isilhir/isilhir_pics/forest_trolls.jpg">';
var mn3='small goblin <img src="http://imgs.sfgate.com/blogs/images/sfgate/culture/2009/12/17/kallikantzaros129x250.jpg">';
var mn4=' Dark elf <img src="http://media.wizards.com/2014/images/dnd/newtodnd/Drow_1Ev2.jpg">';*/
// start attack phrases
var at1="You are attacked by a ";
// road generation rules
var r1=Math.floor(Math.random()*1000), r2=Math.floor(Math.random()*1000), r3=Math.floor(Math.random()*1000), r4=Math.floor(Math.random()*1000), r5=Math.floor(Math.random()*1000), r6=Math.floor(Math.random()*1000), r7=Math.floor(Math.random()*1000), r8=Math.floor(Math.random()*1000), r9=Math.floor(Math.random()*1000), r10=Math.floor(Math.random()*1000), r11=Math.floor(Math.random()*1000), r12=Math.floor(Math.random()*1000), r13=Math.floor(Math.random()*1000), r14=Math.floor(Math.random()*1000), r15=Math.floor(Math.random()*1000), r16=Math.floor(Math.random()*1000);
function roads(){
f[r1][d2]=roads1;
f[d1][r2]=roads2;
f[r3][d2]=roads1;
f[d1][r4]=roads2;
f[r5][d2]=roads1;
f[d1][r6]=roads2;
f[r7][d2]=roads2;
f[d1][r8]=roads1;
f[r9][d2]=roads2;
f[d1][r10]=roads1;
f[r11][d2]=roads2;
f[d1][r12]=roads1;
f[r13][d2]=roads2;
f[d1][r14]=roads1;
f[r15][d2]=roads2;
f[d1][r16]=roads2;
f[r1][r2]=roads3;
f[r1][r4]=roads3;
f[r1][r6]=roads3;
f[r1][r8]=roads3;
f[r1][r10]=roads3;
f[r1][r12]=roads3;
f[r1][r14]=roads3;
f[r1][r16]=roads3;
f[r3][r2]=roads3;
f[r3][r4]=roads3;
f[r3][r6]=roads3;
f[r3][r8]=roads3;
f[r3][r10]=roads3;
f[r3][r12]=roads3;
f[r3][r14]=roads3;
f[r3][r16]=roads3;
f[r5][r2]=roads3;
f[r5][r4]=roads3;
f[r5][r6]=roads3;
f[r5][r8]=roads3;
f[r5][r10]=roads3;
f[r5][r12]=roads3;
f[r5][r14]=roads3;
f[r5][r16]=roads3;
f[r7][r2]=roads3;
f[r7][r4]=roads3;
f[r7][r6]=roads3;
f[r7][r8]=roads3;
f[r7][r10]=roads3;
f[r7][r12]=roads3;
f[r7][r14]=roads3;
f[r7][r16]=roads3;
f[r9][r2]=roads3;
f[r9][r4]=roads3;
f[r9][r6]=roads3;
f[r9][r8]=roads3;
f[r9][r10]=roads3;
f[r9][r12]=roads3;
f[r9][r14]=roads3;
f[r9][r16]=roads3;
f[r11][r2]=roads3;
f[r11][r4]=roads3;
f[r11][r6]=roads3;
f[r11][r8]=roads3;
f[r11][r10]=roads3;
f[r11][r12]=roads3;
f[r11][r14]=roads3;
f[r11][r16]=roads3;
f[r13][r2]=roads3;
f[r13][r4]=roads3;
f[r13][r6]=roads3;
f[r13][r8]=roads3;
f[r13][r10]=roads3;
f[r13][r12]=roads3;
f[r13][r14]=roads3;
f[r13][r16]=roads3;
f[r15][r2]=roads3;
f[r15][r4]=roads3;
f[r15][r6]=roads3;
f[r15][r8]=roads3;
f[r15][r10]=roads3;
f[r15][r12]=roads3;
f[r15][r14]=roads3;
f[r15][r16]=roads3;
};
d1=500;
d2=500;
f[503][501]=shops1;
var vilsq="You stand in the niddle of the vilage square.<p/>Streets lead of in all four directions.";
f[500][500]=vilsq;
function tick(){
if (hp<=0) {document . getElementById ( 'screen' ). innerHTML = "You are dead"; };
if (safe==false&&fight==false&&(f[d1][d2]!=(shops1||roads1||roads2||roads3))&&Math.floor(Math.random()*30)==0) {battleStart(); };
timeplayed();
gameTime();
setCookie("hp", hp, 30);
setCookie("exp", exp, 30);
setCookie("lvl", lvl, 30);
setCookie("hpmax", hpmax, 30);
setCookie("hpns", hpns, 30);
setCookie("explvl", explvl, 30);
//battleStart();
};
tim=39, tod2="", tod1="";
function gameTime(){
++tim;
if (tim>180) {tim=0;};
if (tim==0) { tod2="Midnight, the moon is directly overhead"; };
if (tim==20) {tod2="Early morning, the moon is shrinking to the west";};
if (tim==40) {tod2="dawn, the sun is rising in the east";};
if (tim==60) {tod2="Morning, the sun is climbing in the eastern sky";};
if (tim==90) {tod2="Noon, the sun is shining from above";};
if (tim==110) {tod2="Afternoon, the sun is falling in the west";};
if (tim==140) {tod2="Evening, the sun is setting in the west";};
if (tim==160) {tod2="Night, the moon has risen in the east";};
document . getElementById ( 'sun' ). innerHTML =tod2;
};
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname) {
var name = cname + "=";
ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
var d1min=500, d1max=500, d2min=500, d2nax=500;
function checkCookie() {
hp=getCookie("hp");
exp=getCookie("exp");
hpmax=getCookie("hpmax");
lvl=getCookie("lvl");
hpns=getCookie("hpns");
explvl=getCookie("explvl")
d1min=getCookie("d1min");
d1max=getCookie("d1max");
d2min=getCookie("d2min");
d2max=getCookie("d2max");
for(d1c=d1min;
d1c<d1max;
d1c++){
for(d2c=d2min;
d2c<d2max;
d2c++){
f[d1c][d2c]=getCookie("f"+d1c+d2c);
}}
};
function generat(){
for(d1g=0;
d1g<1000;
++d1g)
{for
(d2g=0;
d2g<1000;
++d2g)
{ if (f[d1g][d2g]==shops1) { f[d2g+1][d2g]=plains1; f[d2g-1][d2g]=plains1; f[d2g][d2g+1]=plains1; f[d2g][d2g-1]=plains1; f[d2g-1][d2g-1]=plains1; f[d2g+1][d2g-1]=plains1; f[d2g+1][d2g+1]=plains1; f[d2g-1][d2g+1]=plains1; };}}};
var counts=0, countm=0;
function timeplayed(){++counts;
if ((counts-60)==0) {++countm; counts=counts-60;};
document . getElementById ( 'timep' ). innerHTML ="Time played: "+countm+" minutes, "+counts+" seconds";
};
var d1min=500, d1max=500, d2min=500, d2max=500;
function changeText () {
safe=false;
roads();
//generat();
var Area=Math.floor((Math.random()*240)+1);
if (f[d1][d2]==plains2) {num=236}
else if (f[d1][d2]==mountains2) {num=169}
else if (f[d1][d2]==hills2) {num=205;}
else if (f[d1][d2]==roads3) {num=2001;}
else if (f[d1][d2]==roads1) {num=20002;}
else if (f[d1][d2]==roads2) {num=20003;}
else if (f[d1][d2]==btl1) {num=20000;}
else if (f[d1][d2]==city) {num=0;}
else if (f[d1][d2]==forest1) {num=1;}
else if (f[d1][d2]==mountains1) {num=50;}
else if (f[d1][d2]==plains1){num=99;}
else if (f[d1][d2]==hills1) {num=120}
else if (f[d1][d2]==shops1) {num=133;}
else if (f[d1][d2]==0) {num=Area;};
if (num>=136&&num<=168) {f[d1][d2]=plains2;}
else if (num>=169&&num<=204) {f[d1][d2]=mountains2}
else if (num>=205&&num<=240) {f[d1][d2]=hills2;}
else if (num==20001) {f[d1][d2]=roads3;}
else if (num==20002) {f[d1][d2]=roads1;}
else if (num==20003) {f[d1][d2]=roads2;}
else if (num==20000) {f[d1][d2]=btl1;}
else if (num==0) {f[d1][d2]=city;}
else if (num<=33){f[d1][d2]=forest1;}
else if (num>33&&num<=66) {f[d1][d2]=mountains1;}
else if (num<=100&&num>66){f[d1][d2]=plains1;}
else if (num>=101&&num<=132) {f[d1][d2]=hills1}
else if (num>=133&&num<=135) {[d1][d2]=shops1;};
if (d1<d1min) {d1min=d1min; setCookie("d1min", d1min, 30);};
if (d1>d1max) {d1max=d1; setCookie("d1max", d1max, 30);};
if (d2<d2min) {d2min=d2; setCookie("d2min", d2min, 30);};
if(d2>d2max) {d2max=d2; setCookie("d2max", d2max, 30);};
if (d1<=1||d1>=999||d2<=1||d2>=999) {f[d1][d2]="Edge of map";};
if (d1==0) {++d1;};
if (d2==0) {++d2;};
if (d1==1000) {--d1;};
if (d2==1000) {--d2;};
if (exp>=explvl) {exp=exp-explvl; explvl=Math.floor(explvl*1.75); hpmax=(hpmax+10); lvl=lvl+1; alert("You have gained a level")};
// var mng=Math.floor((Math.random()*15)-13);
//mng=1;
//if (f[d1][d2]==(city||roads1||roads2||roads3)) {mng==0;};
if (btd1>d1&&btd2>d2) {topo="northeast";}
else if (btd1>d1&&btd2==d2) {topo="north";}
else if (btd1>d1&&btd2<d2) {topo="northwest";}
else if (btd1==d1&&btd2>d2) {topo="east";}
else if (btd1<d1&&btd2<d2) {topo="southwest";}
else if (btd1<d1&&btd2==d2) {topo="south";}
else if (btd1<d1&&btd2>d2) {topo="southeast";}
else if (btd1==d1&&btd2<d2) {topo="west";}
else if (btd1==d1&&btd2==d2) {topo="";};
if (hpns>0) {hbtn=heal;}
else {hbtn="";};
if (hp>hpmax) {hp=hpmax;};
if (mng!=1) { text = f[d1][d2]+"<p>You can see a tower to the "+topo+"</p> <p>You have "+hp+"/"+hpmax+" health and "+hpns+" healthpotions,<p/>"+hbtn+"</p><p/>"+move+"<p/>"+d1+", "+d2+",<p/>"+button1+"characters();'>Character"+button2;};
// Monster generation
/*var mnh;
if (mng==1) {mnh=Math.floor((Math.random()*7)-2);}
else {mnh="";};
if (mng==1&&mnh<1) {mn=mn1; mnhp2=5; mnhp3=3; mndmg2=3; mndmg3=1; mnhc=50; exp=exp+27;}
else if (mng==1&&(mnh==2||mnh==1)) {mn=mn3; mnhp2=6; mnhp3=5; mndmg2=3; mndmg3=3; mnhc=66; exp=exp+42}
else if (mng==1&&mnh==3) {mn=mn4; mnhp2=6; mnhp3=9; mndmg2=5; mndmg3=3; mnhc=95; exp=exp+63;}
else if (mng==1&&mnh==4) {mn=mn2; mnhp2=15; mnhp3=15; mndmg2=5; mndmg3=7; mnhc=25; exp=exp+89;};
if (mng==1) {mnhp=Math.floor((Math.random()*mnhp2)+mnhp3); text=f[d1][d2]+"<p/>"+at1+mn+" with "+mnhp+" health, <p/> You have "+hp+" health, <p/>"+attack;};
*/
if (hp<=0){text="You are dead";};
if (action==1) {action=0;};
document . getElementById ( 'screen' ). innerHTML = text ;
setCookie("f"+d1+d2, f[d1][d2], 30);
}
;
function battle(){
document . getElementById ( 'hit' ). play();
var mnhch=Math.floor((Math.random()*100)+1);
var yhch=Math.floor((Math.random()*100)+1);
if (mnhch<=mnhc) {mndmg=Math.floor((Math.random()*mndmg2)+mndmg3); hp=hp-mndmg; mna="The "+mn+" attacks for "+mndmg+" damage,";}
else if (mnhch>mnhc) {mna="The "+mn+" attacks but misses"};
yhp="You have "+hp+" health,";
if (eval(equipped+".hit()")<=yhc) {eval("dmg="+equipped+".dmg()"); mnhp=mnhp-dmg; /*alert("working");*/ ya="You attack the "+mn+" for "+dmg+" damage";}
else if (eval(equipped+".dmg()")>yhc) {ya="You attack the "+mn+" but miss</p>";};
mnhpt="The "+mn+" has "+mnhp+" health</p>";
//alert("working")
fight=f[d1][d2]+mna+ya+mnhpt+yhp+attack;
if (mnhp<=0) {fight=f[d1][d2]+"</p>You have killed the "+mn+"</p>You gain 1 healthpotion and 10 gold</p>You can see a tower to the "+topo+"</p>You have "+hp+" health and "+(hpns+1)+" healthpotions</p>"+heal+move+"<p/>"+d1+", "+d2+"<p/> "+"<button onclick='characters();'>Character</button>";
hpns=hpns+1; gold=gold+10;};
if (mnhp<=0&&mn==mn1) {++kmn1;}
else if (mnhp<=0&&mn==mn2) {++kmn2;}
else if (mnhp<=0&&mn==mn3) {++kmn3;}
else if (mnhp<=0&&mn==mn4) {++kmn4;};
if (hp<=0) {fight="You are dead";};
document . getElementById ( 'screen' ). innerHTML = fight;
}
function inshops(){
if (f[d1][d2]==shops1&&(tim>=40&&tim<140)) {text2=inshops1;}
else if (f[d1][d2]==shops1&&(tim<40||tim>=140)) {alert("The shop is closed for the night, please come back in the morning"); return 0;};
document . getElementById ( 'screen' ). innerHTML = text2 ; };
function buyshops(){
if (f[d1][d2]==shops1) {text3 =backshops+"<p/>You have "+gold+" gold,<p/>A number of weapons hang from the walls each with a sign above it stating its price."+shortsword.buybutton+"<p/>"+dagger.buybutton+"<p/>"+mace.buybutton+"<p/>"+spear.buybutton+"<p/>"+longsword.buybutton+"<p/>";}
document . getElementById ( 'screen' ). innerHTML = text3 ;
};
function characters(){safe=true;
chartext=button1+"changeText();'>Back"+button2+"<p/>You have "+hp+" health,<p/>"+hpns+"healthpotions<p/>and "+gold+" gold, \
\ You are on level "+lvl+",<p/>You have "+exp+" expierience and need "+explvl+" to raise your level.<p/>Weapons:<p/> The "+equipped+" is equipped<p/>";
if (dagger.amount>0) {chartext=chartext+dagger.amount+dagger.name+dagger.equip+"<p/>";}
if (shortsword.amount>0) {chartext=chartext+shortsword.amount+" "+shortsword.name+shortsword.equip+"<p/>";}
if (mace.amount>0) {chartext=chartext+mace.amount+" "+mace.name+mace.equip+"<p/>";};
if (spear.amount>0) {chartext=chartext+spear.amount+" "+spear.name+spear.equip+"<p/>";}
if (longsword.amount>0) {chartext=chartext+longsword.amount+" "+longsword.name+longsword.equip+"<p/>";}
document . getElementById ( 'screen' ). innerHTML =chartext ;
};
</script>
<p id= "sun" ></p>
<p id = "screen" role="status"><input type = "button" value = "Start a new game" onclick = "setInterval(tick, 1000); changeText(); document.cookie='';"/> <input type = "button" value = "continue with previous game" onclick = ' checkCookie(); changeText(); window.alert("loaded"); setInterval(tick, 1000);'/>
<button onclick= ' document . getElementById ("screen" ). innerHTML =document.cookie; '>View saved information</button>
</p>
<p id="timep"></p>
<p>
<audio id="hit" src="http://soundbible.com/mp3/Swords_Collide-Sound_Explorer-2015600826.mp3"></audio>
</p>
</body> </html>