repl.it
@OmarWadha/

Codecademy-Dragon Slayer Upgraded

JavaScript

Next upgrades: Var Defend Use time / reflexes

fork
loading
main.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
ggvar slaying = true;
// A bit of new math magic to calculate the odds
// of hitting the dragon. We'll cover this soon!
var totalDamage = 100;
var YtotalDamage = 100;
// weakness and force points , smthg like an array / object
// example below, the correct way is to generate randmon valuesbtw  [0,100]
var Ddefend  = [100, 88, 23 , 18] // defend left /right/up / down
var Ydefend = [23, 88, 23 , 99]// defend left /right/up / down
var Dattack = [10, 38, 53 , 90]//attack power left /right/up / down
var Yattack = [100, 100, 33 , 34] //attack power left /right/up / down
while (slaying) {
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random() * 10 + 1);
  if (youHit) {
// prompt player to choose left/right/up/down . multiply damage * Yattack and divide by Ddefend - uncover weakness /strenght as you play ==> totalDamage = damageThisRound * Ddefend/100 * Yattack /100
      totalDamage -= damageThisRound;
    alert ("You hit the dragon and did " + damageThisRound + " damage!/" + "Dragon health" + totalDamage); 
    if (totalDamage <= 0) {
      alert ("You did it! You slew the dragon!");
      slaying = false;
    } else {
    }
  } else {
    // H1: dragon player is dumb or H2: dragon player uses AI to uncover strenghts and weaknesses
     YtotalDamage -= damageThisRound;
    alert ("dragon hit you and did " + damageThisRound + " damage!/" + "You health" + YtotalDamage);
    if (YtotalDamage <= 0) {
      alert ("The dragon burninmate you!");
      slaying = false;
  }
}
}
Native Browser JavaScript
?