-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (56 loc) · 1.67 KB
/
app.js
File metadata and controls
56 lines (56 loc) · 1.67 KB
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
new Vue({
el: '#app',
data:{
playerLife: 100,
monsterLife: 100,
running: false,
logs: []
},
computed:{
hasResult(){
return this.playerLife == 0 || this.monsterLife==0
}
},
methods:{
startGame(){
this.running=true,
this.playerLife =100,
this.monsterLife =100,
this.logs = []
},
attack(special){
this.hurt('playerLife',5,10,special, 'Player', 'Monster', 'player')
if(this.monsterLife > 0){
this.hurt('monsterLife',7,12,false,'Monster','Player','monster')
}
},
hurt(prop,min,max,special,source,target,cls){
const plus = special ? 5 : 0
const hurt = this.getRandom(min+plus, max + plus)
this[prop] = Math.max(this[prop] - hurt,0)
this.registerLog(`${source} attacked ${target} with ${hurt}.`, cls)
},
getRandom(min, max){
const value = Math.random() * (max-min) + min
return Math.round(value)
},
healAndHurt(){
this.heal(10,15)
this.hurt('playerLife',7,12,false, 'Monster', 'Player', 'monster')
},
heal(min,max){
const heal = this.getRandom(min,max)
this.playerLife = Math.min(this.playerLife + heal, 100)
this.registerLog(`Player gained strength with ${heal}.`,'player')
},
registerLog(text,cls){
this.logs.unshift({text,cls})
console.log(this.logs)
}
},
watch:{
hasResult(value){
if(value) this.running = false
}
}
})