From 807972024cb2e4c0f2235d7a8941e201ea40ca2c Mon Sep 17 00:00:00 2001 From: Cristiano Magro <cristiano.magro@vola.it> Date: Fri, 27 Dec 2024 00:22:00 +0100 Subject: [PATCH] implement game over by watch --- 04 - monster slayer game/prj-monster-01-starting-setup/app.js | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/04 - monster slayer game/prj-monster-01-starting-setup/app.js b/04 - monster slayer game/prj-monster-01-starting-setup/app.js index 8c7319a..4422cc1 100644 --- a/04 - monster slayer game/prj-monster-01-starting-setup/app.js +++ b/04 - monster slayer game/prj-monster-01-starting-setup/app.js @@ -8,6 +8,7 @@ playerHealth: 100, monsterHealth: 100, currentRound: 0, + winner: null, }; }, computed: { @@ -21,7 +22,22 @@ 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++; -- Gitblit v1.8.0