diff --git a/prj-monster-01-starting-setup/app.js b/prj-monster-01-starting-setup/app.js index 8745c59..973fe89 100644 --- a/prj-monster-01-starting-setup/app.js +++ b/prj-monster-01-starting-setup/app.js @@ -11,6 +11,7 @@ const app = Vue.createApp({ monsterHealth: 100, battleLog: [], currentRound: 0, + winner: null, }; }, computed: { @@ -23,6 +24,43 @@ const app = Vue.createApp({ specialAttackAllowed() { return this.currentRound % 3 !== 0; }, + playerWon() { + if (this.winner === "player") { + return true; + } else { + return false; + } + }, + monsterWon() { + if (this.winner === "monster") { + return true; + } else { + return false; + } + }, + draw() { + if (this.winner === "draw") { + return true; + } else { + return false; + } + }, + }, + watch: { + playerHealth(value) { + if (value <= 0 && this.monsterHealth <= 0) { + this.winner = "draw"; + } else if (value <= 0) { + this.winner = "monster"; + } + }, + monsterHealth(value) { + if (value <= 0 && this.playerHealth <= 0) { + this.winner = "draw"; + } else if (value <= 0) { + this.winner = "player"; + } + }, }, methods: { attackMonster() { diff --git a/prj-monster-01-starting-setup/index.html b/prj-monster-01-starting-setup/index.html index 5d02080..7d8cf34 100644 --- a/prj-monster-01-starting-setup/index.html +++ b/prj-monster-01-starting-setup/index.html @@ -22,6 +22,12 @@
+
+

Game Over!

+

You lost!

+

You won!

+

It's a draw'!

+

Your Health