|
|
|
@ -2,12 +2,15 @@ let game = new Vue({
@@ -2,12 +2,15 @@ let game = new Vue({
|
|
|
|
|
el: '#root', |
|
|
|
|
data: { |
|
|
|
|
money: 0, |
|
|
|
|
loaded: false, |
|
|
|
|
resources: { |
|
|
|
|
wood: 50, |
|
|
|
|
stone: 0, |
|
|
|
|
iron: 0, |
|
|
|
|
bricks: 0, |
|
|
|
|
corn: 0 |
|
|
|
|
corn: 0, |
|
|
|
|
coal: 0, |
|
|
|
|
planks: 0 |
|
|
|
|
}, |
|
|
|
|
buildings: [ |
|
|
|
|
{ |
|
|
|
@ -40,6 +43,25 @@ let game = new Vue({
@@ -40,6 +43,25 @@ let game = new Vue({
|
|
|
|
|
price: 100, |
|
|
|
|
priceMultiplicator: 2 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'Carpenter', |
|
|
|
|
resource: 'planks', |
|
|
|
|
icon: 'medieval_lumber', |
|
|
|
|
level: 0, |
|
|
|
|
maxLevel: 15, |
|
|
|
|
isOwned: false, |
|
|
|
|
isUpgradeable: true, |
|
|
|
|
amount: 5, |
|
|
|
|
amountMultiplicator: 1, |
|
|
|
|
intervalInSeconds: 25, |
|
|
|
|
intervalMultiplicator: 0.80, |
|
|
|
|
price: 15000, |
|
|
|
|
priceMultiplicator: 2, |
|
|
|
|
hasRequirements: true, |
|
|
|
|
requires: { |
|
|
|
|
wood: 2 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'Quarry', |
|
|
|
|
resource: 'stone', |
|
|
|
@ -55,6 +77,41 @@ let game = new Vue({
@@ -55,6 +77,41 @@ let game = new Vue({
|
|
|
|
|
price: 250, |
|
|
|
|
priceMultiplicator: 2 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'Coal Mine', |
|
|
|
|
resource: 'coal', |
|
|
|
|
icon: 'medieval_mine', |
|
|
|
|
level: 0, |
|
|
|
|
maxLevel: 15, |
|
|
|
|
isOwned: false, |
|
|
|
|
isUpgradeable: true, |
|
|
|
|
amount: 2, |
|
|
|
|
amountMultiplicator: 1, |
|
|
|
|
intervalInSeconds: 20, |
|
|
|
|
intervalMultiplicator: 0.95, |
|
|
|
|
price: 600, |
|
|
|
|
priceMultiplicator: 2 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'Blacksmith', |
|
|
|
|
resource: 'iron', |
|
|
|
|
icon: 'medieval_blacksmith', |
|
|
|
|
level: 0, |
|
|
|
|
maxLevel: 15, |
|
|
|
|
isOwned: false, |
|
|
|
|
isUpgradeable: true, |
|
|
|
|
amount: 2, |
|
|
|
|
amountMultiplicator: 3, |
|
|
|
|
intervalInSeconds: 20, |
|
|
|
|
intervalMultiplicator: 0.95, |
|
|
|
|
price: 1000, |
|
|
|
|
priceMultiplicator: 2.5, |
|
|
|
|
hasRequirements: true, |
|
|
|
|
requires: { |
|
|
|
|
stone: 2, |
|
|
|
|
coal: 1 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'Farm', |
|
|
|
|
resource: 'corn', |
|
|
|
@ -81,6 +138,7 @@ let game = new Vue({
@@ -81,6 +138,7 @@ let game = new Vue({
|
|
|
|
|
|
|
|
|
|
this.loadBuildings(); |
|
|
|
|
this.reloadBuildings(); |
|
|
|
|
this.loaded = true; |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
saveMoney() { |
|
|
|
@ -101,9 +159,18 @@ let game = new Vue({
@@ -101,9 +159,18 @@ let game = new Vue({
|
|
|
|
|
case 'stone': |
|
|
|
|
this.resources.stone += amount; |
|
|
|
|
break; |
|
|
|
|
case 'bricks': |
|
|
|
|
this.resources.bricks += amount; |
|
|
|
|
break; |
|
|
|
|
case 'corn': |
|
|
|
|
this.resources.corn += amount; |
|
|
|
|
break; |
|
|
|
|
case 'coal': |
|
|
|
|
this.resources.coal += amount; |
|
|
|
|
break; |
|
|
|
|
case 'planks': |
|
|
|
|
this.resources.planks += amount; |
|
|
|
|
break; |
|
|
|
|
case 'gold': |
|
|
|
|
this.money += amount; |
|
|
|
|
break; |
|
|
|
@ -127,8 +194,6 @@ let game = new Vue({
@@ -127,8 +194,6 @@ let game = new Vue({
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
reloadBuildings() { |
|
|
|
|
this.killIntervals(); |
|
|
|
|
|
|
|
|
|
let game = this; |
|
|
|
|
this.buildings.forEach((building) => { |
|
|
|
|
if (building.isOwned) { |
|
|
|
@ -139,7 +204,26 @@ let game = new Vue({
@@ -139,7 +204,26 @@ let game = new Vue({
|
|
|
|
|
|
|
|
|
|
initiateIntervals(building) { |
|
|
|
|
building.intervalEarnID = setInterval(() => { |
|
|
|
|
game.add(building.amount, building.resource); |
|
|
|
|
if (building.requires) { |
|
|
|
|
if ( |
|
|
|
|
building.requires.wood > game.resources.wood || |
|
|
|
|
building.requires.stone > game.resources.stone || |
|
|
|
|
building.requires.iron > game.resources.iron || |
|
|
|
|
building.requires.bricks > game.resources.bricks || |
|
|
|
|
building.requires.coal > game.resources.coal || |
|
|
|
|
building.requires.corn > game.resources.corn |
|
|
|
|
) { |
|
|
|
|
building.hasMissingResources = true; |
|
|
|
|
clearInterval(building.intervalLoadingID); |
|
|
|
|
} else { |
|
|
|
|
building.hasMissingResources = false; |
|
|
|
|
game.useRequiredResources(building); |
|
|
|
|
game.add(building.amount, building.resource); |
|
|
|
|
game.reloadSingleBuilding(building); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
game.add(building.amount, building.resource); |
|
|
|
|
} |
|
|
|
|
}, building.intervalInSeconds * 1000); |
|
|
|
|
|
|
|
|
|
building.intervalLoadingID = setInterval(() => { |
|
|
|
@ -156,16 +240,6 @@ let game = new Vue({
@@ -156,16 +240,6 @@ let game = new Vue({
|
|
|
|
|
this.loadedIntervals.push(building.intervalEarnID, building.intervalLoadingID); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
killIntervals() { |
|
|
|
|
this.buildings.forEach((building) => { |
|
|
|
|
building.loader = 0; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.loadedIntervals.forEach((interval) => { |
|
|
|
|
clearInterval(interval) |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
buyBuilding(building) { |
|
|
|
|
if (this.money >= building.price) { |
|
|
|
|
this.sub(building.price); |
|
|
|
@ -193,8 +267,6 @@ let game = new Vue({
@@ -193,8 +267,6 @@ let game = new Vue({
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
upgradeBuilding(building, first = false) { |
|
|
|
|
// this.killIntervals();
|
|
|
|
|
|
|
|
|
|
if (building.level < (building.maxLevel - 1)) { |
|
|
|
|
building.level++; |
|
|
|
|
} else { |
|
|
|
@ -202,13 +274,15 @@ let game = new Vue({
@@ -202,13 +274,15 @@ let game = new Vue({
|
|
|
|
|
building.isUpgradeable = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
building.price = Number(building.price * building.priceMultiplicator).toFixed(2); |
|
|
|
|
building.price = Number( |
|
|
|
|
building.price * building.priceMultiplicator |
|
|
|
|
).toFixed(2); |
|
|
|
|
|
|
|
|
|
if (first === false) { |
|
|
|
|
building.amount = building.amount * building.amountMultiplicator; |
|
|
|
|
building.intervalInSeconds = Number(building.intervalInSeconds * building.intervalMultiplicator).toFixed(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// this.reloadBuildings();
|
|
|
|
|
this.reloadSingleBuilding(building); |
|
|
|
|
this.saveBuildings(); |
|
|
|
|
}, |
|
|
|
@ -247,7 +321,7 @@ let game = new Vue({
@@ -247,7 +321,7 @@ let game = new Vue({
|
|
|
|
|
|
|
|
|
|
generateQuest() { |
|
|
|
|
let possibleAmountsForQuest = [ |
|
|
|
|
0, 5, 10, 15, 20, 25, 30, 35 |
|
|
|
|
0, 0, 0, 5, 10, 15, 20, 25, 30, 35 |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
let randomWood = 0; |
|
|
|
@ -255,6 +329,9 @@ let game = new Vue({
@@ -255,6 +329,9 @@ let game = new Vue({
|
|
|
|
|
let randomIron = 0; |
|
|
|
|
let randomBricks = 0; |
|
|
|
|
let randomCorn = 0; |
|
|
|
|
let randomCoal = 0; |
|
|
|
|
let randomPlanks = 0; |
|
|
|
|
|
|
|
|
|
let rewardSum = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -270,7 +347,7 @@ let game = new Vue({
@@ -270,7 +347,7 @@ let game = new Vue({
|
|
|
|
|
|
|
|
|
|
if (this.resources.iron > 0) { |
|
|
|
|
randomIron = this.getRandomElement(possibleAmountsForQuest); |
|
|
|
|
rewardSum += (randomIron * 15); |
|
|
|
|
rewardSum += (randomIron * 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.resources.bricks > 0) { |
|
|
|
@ -283,6 +360,16 @@ let game = new Vue({
@@ -283,6 +360,16 @@ let game = new Vue({
|
|
|
|
|
rewardSum += (randomCorn * 30); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.resources.coal > 0) { |
|
|
|
|
randomCoal = this.getRandomElement(possibleAmountsForQuest); |
|
|
|
|
rewardSum += (randomCoal * 10); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.resources.planks > 0) { |
|
|
|
|
randomPlanks = this.getRandomElement(possibleAmountsForQuest); |
|
|
|
|
rewardSum += (randomPlanks * 5); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (rewardSum > 0) { |
|
|
|
|
this.currentQuest = { |
|
|
|
|
wood: randomWood, |
|
|
|
@ -290,6 +377,8 @@ let game = new Vue({
@@ -290,6 +377,8 @@ let game = new Vue({
|
|
|
|
|
iron: randomIron, |
|
|
|
|
bricks: randomBricks, |
|
|
|
|
corn: randomCorn, |
|
|
|
|
coal: randomCoal, |
|
|
|
|
planks: randomPlanks, |
|
|
|
|
reward: rewardSum |
|
|
|
|
}; |
|
|
|
|
} else { |
|
|
|
@ -309,7 +398,8 @@ let game = new Vue({
@@ -309,7 +398,8 @@ let game = new Vue({
|
|
|
|
|
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.resources.corn >= this.currentQuest.corn && |
|
|
|
|
this.resources.coal >= this.currentQuest.coal |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
@ -321,11 +411,51 @@ let game = new Vue({
@@ -321,11 +411,51 @@ let game = new Vue({
|
|
|
|
|
this.resources.iron -= this.currentQuest.iron; |
|
|
|
|
this.resources.bricks -= this.currentQuest.bricks; |
|
|
|
|
this.resources.corn -= this.currentQuest.corn; |
|
|
|
|
this.resources.coal -= this.currentQuest.coal; |
|
|
|
|
|
|
|
|
|
this.generateQuest(); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
useRequiredResources(building) { |
|
|
|
|
this.resources.wood -= building.requires.wood; |
|
|
|
|
this.resources.stone -= building.requires.stone; |
|
|
|
|
this.resources.iron -= building.requires.iron; |
|
|
|
|
this.resources.bricks -= building.requires.bricks; |
|
|
|
|
this.resources.corn -= building.requires.corn; |
|
|
|
|
this.resources.coal -= building.requires.coal; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getResourceIconForBuilding(building) { |
|
|
|
|
return this.getResourceIcon(building.resource); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getResourceIcon(resource) { |
|
|
|
|
return '<img class="resource-icon" src="img/' + resource + '.png" title="' + resource + '" alt="' + resource + '">'; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getRequirementsForProduction(building) { |
|
|
|
|
let requirementList = '<br/>Uses'; |
|
|
|
|
|
|
|
|
|
if (building.requires.wood) { |
|
|
|
|
requirementList += ' ' + building.requires.wood + ' ' + this.getResourceIcon('wood'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (building.requires.stone) { |
|
|
|
|
requirementList += ' ' + building.requires.stone + ' ' + this.getResourceIcon('stone'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (building.requires.coal) { |
|
|
|
|
requirementList += ' ' + building.requires.coal + ' ' + this.getResourceIcon('coal'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (building.requires.iron) { |
|
|
|
|
requirementList += ' ' + building.requires.iron + ' ' + this.getResourceIcon('iron'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return requirementList + ' / ' + building.amount + ' ' + this.getResourceIconForBuilding(building); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|