my solution to the battlelog

This commit is contained in:
Andreas Zweili 2021-01-22 20:14:19 +01:00
parent b8850474a8
commit 29a258cc73
2 changed files with 22 additions and 4 deletions

View File

@ -77,12 +77,18 @@ const app = Vue.createApp({
}, },
attackMonster() { attackMonster() {
this.currentRound++; this.currentRound++;
this.monsterHealth -= getRandomValue(5, 12); const attackValue = getRandomValue(5, 12);
this.monsterHealth -= attackValue;
this.addToBattleLog("You deal " + attackValue + " damage.");
this.attackPlayer(); this.attackPlayer();
}, },
specialAttackMonster() { specialAttackMonster() {
this.currentRound++; this.currentRound++;
this.monsterHealth -= getRandomValue(10, 25); const attackValue = getRandomValue(10, 25);
this.monsterHealth -= attackValue;
this.addToBattleLog(
"Your special attack deals " + attackValue + " damage."
);
this.attackPlayer(); this.attackPlayer();
}, },
healPlayer() { healPlayer() {
@ -93,13 +99,23 @@ const app = Vue.createApp({
} else { } else {
this.playerHealth += healValue; this.playerHealth += healValue;
} }
this.addToBattleLog(
"You heal yourself with " + healValue + " heal points."
);
this.attackPlayer(); this.attackPlayer();
}, },
surrender() { surrender() {
this.winner = "monster"; this.winner = "monster";
}, },
attackPlayer() { attackPlayer() {
this.playerHealth -= getRandomValue(8, 15); const attackValue = getRandomValue(8, 15);
this.addToBattleLog(
"The monster deals " + attackValue + " damage."
);
this.playerHealth -= attackValue;
},
addToBattleLog(input) {
this.battleLog.push(input);
}, },
}, },
}); });

View File

@ -43,7 +43,9 @@
</section> </section>
<section id="log" class="container"> <section id="log" class="container">
<h2>Battle Log</h2> <h2>Battle Log</h2>
<ul></ul> <ul>
<li v-for=" item in battleLog" :key="item">{{ item }}</li>
</ul>
</section> </section>
</div> </div>
</body> </body>