add a function to heal the player

This commit is contained in:
Andreas Zweili 2021-01-22 19:50:16 +01:00
parent 3ffbadeb3a
commit 12a907e630
2 changed files with 10 additions and 3 deletions

View File

@ -35,12 +35,19 @@ const app = Vue.createApp({
this.monsterHealth -= getRandomValue(10, 25); this.monsterHealth -= getRandomValue(10, 25);
this.attackPlayer(); this.attackPlayer();
}, },
healPlayer() {
this.currentRound++;
const healValue = getRandomValue(8, 20);
if (this.playerHealth + healValue > 100) {
this.playerHealth = 100;
} else {
this.playerHealth += healValue;
}
this.attackPlayer(); this.attackPlayer();
}, },
healPlayer() {},
surrender() {}, surrender() {},
attackPlayer() { attackPlayer() {
this.playerHealth -= attackValue(8, 15); this.playerHealth -= getRandomValue(8, 15);
}, },
}, },
}); });

View File

@ -31,7 +31,7 @@
<section id="controls"> <section id="controls">
<button @click="attackMonster">ATTACK</button> <button @click="attackMonster">ATTACK</button>
<button :disabled="specialAttackAllowed" @click="specialAttackMonster">SPECIAL ATTACK</button> <button :disabled="specialAttackAllowed" @click="specialAttackMonster">SPECIAL ATTACK</button>
<button>HEAL</button> <button @click="healPlayer">HEAL</button>
<button>SURRENDER</button> <button>SURRENDER</button>
</section> </section>
<section id="log" class="container"> <section id="log" class="container">