-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (55 loc) · 1.68 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
new Vue({
el: '#app',
data: {
running: false,
playerLife: 100,
monsterLife: 100,
logs: []
},
computed: {
hasResult() {
return this.playerLife == 0 || this.monsterLife == 0
}
},
methods: {
startGame() {
this.running = true
this.playerLife = 100
this.monsterLife = 100
this.logs = []
},
attack(especial) {
this.hurt('monsterLife', 5, 10, especial, 'Jogador', 'Monstro', 'player')
if(this.monsterLife > 0) {
this.hurt('playerLife', 7, 12, false, 'Monstro', 'Jogador', 'monster')
}
},
hurt(prop, min, max, especial, source, target, cls) {
const plus = especial ? 5 : 0
const hurt = this.getRandom(min + plus, max + plus)
this[prop] = Math.max(this[prop] - hurt, 0)
this.registerLog(`${source} atingiu ${target} com ${hurt}.`, cls)
},
healAndHurt() {
this.heal(10, 15)
this.hurt('playerLife', 7, 12, false, 'Monstro', 'Jogador', 'monster')
},
heal(min, max) {
const heal = this.getRandom(min, max)
this.playerLife = Math.min(this.playerLife + heal, 100)
this.registerLog(`Jogador ganhou força de ${heal}.`, 'player')
},
getRandom(min, max) {
const value = Math.random() * (max - min) + min
return Math.round(value)
},
registerLog(text, cls) {
this.logs.unshift({ text, cls })
}
},
watch: {
hasResult(value) {
if (value) this.running = false
}
}
})