Browse Source

save stuff, fix stuff

master
neroignis@gmail.com 4 years ago
parent
commit
9fda713068
  1. 4
      index.html
  2. 41
      js/app.js

4
index.html

@ -85,10 +85,10 @@
<span v-if="currentQuest.bricks > 0"><img class="resource-icon" src="img/bricks.png"> {{ currentQuest.bricks }}</span> <span v-if="currentQuest.bricks > 0"><img class="resource-icon" src="img/bricks.png"> {{ currentQuest.bricks }}</span>
<br/> <br/>
<br/> <br/>
<a href="javascript:" class="btn btn-sm btn-success" :disabled="isQuestRedeemable()">Redeem reward ({{ currentQuest.reward }} <img class="resource-icon" src="img/gold.png">)</a> <a href="javascript:" class="btn btn-sm btn-success" @click="redeemReward()">Redeem reward ({{ currentQuest.reward }} <img class="resource-icon" src="img/gold.png">)</a>
</div> </div>
<div v-else> <div v-else>
<a @click="generateQuest()">Get Quest (resources needed)</a> <a class="btn btn-sm btn-info" @click="generateQuest()">Get Quest (resources needed)</a>
</div> </div>
</div> </div>
</div> </div>

41
js/app.js

@ -3,8 +3,8 @@ let game = new Vue({
data: { data: {
money: 0, money: 0,
resources: { resources: {
wood: 2, wood: 50,
stone: 2, stone: 0,
iron: 0, iron: 0,
bricks: 0, bricks: 0,
corn: 0 corn: 0
@ -77,7 +77,9 @@ let game = new Vue({
created() { created() {
this.money = this.getSavedMoney(); this.money = this.getSavedMoney();
this.saveMoney(); this.saveMoney();
this.loadResources();
this.loadBuildings();
this.reloadBuildings(); this.reloadBuildings();
}, },
methods: { methods: {
@ -107,6 +109,7 @@ let game = new Vue({
break; break;
} }
this.saveResources();
return this.saveMoney(); return this.saveMoney();
}, },
@ -225,15 +228,28 @@ let game = new Vue({
loadBuildings: function () { loadBuildings: function () {
let savedBuildings = JSON.parse(localStorage.getItem('buildings')); let savedBuildings = JSON.parse(localStorage.getItem('buildings'));
if (savedBuildings.length > 0) { if (savedBuildings) {
this.buildings = 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() { generateQuest() {
let possibleAmountsForQuest = [ let possibleAmountsForQuest = [
0, 5, 10, 15, 20, 25, 30, 35 0, 5, 10, 15, 20, 25, 30, 35
]; ];
let randomWood = 0; let randomWood = 0;
let randomStone = 0; let randomStone = 0;
let randomIron = 0; let randomIron = 0;
@ -289,22 +305,27 @@ let game = new Vue({
isQuestRedeemable() { isQuestRedeemable() {
return ( return (
this.wood >= this.currentQuest.wood && this.resources.wood >= this.currentQuest.wood &&
this.stone >= this.currentQuest.stone && this.resources.stone >= this.currentQuest.stone &&
this.iron >= this.currentQuest.iron && this.resources.iron >= this.currentQuest.iron &&
this.bricks >= this.currentQuest.bricks && this.resources.bricks >= this.currentQuest.bricks &&
this.corn >= this.currentQuest.corn this.resources.corn >= this.currentQuest.corn
); );
}, },
redeemQuest() { redeemReward() {
if (this.isQuestRedeemable()) { if (this.isQuestRedeemable()) {
this.money += this.currentQuest.reward; 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(); this.generateQuest();
} else { } else {
return false; return false;
} }
} }
}, },
}); });

Loading…
Cancel
Save