From 8c672a568ad096f28d4c3a2ba95b01ecc30cc3ce Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Thu, 26 Dec 2024 23:51:23 +0100
Subject: [PATCH] draw bar healt after attack

---
 04 - monster slayer game/prj-monster-01-starting-setup/app.js |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 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
new file mode 100644
index 0000000..75dc449
--- /dev/null
+++ b/04 - monster slayer game/prj-monster-01-starting-setup/app.js
@@ -0,0 +1,35 @@
+function getRandomValue(min, max){
+    return Math.floor(Math.random() * (max - min)) + min;
+}
+
+
+const app = Vue.createApp({
+  data() {
+    return {
+      playerHealth: 100,
+      monsterHealth: 100,
+    };
+  },
+  computed: {
+    monsterBarStyle(){
+        return {width: this.monsterHealth + '%'}
+    },
+    playerBarStyle(){
+        return {width: this.playerHealth + '%'}
+    },
+  },
+  watch: {},
+  methods: {
+    attackMonster() {
+      const attackValue = getRandomValue(5,12);
+      this.monsterHealth -= attackValue;
+      this.attackPlayer();
+    },
+    attackPlayer(){
+        const attackValue = getRandomValue(8,15);
+        this.playerHealth -= attackValue;
+    },
+  },
+});
+
+app.mount("#game");

--
Gitblit v1.8.0