From 4a01d95d25a6c59e20618365ba675a4d0736080d Mon Sep 17 00:00:00 2001 From: Cristiano Magro <cristiano.magro@vola.it> Date: Thu, 26 Dec 2024 23:48:44 +0100 Subject: [PATCH] logica per l'attacco al mostro --- 04 - monster slayer game/prj-monster-01-starting-setup/app.js | 34 ++++++++++++++++++++++++++-------- 1 files changed, 26 insertions(+), 8 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 7a1c0b4..a617f63 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 @@ -1,10 +1,28 @@ +function getRandomValue(min, max){ + return Math.floor(Math.random() * (max - min)) + min; +} + + const app = Vue.createApp({ - data() { - return {}; + data() { + return { + playerHealth: 100, + monsterHealth: 100, + }; + }, + computed: {}, + watch: {}, + methods: { + attackMonster() { + const attackValue = getRandomValue(5,12); + this.monsterHealth -= attackValue; + this.attackPlayer(); }, - computed: {}, - watch: {}, - methods: {}, - }); - - app.mount("#game"); \ No newline at end of file + attackPlayer(){ + const attackValue = getRandomValue(8,15); + this.playerHealth -= attackValue; + }, + }, +}); + +app.mount("#game"); -- Gitblit v1.8.0