-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonsterSlayer.js
91 lines (90 loc) · 2.72 KB
/
monsterSlayer.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
89
90
91
var app = new Vue({
el : '#app',
data : {
myHealBar : 100,
monsterHealBar : 100,
gameIsStarting : false,
logs : [],
},
methods : {
gameStart : function(){
this.gameIsStarting = true,
this.myHealBar = 100,
this.monsterHealBar = 100,
this.logs = [];
},
attack(){
var damage = this.checkDamage(10,3)
this.monsterHealBar -= damage;
this.logs.unshift({
isPlayer : true,
text : 'Player hit Monster hard for ' + damage
});
this.monsterAttack()
this.checkWin()
},
specialAttack(){
var damage = this.checkDamage(20,10)
this.monsterHealBar -= damage;
this.logs.unshift({
isPlayer : true,
text : 'Player hit Monster hard for ' + damage,
});
this.monsterAttack()
this.checkWin()
},
heal(){
if(this.myHealBar <= 90){
this.myHealBar += 10;
}else{
this.myHealBar = 100
}
this.logs.unshift({
isPlayer : true,
text : 'Player Heal for 10'
})
this.monsterAttack()
},
giveUp(){
this.gameIsStarting = false;
this.logs = []
this.myHealBar = 100;
this.monsterHealBar=100;
},
checkDamage(max,min){
return Math.max(Math.floor(Math.random()* max)+1,min);
},
checkWin(){
if(this.monsterHealBar <= 0){
if(confirm('You Won! Do You Want to Start A New Game?')){
this.gameStart()
}else{
this.gameIsStarting = false
this.logs = []
this.myHealBar = 100;
this.monsterHealBar=100;
}
return true
}else if(this.myHealBar <= 0){
if(confirm('You Lost! Do You Want to Start A New Game')){
this.gameStart()
}else{
this.gameIsStarting = false
this.logs = []
this.myHealBar = 100;
this.monsterHealBar=100;
}
return true
}
return false
},
monsterAttack(){
var damage = this.checkDamage(12,5)
this.myHealBar -= damage;
this.logs.unshift({
isPlayer : false,
text : 'Monster hit player hard for ' + damage,
});
}
}
})