From d35c69421640a458d16c64d7f4a556ad9d6cdbd3 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Sat, 14 Apr 2018 00:08:16 -0400 Subject: [PATCH] Monster game!!! --- proj_1_monster/app.js | 79 +++++++++++++++++++++++++++++++++++++++ proj_1_monster/index.html | 40 +++++++++++++------- 2 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 proj_1_monster/app.js diff --git a/proj_1_monster/app.js b/proj_1_monster/app.js new file mode 100644 index 0000000..01afe6c --- /dev/null +++ b/proj_1_monster/app.js @@ -0,0 +1,79 @@ +PLAYER = 0; +MONSTER = 1; + +var app = new Vue({ + el: '#app', + data: { + pHP: 100, + mHP: 100, + gameOn: false, + logs: [], + }, + watch: { + pHP(value){ + if (value <= 0){ + alert("You lose"); + this.giveUp(); + } + }, + mHP(value){ + if (value <= 0){ + alert("You Win!"); + this.giveUp(); + } + } + }, + methods:{ + start(){ + this.gameOn = true; + this.mHP = 100; + this.pHP = 100; + this.logs = []; + }, + playerAttack(){ + console.log("player Attack"); + var dmg = this.getRandomInt(1, 10); + var log = {attacker: 'player', dmg: dmg} + this.mHP -= dmg; + this.logs.unshift(log); + this.monsterAttack(); + }, + specialAttack(){ + console.log("special Attack"); + var dmg = this.getRandomInt(1, 20); + var log = {attacker: 'player', dmg: dmg} + this.mHP -= dmg; + this.logs.unshift(log); + this.monsterAttack(); + }, + heal(){ + console.log("heal"); + var hp = this.getRandomInt(1, 10); + this.pHP += hp; + this.monsterAttack(); + }, + giveUp(){ + this.gameOn = false; + this.logs = []; + }, + monsterAttack(){ + console.log("attacked"); + var dmg = this.getRandomInt(1, 10); + var log = { attacker: 'monster', dmg: dmg} + this.pHP -= dmg; + this.logs.unshift(log); + }, + getRandomInt(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; + } + }, + computed: { + + mHPStyle(){ + return {width: this.mHP + "%"}; + }, + pHPStyle(){ + return {width: this.pHP + "%"}; + }, + } +}) diff --git a/proj_1_monster/index.html b/proj_1_monster/index.html index 17d14ed..ab080fd 100644 --- a/proj_1_monster/index.html +++ b/proj_1_monster/index.html @@ -12,42 +12,54 @@

YOU

-
- +
+ {{pHP}}

MONSTER

-
- +
+ {{mHP}}
-
+
- +
-
+
- - - - + + + +
    -
  • + -
+ + - \ No newline at end of file +