diff --git a/index.html b/index.html index f8f8ae0..4203ad3 100644 --- a/index.html +++ b/index.html @@ -85,10 +85,10 @@ {{ currentQuest.bricks }}

- Redeem reward ({{ currentQuest.reward }} ) + Redeem reward ({{ currentQuest.reward }} )
- Get Quest (resources needed) + Get Quest (resources needed)
diff --git a/js/app.js b/js/app.js index c959d97..2ba066b 100644 --- a/js/app.js +++ b/js/app.js @@ -3,8 +3,8 @@ let game = new Vue({ data: { money: 0, resources: { - wood: 2, - stone: 2, + wood: 50, + stone: 0, iron: 0, bricks: 0, corn: 0 @@ -77,7 +77,9 @@ let game = new Vue({ created() { this.money = this.getSavedMoney(); this.saveMoney(); + this.loadResources(); + this.loadBuildings(); this.reloadBuildings(); }, methods: { @@ -107,6 +109,7 @@ let game = new Vue({ break; } + this.saveResources(); return this.saveMoney(); }, @@ -225,15 +228,28 @@ let game = new Vue({ loadBuildings: function () { let savedBuildings = JSON.parse(localStorage.getItem('buildings')); - if (savedBuildings.length > 0) { + if (savedBuildings) { this.buildings = savedBuildings; } }, + saveResources() { + localStorage.setItem('resources', JSON.stringify(this.resources)); + }, + + loadResources: function () { + let savedResources = JSON.parse(localStorage.getItem('resources')); + + if (savedResources) { + this.resources = savedResources; + } + }, + generateQuest() { let possibleAmountsForQuest = [ 0, 5, 10, 15, 20, 25, 30, 35 ]; + let randomWood = 0; let randomStone = 0; let randomIron = 0; @@ -289,22 +305,27 @@ let game = new Vue({ isQuestRedeemable() { return ( - this.wood >= this.currentQuest.wood && - this.stone >= this.currentQuest.stone && - this.iron >= this.currentQuest.iron && - this.bricks >= this.currentQuest.bricks && - this.corn >= this.currentQuest.corn + this.resources.wood >= this.currentQuest.wood && + this.resources.stone >= this.currentQuest.stone && + this.resources.iron >= this.currentQuest.iron && + this.resources.bricks >= this.currentQuest.bricks && + this.resources.corn >= this.currentQuest.corn ); }, - redeemQuest() { + redeemReward() { if (this.isQuestRedeemable()) { this.money += this.currentQuest.reward; + this.resources.wood -= this.currentQuest.wood; + this.resources.stone -= this.currentQuest.stone; + this.resources.iron -= this.currentQuest.iron; + this.resources.bricks -= this.currentQuest.bricks; + this.resources.corn -= this.currentQuest.corn; + this.generateQuest(); } else { return false; } - } }, });