-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
52 lines (42 loc) · 2.53 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
//Make the USS HelloWorld class object (even though there is only one ship for team Earth right now I will create a class b/c it makes more sense to me with my logic and also so I could always add new earthSpaceShip instances in the future with an array)
class EarthSpaceShip {
constructor(name, hull, firepower, accuracy) {
this.name = name;
this.hull = hull;
this.firepower = firepower;
this.accuracy = accuracy;
this.isAlive = true;
}
attack(target) {
target.hull = target.hull - ussHelloWorld.firepower; //firepower is the amount of damage done to the hull of the target with a successful hit so take the target's current hull and subtract the attacker's firepower
if (target.hull <= 0) {
//If hull reaches 0 or less, the ship is destroyed
target.isAlive = false;
console.log("You have destroyed the target!");
}
}
}
const ussHelloWorld = new EarthSpaceShip("USS HelloWorld", 20, 5, 0.7);
console.log(ussHelloWorld);
//Make an alienSpaceShip class object (will create an array of 6 consts of this class using a for loop)
class AlienSpaceShip {
constructor(name, hull, firepower, accuracy) {
this.name = name;
this.hull = hull;
this.firepower = firepower;
this.accuracy = accuracy;
this.isAlive = true;
}
}
//creating one AlienSpaceShip instance first and assigning it values to test the battle now between these 2 ships only
const interGalactic = new AlienSpaceShip("Intergalactic", 4, 3, 0.7);
console.log(interGalactic);
//while I'm thinking of alien spaceship names: Astral Plane, Blazing Arrow, Cosmic Flows, planetHopper, spaceCase, galaxy warriors, infinity, solarShip, starryNight, Earth Shatterer, Abyss, Cosmic Jungle, Not a Meteorite, Gravity Sucks, Universal Soldiers , Sonic Boom, Saturn Hoops, Alienaughts ,
ussHelloWorld.attack(interGalactic); // running the attack method and passing the alien ship through the function as the target
console.log(interGalactic.hull); // yay! my one ship test works, so onto the next.
// 1st commit to github
//Make a
const battle = (ussHelloWorld, interGalactic) => {};
//***when I start fresh tomorrow, finish it with just the 2 ships and then go from there***
//wait, stop, I think i only need ONE ship class and then instance of const USS Hello World and instance of alien array object of 6 ships and use "this" for the attack method and pass through which ship in the argument
//after realizing that I wanted to try only one Class of Ship I started my code over on file js\script2.js