-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
647 lines (385 loc) · 19.4 KB
/
script.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
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
// Miscelanious Variables
var fishBank = $("#fishBank")
var fishCaught = 0;
var berryBank = $("#basketsGathered")
var basketsOfBerry = 0;
var bearsBank = $("#bearsTricked")
var bearsAmount = 0;
// Constructor for heroes
class RpgChar{
constructor(name, description, type, gold, weapon, currentHp, maxHp, alive, acuity, speed, wisdom, defence, magic, strength){
this.name = name;
this.description = description;
this.type = type
this.gold = gold
this. weapon = weapon;
this.currentHp = currentHp
this.maxHp = maxHp;
this.alive = alive
this.acuity = acuity;
this.speed = speed
this.wisdom = wisdom;
this.defence = defence;
this.magic = magic;
this.strength = strength;
}
// Methods for RPGCHAR
cast(){
var fishAction = $("<div>")
var castDiv = $("<div>")
castDiv.text("You cast a net into the water.")
console.log('You cast a net into the water')
castDiv.appendTo(fishAction)
var fishInNet = (Math.floor(Math.random()*7))
console.log(fishInNet)
fishCaught = fishCaught + fishInNet
if(fishInNet > 5){
user.strength = user.strength + 1
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
var gainStrengthDiv = ($("<div>"))
gainStrengthDiv.text("You Got a big haul and gained a strengh point!")
gainStrengthDiv.appendTo(fishAction)
}else{
var catchAmount = $("<div>")
catchAmount.text(`You caught ${fishInNet} fish!`)
catchAmount.appendTo(fishAction)
}
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(fishAction)
fishAction.prependTo(actionBox1)
fishBank.text(fishCaught)
}
gatherBerries(){
var gatherAction = $("<div>")
var goGathDiv = $("<div>")
goGathDiv.text("You head out to the surrounding wild to gather some berries.")
goGathDiv.appendTo(gatherAction)
basketsOfBerry = basketsOfBerry + 1
var slightOfHand = Math.random()
if (slightOfHand > 0.85){
this.acuity = this.acuity + 1
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
var gainAcuityDiv = $("<div>")
gainAcuityDiv.text("You avoided all thorny branches and gained an acuity point!")
gainAcuityDiv.appendTo(gatherAction)
}
var berrySucDiv= $("<div>")
berrySucDiv.text("You collect 1 basket of Wildberries!")
berrySucDiv.appendTo(gatherAction)
berryBank.text(basketsOfBerry)
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(gatherAction)
gatherAction.prependTo(actionBox1)
}
investigate(){
var investigateAction = $("<div>")
var investDiv = $("<div>")
investDiv.text("You take a walk around your tribes encampment searching for any threats.")
investDiv.appendTo(investigateAction)
var check = Math.random()
if(check < .25){
var safe = $("<div>")
safe.text("Everything is safe and secure.")
safe.appendTo(investigateAction)
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(investigateAction)
} else if(check >.25 && check < .8){
var possibleDanger= $("<div>")
possibleDanger.text("You see a bear in the distance, but it's several miles away from camp.")
possibleDanger.appendTo(investigateAction)
console.log("You see a bear, but it's a good ways in the distance.")
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(investigateAction)
}else if(check > .80){
console.log("A bear tears out of the brush and chalenges you!")
var bearChallenge = $("<div>")
bearChallenge.text("A bear tears out of the brush and chalenges you!")
bearChallenge.appendTo(investigateAction)
var trickBear = confirm("A bear tears out of the brush and chalenges you! can you lead it away from the camp? (Hit 'Ok' to try and trick the bear, 'cancel' to run! (WARNING: Trciking the bear is dangerous))")
var yesTrickBear = $("<div>")
if(trickBear === true){
var trickRoll = Math.floor(Math.random()* this.wisdom)
if(trickRoll >= 4){
var yesFightBear = $("<div>")
yesTrickBear.text("You lead the bear a good ways from camp and escape unharmed!")
yesTrickBear.appendTo(investigateAction)
var gainWisdomDiv = $("<div>")
gainWisdomDiv.text("You gained a wisdom point!")
gainWisdomDiv.appendTo(investigateAction)
user.wisdom = user.wisdom +1
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
bearsAmount = bearsAmount + 1
bearsBank.text(bearsAmount)
}else if (trickRoll < 4 && trickRoll > 1){
var yesFightBear = $("<div>")
yesTrickBear.text("You lead the bear a good ways from camp but get injured during the process!")
yesTrickBear.appendTo(investigateAction)
var lostHealth = $("<div>")
lostHealth.text("You lost 5 health")
lostHealth.appendTo(investigateAction)
bearsAmount = bearsAmount + 1
bearsBank.text(bearsAmount)
user.currentHp = user.currentHp - 5
if(this.currentHp <= 0){
var deathHp = alert("You lost all of your HP and died.")
main.html("<h1> GAME OVER </h1>")
main.attr("style", "text-align: center;")
next2.attr("style", "display: none")
}
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
}else{
var death = alert("While leading the bear away you trip over a log and are mauled to death.")
main.html("<h1> GAME OVER </h1>")
main.attr("style", "text-align: center;")
next2.attr("style", "display: none")
}
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(investigateAction)
}else if(trickBear === false){
var runRoll = Math.floor(Math.random() * user.speed)
console.log(runRoll)
if(runRoll >= 4){
var noFightBear = $("<div>")
noFightBear.text("You run as hard as you can and escape the bear. By some miracle he doesn't follow you.")
noFightBear.appendTo(investigateAction)
var gainSpeedDiv = $("<div>")
gainSpeedDiv.text("You gained a speed point!")
gainSpeedDiv.appendTo(investigateAction)
user.speed = user.speed +1
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
} else if (runRoll > 1 && runRoll < 4){
var noFightBear = $("<div>")
noFightBear.text("You throw some of your food at the bear and run!")
noFightBear.appendTo(investigateAction)
basketsOfBerry = basketsOfBerry - 1
fishCaught = fishCaught - 3
fishBank.text(fishCaught)
berryBank.text(basketsOfBerry)
}else{
var cowardice = $("<div>")
cowardice.text("The bear won't stop chasing you so you have to drop all of the food you have!")
cowardice.appendTo(investigateAction)
basketsOfBerry = 0;
fishCaught = 0;
fishBank.text(fishCaught)
berryBank.text(basketsOfBerry)
}
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(investigateAction)
}
}
investigateAction.prependTo(actionBox1)
}
eatMeal(){
var mealAction = $("<div>")
if (fishCaught >= 10 && basketsOfBerry >= 5){
this.currentHp = this.maxHp
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
var meal = $("<div>")
meal.text("You sit down around the fire for a meal with your tribesmen. Your HP is restored.")
meal.appendTo(mealAction)
var depletion = $("<div>")
depletion.text("You deplete 10 fish and 5 baskets of berries from your stores.")
depletion.appendTo(mealAction)
fishCaught = fishCaught - 10
fishBank.text(fishCaught)
basketsOfBerry = basketsOfBerry - 5
berryBank.text(basketsOfBerry)
var mealRoll = Math.random()
if(mealRoll > .6){
var gainMaxHp = $("<div>")
gainMaxHp.text("You gained an HP point!")
gainMaxHp.appendTo(mealAction)
this.maxHp = this.maxHp +1
this.currentHp = this.currentHp +1
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
}
} else {
var notEnough = $("<div>")
notEnough.text("You don't have enough in your food stores.")
notEnough.appendTo(mealAction)
}
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(mealAction)
mealAction.prependTo(actionBox1)
}
experiment(){
var experimentAction = $("<div>")
var tryExpDiv = $("<div>")
tryExpDiv.text("You try to experiment with Magic")
tryExpDiv.appendTo(experimentAction)
var experimentRoll = Math.random() * user.magic
if(experimentRoll >= 4){
var expSuc = $("<div>")
expSuc.text("You gain more knowledge of the mysterious Arcane particles!")
expSuc.appendTo(experimentAction)
user.magic = user.magic + 1
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
var gainMagicDiv = $("<div>")
gainMagicDiv.text("You gained a magic point!")
gainMagicDiv.appendTo(experimentAction)
}else if (experimentRoll > 2 && experimentRoll < 4){
var expFail = $("<div>")
expFail.text("You failed to gain more knowledge of the Arcane.")
expFail.appendTo(experimentAction)
}else{
var expInjury = $("<div>")
expInjury.text("You hurt yourself while experimenting with magic.")
expInjury.appendTo(experimentAction)
user.currentHp = user.currentHp - 5;
if (user.currentHp <= 0 ){
var deathHp = alert("You lost all of your HP and died.")
main.html("<h1> GAME OVER </h1>")
main.attr("style", "text-align: center;")
next2.attr("style", "display: none")
}
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
var expHealth = $("<div>")
expHealth.text("You lost 5 HP")
expHealth.appendTo(experimentAction)
}
var spaceDiv = $("<div>")
spaceDiv.text("----------------------------")
spaceDiv.appendTo(experimentAction)
experimentAction.prependTo(actionBox1)
}
};
//CHARACTER CREATION ZONE
// HUMANS
//The user playing will control this character
var user = new RpgChar("user", "Close friend of Corinthe", "mage", 0, "None", 20, 20, true, 5, 5, 5, 5, 5, 5)
var cor = new RpgChar("Corinthe", "Tribe leader", "mage", 100, "None", 20, 20, true, 10, 8, 10, 10, 10, 7)
var kel = new RpgChar("Kellian", "son of Corinthe", "mage", 100, "None", 15, 15, true, 6, 8, 5, 6, 9, 6)
var ell = new RpgChar("Ellora", "Wife of Corinthe", "mage", 100, "none", 19, 20, true, 10, 8, 10, 5, 8, 5)
// Creature Constructor
class Creature{
constructor(name,currentHp, maxHp, speed, defence, magic, strength){
this.name = name
this.currentHp = currentHp
this.maxHp = maxHp
this.speed = speed
this.defence = defence
this.magic = magic
this.strength = strength
}
}
// Creature Creation
var yeti = new Creature("Forrest Yeti", 75, 75, 5, 5, 0, 11)
console.log(yeti)
//test zone
console.log("")
console.log("----------------------------")
console.log ("")
console.log("What is(are) your action(s)?")
console.log("")
console.log("----------------------------")
console.log ("")
// Run tests here
// JAVASCRIPT/HTML INTERACTION
//INTRO
var startGame = $("#start")
var main = $("#main")
var gameBox = $("#game")
var buttons = $("#buttons")
var next =$("#next")
var intro = $("#intro")
var next0 = $("#next0")
startGame.on("click", function(){
var userName = prompt("Please name your character. (0-10 characters)")
user.name = userName
gameBox.html(`<h1>Character: ${user.name}</h1> Gold: ${user.gold} <br> class: ${user.type} <br> Description: ${user.description} <h3>Skills</h3> HP: ${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}`)
console.log(user)
intro.attr("style", "display: none;")
main.attr("style", "text-align: center;")
next0.attr("style", "display: initial;")
})
var chap1 = $("#chap1")
var next1 = $("#next1")
next0.on("click", function(){
next0.attr("style", "display: none;")
gameBox.html("")
chap1.attr("style", "display: initial;")
next1.attr("style", "display: initial;")
})
// CHAPTER 1
var game1 = $("#game1")
var statBox = $("#statsBox")
var actionBox1 = $("#actionBox1")
var next2 = $("#next2")
next1.on("click", function(){
chap1.attr("style", "display: none;")
next1.attr("style", "display: none;")
main.attr("style", "height: 400px")
statBox.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
console.log(user.name)
game1.attr("style", "display: initial;")
next2.attr("style", "display: initial;")
main.attr("style", "background-color: papayawhip")
})
var catchFish = $("#cast")
catchFish.on("click", function(){
user.cast()
})
var gather = $("#gather")
gather.on("click", function(){
user.gatherBerries()
})
var investigate = $("#investigate")
investigate.on("click", function(){
user.investigate()
})
var meal = $("#meal")
meal.on("click", function(){
user.eatMeal()
})
var exper = $("#exper")
exper.on("click", function(){
user.experiment()
})
// Depart to next chapter/
var next3 = $("#next3")
var chap2 = $("#chap2")
next2.on("click", function(){
if(fishCaught > 30 && basketsOfBerry > 15){
// main.html("<h1>CHAPTER 2 COMING SOON!</h1>")
// main.attr("style", "text-align: center;")
// REMOVE from screen
next2.attr("style", "display: none;")
game1.attr("style", "display: none;")
actionBox1.attr("style", "display: none;")
// ADD to screen
next3.attr("style", "display: initial;")
chap2.attr("style", "display: initial;")
main.attr("style", "height: auto;")
main.attr("style", "background-color: oldlace")
} else {
alert("Your people are not prepared for the journey! You need a storehouse of at least 30 fish and 15 baskets of wildberries to depart.")
}
})
// CHAPTER 2
var game2 = $("#game2")
var actionBox2 = $("#actionBox2")
var statsBox2 = $("#statsBox2")
var statsBox3 = $("#statsBox3")
var fightBar = $("#fightBar")
var enemyBox = $("#enemyBox")
next3.on("click", function(){
// Disapear
next3.attr("style", "display: none;")
chap2.attr("style", "display: none;")
main.attr("style", "background-color: papayawhip")
// Add to screen
game2.attr("style", "display: initial;")
statsBox2.html(`<h3><strong>${user.name}</strong></h3><p>Gold:${user.gold}<h3>Skills</h3> HP: ${user.currentHp}/${user.maxHp} <br> Acuity: ${user.acuity}<br> Speed: ${user.speed} <br> Wisdom: ${user.wisdom} <br> Defence: ${user.defence} <br> Magic: ${user.magic} <br> Strength: ${user.strength}</p>`)
statsBox3.html(`<h3><strong>${yeti.name}</strong></h3><h4>HP: ${yeti.currentHp}/${yeti.maxHp}</h4>`)
enemyBox.attr("style", "display: initial;")
fightBar.attr("style", "display: initial;")
alert("This section of the game is still currently under development. Thank you for participating, please come back and try it out at a later date! -Jared C. Gober, Developer")
})