-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
55 lines (55 loc) · 2.33 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
new Vue({
el: "#app",
data: {
gameOn: false,
playerHealth: 100,
monsterHealth: 100,
battleLog: []
},
methods: {
atk: function () {
var damage = Math.floor(Math.random() * Math.floor(10));
this.monsterHealth -= damage;
this.battleLog = ["Player did " + damage + " damage to monster"].concat(this.battleLog);
if (this.monsterHealth >= 0) {
damage = Math.floor(Math.random() * Math.floor(10));
this.playerHealth -= damage;
this.battleLog = ["Monster did " + damage + " damage to player"].concat(this.battleLog);
if (this.playerHealth <= 0) {
this.battleLog = ["You died bravely..."].concat(this.battleLog);
this.gameOn = false;
}
} else {
this.battleLog = ["You win!"].concat(this.battleLog);
this.gameOn = false;
}
},
spatk: function () {
this.monsterHealth -= 10;
this.battleLog = ["Player did " + damage + " damage to monster"].concat(this.battleLog);
if (this.monsterHealth >= 0) {
var damage = Math.floor(Math.random() * Math.floor(10));
this.playerHealth -= damage
this.battleLog = ["Monster did " + damage + " damage to player"].concat(this.battleLog);
if (this.playerHealth <= 0) {
this.battleLog = ["You died bravely..."].concat(this.battleLog);
this.gameOn = false;
}
} else {
this.battleLog = ["You win!"].concat(this.battleLog);
this.gameOn = false;
}
},
heal: function () {
this.playerHealth += 10;
this.battleLog = ["Player healed for 10 health"].concat(this.battleLog);
var damage = Math.floor(Math.random() * Math.floor(10));
this.playerHealth -= damage;
this.battleLog = ["Monster did " + damage + " damage to player"].concat(this.battleLog);
if (this.playerHealth <= 0) {
this.battleLog = ["You died bravely..."].concat(this.battleLog);
this.gameOn = false;
}
}
}
})