cleanup refactor a bit

This commit is contained in:
Tyrel Souza 2018-04-14 00:55:51 -04:00
parent 1605e37c6d
commit c4d5b97bb1
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
2 changed files with 13 additions and 22 deletions

View File

@ -32,24 +32,24 @@ var app = new Vue({
}, },
playerAttack(){ playerAttack(){
console.log("player Attack"); console.log("player Attack");
var dmg = this.getRandomInt(1, 10); var dmg = this.getRandomInt(3, 10);
var log = {attacker: 'player', dmg: dmg}
this.mHP -= dmg; this.mHP -= dmg;
this.logs.unshift(log); this.logs.unshift({isPlayer: true, text: 'Player hits monster for ' + dmg});
this.monsterAttack(); this.monsterAttack();
}, },
specialAttack(){ specialAttack(){
console.log("special Attack"); console.log("special Attack");
var dmg = this.getRandomInt(1, 20); var dmg = this.getRandomInt(10, 20);
var log = {attacker: 'player', dmg: dmg}
this.mHP -= dmg; this.mHP -= dmg;
this.logs.unshift(log); this.logs.unshift({isPlayer: true, text: 'Player hits monster hard for ' + dmg});
this.monsterAttack(); this.monsterAttack();
}, },
heal(){ heal(){
console.log("heal"); console.log("heal");
var hp = this.getRandomInt(1, 10); var hp = 10
this.pHP += hp; this.pHP = Math.min(100, this.pHP + 10 );
var log =
this.logs.unshift({isPlayer: true, text: 'Player heals for 10'});
this.monsterAttack(); this.monsterAttack();
}, },
giveUp(){ giveUp(){
@ -58,8 +58,8 @@ var app = new Vue({
}, },
monsterAttack(){ monsterAttack(){
console.log("attacked"); console.log("attacked");
var dmg = this.getRandomInt(1, 10); var dmg = this.getRandomInt(5, 12);
var log = { attacker: 'monster', dmg: dmg} var log = { isPlayer: false, text: 'monster hits player for ' + dmg}
this.pHP -= dmg; this.pHP -= dmg;
this.logs.unshift(log); this.logs.unshift(log);
}, },

View File

@ -42,18 +42,9 @@
<section class="row log"> <section class="row log">
<div class="small-12 columns"> <div class="small-12 columns">
<ul> <ul>
<template v-for="log in logs"> <li v-for="log in logs" :class="[{'player-turn': log.isPlayer, 'monster-turn': !log.isPlayer}]">
<template v-if="log.attacker == 'player'"> {{log.text}}
<li class="player-turn">
player hits monster for {{log.dmg}} damage.
</li> </li>
</template>
<template v-else>
<li class="monster-turn">
monster hits player for {{log.dmg}} damage.
</li>
</template>
</template>
</ul> </ul>
</div> </div>