This repository has been archived on 2021-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
vuejs_course/prj-monster-01-starting-setup/app.js

49 lines
1.1 KiB
JavaScript

"use strict";
function getRandomValue(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
const app = Vue.createApp({
data() {
return {
playerHealth: 100,
monsterHealth: 100,
battleLog: [],
currentRound: 0,
};
},
computed: {
monsterBarStyles() {
return { width: this.monsterHealth + "%" };
},
playerBarStyles() {
return { width: this.playerHealth + "%" };
},
specialAttackAllowed() {
return this.currentRound % 3 !== 0;
},
},
methods: {
attackMonster() {
this.currentRound++;
this.monsterHealth -= getRandomValue(5, 12);
this.attackPlayer();
},
specialAttackMonster() {
this.currentRound++;
this.monsterHealth -= getRandomValue(10, 25);
this.attackPlayer();
},
this.attackPlayer();
},
healPlayer() {},
surrender() {},
attackPlayer() {
this.playerHealth -= attackValue(8, 15);
},
},
});
app.mount("#game");