-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
87 lines (84 loc) · 2.47 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
var app = new Vue({
el: '#app',
data: {
playing: false,
currentPlayerLife: 100,
currentMonsterLife: 100,
playerPower: 10,
monsterPower: 13,
actionsLogs: [],
winner: '',
hasWinner: false
},
watch: {
currentPlayerLife(current){
if(current <= 0){
this.currentPlayerLife = 0
this.playing = false
this.winner = 'monster'
this.hasWinner = true
}
},
currentMonsterLife(current){
if(current <= 0){
this.currentMonsterLife = 0
this.playing = false
this.winner = 'player'
this.hasWinner = true
}
},
playing(){
if (this.currentMonsterLife <= 0 && this.currentPlayerLife <= 0){
this.winner = 'draw'
}
}
},
computed: {
disable(){
return this.currentPlayerLife >= 100 ? true : false
},
healthStylePlayer(){
return {
width: `${this.currentPlayerLife}%`,
backgroundColor: this.currentPlayerLife < 20 ? '#ff0000c4' : '#087508'
}
},
healthStyleMonster(){
return {
width: `${this.currentMonsterLife}%`,
backgroundColor: this.currentMonsterLife < 20 ? '#ff0000c4' : '#087508'
}
}
},
methods: {
randomNumber(min, max){
return Math.floor(Math.random() * (max - min) ) + min;
},
attack(specialAttack){
let currentPlayerPower = this.playerPower
if(specialAttack) currentPlayerPower += 8
let monsterAttack = this.randomNumber(5, this.monsterPower)
let playerAttack = this.randomNumber(5, currentPlayerPower)
this.currentPlayerLife -= monsterAttack
this.currentMonsterLife -= playerAttack
this.actionsLogs.unshift({ monsterAttack: `MONSTRO ATACOU JOGADOR COM ${monsterAttack}`,
playerAttack: `JOGADOR ATACOU MONSTRO COM ${playerAttack}`})
},
heal(){
let monsterAttack = this.randomNumber(5, this.monsterPower)
let playerHeal = this.randomNumber(5, 13)
this.currentPlayerLife -= monsterAttack
this.currentPlayerLife += playerHeal
if(this.currentPlayerLife > 100) this.currentPlayerLife = 100
this.actionsLogs.unshift({ monsterAttack: `MONSTRO ATACOU JOGADOR COM ${monsterAttack}`,
playerAttack: `JOGADOR CUROU COM ${playerHeal}`})
},
startGame(){
this.playing = true
this.currentPlayerLife = 100
this.currentMonsterLife = 100
this.actionsLogs = []
this.hasWinner = false
}
}
})