-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
88 lines (87 loc) · 3 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
88
const app = Vue.createApp({
data() {
return {
playerHealth: 0,
monsterHealth: 0,
specialAttackCD: 0,
healCD: 0,
battleLog: [],
gameOn: false,
surrenderText: '',
endGameText: ''
};
},
methods: {
startGame() {
if(!this.gameOn) {
this.playerHealth = 100;
this.monsterHealth = 100;
this.specialAttackCD = 4;
this.healCD = 3;
this.battleLog = [];
this.gameOn = true;
this.endGameText = '';
}
},
surrenderGame() {
this.gameOn = false;
this.endGameText = 'You fleed.';
},
endGame() {
if (this.playerHealth <= 0 && this.monsterHealth <= 0) {
this.playerHealth = 0;
this.monsterHealth = 0;
this.endGameText = "You killed a monster but at the same time u also died.";
this.gameOn = false;
} else if (this.playerHealth <= 0) {
this.playerHealth = 0;
this.endGameText = 'You get slayed!';
this.gameOn = false;
} else if (this.monsterHealth <= 0) {
this.monsterHealth = 0;
this.endGameText = "You killed a monster!";
this.gameOn = false;
}
},
playerAttack() {
const playerDamage = this.calculateAmmount(5, 15);
this.monsterHealth -= playerDamage;
this.battleLog.unshift(`Player attacked Monster for ${playerDamage}`);
this.checkCooldowns();
this.endGame();
},
monsterAttack() {
const monsterDamage = this.calculateAmmount(8, 18);
this.playerHealth -= monsterDamage;
this.battleLog.unshift(`Monster attacked Player for ${monsterDamage}`);
this.endGame();
},
specialAttack(power) {
const playerDamage = this.calculateAmmount(8, 18) + power;
this.monsterHealth -= playerDamage;
this.battleLog.unshift(`Player attacked Monster for ${playerDamage}`);
this.checkCooldowns()
this.specialAttackCD = 4;
this.endGame();
},
heal() {
const healAmount = this.calculateAmmount(5,10)
this.playerHealth += healAmount;
this.battleLog.unshift(`Player healed for ${healAmount}`);
this.checkCooldowns()
this.healCD = 3;
},
checkCooldowns() {
if(this.specialAttackCD !== 0) {
this.specialAttackCD--
}
if(this.healCD !== 0) {
this.healCD--
}
},
calculateAmmount(min, max) {
return Math.max(Math.floor(Math.random() * max) + 1, min);
},
}
})
app.mount("#game");