-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
87 lines (86 loc) · 1.75 KB
/
app.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
new Vue({
el: '#app',
data: {
playerHealth: '100',
monsterHealth: '100',
gameIsRunning: false,
turns: []
},
methods: {
startGame() {
this.gameIsRunning = true;
this.playerHealth = 100;
this.monsterHealth = 100;
this.turns = [];
},
attack() {
var damage = this.calculateDamage(3, 10);
this.monsterHealth -= damage;
this.turns.unshift({
isPlayer: true,
text: 'You hit Monster for ' + damage
});
if (this.checkwin()) {
return;
}
this.monsterAttacks();
},
specialAttack() {
var damage = this.calculateDamage(8, 20);
this.monsterHealth -= damage;
this.turns.unshift({
isPlayer: true,
text: 'You hit Monster with your special attack for ' + damage
});
if (this.checkwin()) {
return;
}
this.monsterAttacks();
},
heal() {
if(this.playerHealth <= 90) {
this.playerHealth += 10;
} else {
this.playerHealth = 100
}
this.turns.unshift({
isPlayer: true,
text: 'You use a health potion'
});
this.monsterAttacks;
},
giveUp() {
this.gameIsRunning = false;
},
monsterAttacks() {
var damage = this.calculateDamage(5, 12);
this.playerHealth -= damage;
this.checkwin();
this.turns.unshift({
isPlayer: false,
text: 'Monster hits you for ' + damage
});
},
calculateDamage(min, max) {
return Math.max(Math.floor(Math.random() * max) + 1), min;
},
checkwin() {
if (this.monsterHealth <= 0) {
if(confirm('You won, new game?')) {
this.startGame();
} else {
this.gameIsRunning = false;
}
return true;
} else if (this.playerHealth <= 0) {
if(confirm('You lost, new game?')) {
this.startGame();
} else {
this.gameIsRunning = false;
}
return true;
}
return false;
}
}
});