logica per l'attacco al mostro
| | |
| | | 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"); |
| | | attackPlayer(){ |
| | | const attackValue = getRandomValue(8,15); |
| | | this.playerHealth -= attackValue; |
| | | }, |
| | | }, |
| | | }); |
| | | |
| | | app.mount("#game"); |
| | |
| | | rel="stylesheet" |
| | | /> |
| | | <link rel="stylesheet" href="styles.css" /> |
| | | <script src="https://unpkg.com/vue@next" defer></script> |
| | | <script src="https://unpkg.com/vue@3.4.9/dist/vue.global.js"></script> |
| | | <script src="app.js" defer></script> |
| | | </head> |
| | | <body> |