diff --git a/index.html b/index.html index bbd9e65..c955a04 100644 --- a/index.html +++ b/index.html @@ -71,6 +71,24 @@ + +
+
+

Quests

+
+
+
+ The following items are needed:
+ {{ currentQuest.wood }} + {{ currentQuest.stone }} + {{ currentQuest.iron }} + {{ currentQuest.bricks }} +
+
+ Redeem reward ({{ currentQuest.reward }} ) +
+
+
diff --git a/js/app.js b/js/app.js index 0691dab..27a0b2c 100644 --- a/js/app.js +++ b/js/app.js @@ -3,8 +3,8 @@ let game = new Vue({ data: { money: 0, resources: { - wood: 0, - stone: 0, + wood: 2, + stone: 2, iron: 0, bricks: 0, corn: 0 @@ -228,6 +228,73 @@ let game = new Vue({ if (savedBuildings.length > 0) { this.buildings = savedBuildings; } + }, + + generateQuest() { + let possibleAmountsForQuest = [ + 0, 5, 10, 15, 20, 25, 30, 35 + ]; + let randomWood = 0; + let randomStone = 0; + let randomIron = 0; + let randomBricks = 0; + let randomCorn = 0; + let rewardSum = 0; + + + if (this.resources.wood > 0) { + randomWood = this.getRandomElement(possibleAmountsForQuest); + rewardSum += (randomWood * 5); + } + + if (this.resources.stone > 0) { + randomStone = this.getRandomElement(possibleAmountsForQuest); + rewardSum += (randomStone * 7); + } + + if (this.resources.iron > 0) { + randomIron = this.getRandomElement(possibleAmountsForQuest); + rewardSum += (randomIron * 15); + } + + if (this.resources.bricks > 0) { + randomBricks = this.getRandomElement(possibleAmountsForQuest); + rewardSum += (randomBricks * 25); + } + + if (this.resources.corn > 0) { + randomCorn = this.getRandomElement(possibleAmountsForQuest); + rewardSum += (randomCorn * 30); + } + + if (rewardSum > 0) { + this.currentQuest = { + wood: randomWood, + stone: randomStone, + iron: randomIron, + bricks: randomBricks, + corn: randomCorn, + reward: rewardSum + }; + } else { + this.currentQuest = null; + } + + return this.currentQuest; + }, + + getRandomElement(possibleValues) { + return possibleValues[Math.floor(Math.random() * possibleValues.length)]; + }, + + 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 + ); } }, });