implement game over by watch
| | |
| | | playerHealth: 100, |
| | | monsterHealth: 100, |
| | | currentRound: 0, |
| | | winner: null, |
| | | }; |
| | | }, |
| | | computed: { |
| | |
| | | return this.currentRound % 3 !== 0; |
| | | }, |
| | | }, |
| | | watch: {}, |
| | | watch: { |
| | | playerHealt(value) { |
| | | if (value <= 0 && this.monsterHealth <= 0) { |
| | | this.winner = "draw"; |
| | | } else if (value <= 0) { |
| | | this.winner = "moster"; |
| | | } |
| | | }, |
| | | monsterHealth(value) { |
| | | if (value <= 0 && this.playerHealt <= 0) { |
| | | this.winner = "draw"; |
| | | } else if (value <= 0) { |
| | | this.winner = "player"; |
| | | } |
| | | }, |
| | | }, |
| | | methods: { |
| | | attackMonster() { |
| | | this.currentRound++; |
| | |
| | | <div class="healthbar__value" :style="playerBarStyle"></div> |
| | | </div> |
| | | </section> |
| | | <section class="container" v-if="winner"> |
| | | <h2>Game Over!</h2> |
| | | <h3 v-if="winner == 'monster'">You lost!</h3> |
| | | <h3 v-else-if="winner == 'player'">You won!</h3> |
| | | <h3 v-else>It's a Draw</h3> |
| | | </section> |
| | | <section id="controls"> |
| | | <button @click="attackMonster">ATTACK</button> |
| | | <button @click="specialAttackMonster" :disabled="mayUseSpecialAttack"> |