commit | author | age
|
5529c7
|
1 |
function getRandomValue(min, max) { |
CM |
2 |
return Math.floor(Math.random() * (max - min)) + min; |
4a01d9
|
3 |
} |
CM |
4 |
|
14370b
|
5 |
const app = Vue.createApp({ |
4a01d9
|
6 |
data() { |
CM |
7 |
return { |
|
8 |
playerHealth: 100, |
|
9 |
monsterHealth: 100, |
5529c7
|
10 |
currentRound: 0, |
4a01d9
|
11 |
}; |
CM |
12 |
}, |
8c672a
|
13 |
computed: { |
5529c7
|
14 |
monsterBarStyle() { |
CM |
15 |
return { width: this.monsterHealth + "%" }; |
8c672a
|
16 |
}, |
5529c7
|
17 |
playerBarStyle() { |
CM |
18 |
return { width: this.playerHealth + "%" }; |
|
19 |
}, |
|
20 |
mayUseSpecialAttack() { |
|
21 |
return this.currentRound % 3 !== 0; |
8c672a
|
22 |
}, |
CM |
23 |
}, |
4a01d9
|
24 |
watch: {}, |
CM |
25 |
methods: { |
|
26 |
attackMonster() { |
5529c7
|
27 |
this.currentRound++; |
CM |
28 |
const attackValue = getRandomValue(5, 12); |
4a01d9
|
29 |
this.monsterHealth -= attackValue; |
CM |
30 |
this.attackPlayer(); |
14370b
|
31 |
}, |
5529c7
|
32 |
attackPlayer() { |
CM |
33 |
const attackValue = getRandomValue(8, 15); |
|
34 |
this.playerHealth -= attackValue; |
|
35 |
}, |
|
36 |
specialAttackMonster() { |
|
37 |
this.currentRound++; |
|
38 |
const attackValue = getRandomValue(10, 20); |
|
39 |
this.monsterHealth -= attackValue; |
|
40 |
this.attackPlayer(); |
4a01d9
|
41 |
}, |
02ffa3
|
42 |
healPlayer() { |
CM |
43 |
this.currentRound++; |
|
44 |
const healValue = getRandomValue(8, 20); |
|
45 |
if (this.playerHealth + healValue > 100) { |
|
46 |
this.playerHealth = 100; |
|
47 |
} else { |
|
48 |
this.playerHealth += healValue; |
|
49 |
} |
|
50 |
this.attackPlayer(); |
|
51 |
}, |
4a01d9
|
52 |
}, |
CM |
53 |
}); |
|
54 |
|
|
55 |
app.mount("#game"); |