forked from CoachJulian/2023TeamEdgeTerm0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuperheros.js
147 lines (109 loc) · 4.31 KB
/
superheros.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
/********************************************************************
*
* Team Edge objects: SUPERHERO CHALLENGES
*
* In this challenge you are going to modify this code to do the
* the following below. Before you begin, walkthrough the code
* with your coaches.
*
* 1. Change both superhero and nemesis using same class.
* 2. Change the constants to modify gameplay and see how it affects
* the game outcomes.
* 3. Make any improvements you think would make this game better.
* 4. Complete all the comments to demonstrate you understand the code
* Be specific about what each code block is doing.
*
*
* ***************************************************************/
console.log("------------------- SUPERHERO !! -------------------")
const DELAY = 3000
const DAMAGE_LIMIT = 5
const MAJOR_BLOW = DAMAGE_LIMIT -2
const LIVES_TOP_RANGE = 60
const LIVES_BOTTOM_RANGE = 40
let rounds = 1
let gameIsOn = true
//COMMENT 1:
class Superhero {
constructor(name, isAlive, friends, hitPoints, isGood , attackPower) {
this.name = name;
this.isAlive = isAlive;
this.taunts=[]
this.cries=[]
this.lives = []
} attack(enemy){
//COMMENT 2 ....
if(this.isAlive && enemy.isAlive){
console.log(" \n ")
let damage = randomInteger(0,DAMAGE_LIMIT)
enemy.lives.splice(0, damage)
if(damage >= MAJOR_BLOW){
console.log(` ⚔️⚔️⚔️ Major Blow! ⚔️⚔️⚔️ \n`)
}
//COMMENT 3....
console.log(`${this.name} 💬 : ${this.taunts[randomInteger(0,this.taunts.length-1)]} \n`)
console.log(`${this.name} 💥X ${damage} ${enemy.name} ${enemy.lives} : ${enemy.lives.length} \n`)
if(enemy.lives.length <= 0){
//COMMENT 4....
enemy.isAlive=false
gameIsOn =false
console.log(`💀💀💀💀💀💀 ${enemy.name} has been slain!!! 💀💀💀💀💀 `)
console.log(` GAME OVER `)
clearInterval(timer)
}
if(this.lives.length <= 0 ){
this.isAlive = false
gameIsOn =false
console.log(`💀💀💀💀💀💀 ${this.name} has been slain!!! 💀💀💀💀💀`)
console.log(` GAME OVER `)
clearInterval(timer);
}
}
}
fillHealth(){
//COMMENT 5....
let amt = randomInteger(LIVES_BOTTOM_RANGE, LIVES_TOP_RANGE)
for(let i = 0; i <= amt ; i++){
this.lives.push("💙")
}
}
}
//COMMENT 6....
let batman = new Superhero()
batman.name="Batman 🦸♂️"
batman.isAlive = true
batman.lives=[]
batman.taunts=["The Dark Knight always wins!" , "You can't hang with the bat man" , "Meet my fist, scumbag" , "You Suck!"]
batman.cries=["Ouch!" , "UFF!" , "Gaaaaaaa" , "No!!!!!"]
batman.fillHealth()
let joker = new Superhero()
joker.name = "Joker 🦹♂️"
joker.isAlive = true
joker.lives=[]
joker.taunts =["You are a schmemer" , "Don't mess with the Joker!" , "Pick your face off the ground, you might need it!", "Getting tired of the beatings?"]
joker.cries = ["Aaaa!" , "Goh!" , "Hmph!" ,"You will pay for this"]
joker.fillHealth()
console.log(`${joker.name} : ${joker.lives} - ${joker.lives.length}`)
console.log(`${batman.name} : ${batman.lives} - ${batman.lives.length} `)
console.log(`${batman.name} 💬 ${batman.taunts[1]} \n `)
console.log(`${joker.name} 💬 ${joker.taunts[1]} \n `)
//COMMENT 7....
function fight(a, b){
console.log(" ------------- ROUND -------------> " + rounds)
a.attack(b)
b.attack(a)
rounds ++
}
//This helper function returns a random number between a given min and max value, and is used various times in this game.
function randomInteger(min, max) {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min + 1)) + min
}
//COMMENT 8....
let timer = setInterval(function() {
if(gameIsOn){
fight(batman,joker)
console.log(" \n")
}
}, DELAY);