Browse Source

allow to build buildings in planet

master
arnaucube 5 years ago
parent
commit
ba3c9b374b
25 changed files with 268 additions and 99 deletions
  1. +1
    -0
      .gitignore
  2. +44
    -28
      buildings.js
  3. +53
    -53
      calc.js
  4. BIN
      images/buildings/alliancedepot.png
  5. BIN
      images/buildings/crystalmine.png
  6. BIN
      images/buildings/crystalstorage.png
  7. BIN
      images/buildings/deuteriummine.png
  8. BIN
      images/buildings/deuteriumstorage.png
  9. BIN
      images/buildings/fusionreactor.png
  10. BIN
      images/buildings/metalmine.png
  11. BIN
      images/buildings/metalstorage.png
  12. BIN
      images/buildings/missilesilo.png
  13. BIN
      images/buildings/ressearchlab.png
  14. BIN
      images/buildings/roboticsfactory.png
  15. BIN
      images/buildings/shipyard.png
  16. BIN
      images/buildings/solarmine.png
  17. BIN
      images/buildings/spacedock.png
  18. BIN
      images/crystal.png
  19. BIN
      images/deuterium.png
  20. BIN
      images/energy.png
  21. BIN
      images/metal.png
  22. +61
    -0
      package-lock.json
  23. +15
    -0
      package.json
  24. +72
    -0
      test/calc.test.js
  25. +22
    -18
      user.js

+ 1
- 0
.gitignore

@ -0,0 +1 @@
node_modules

+ 44
- 28
buildings.js

@ -34,11 +34,11 @@ function printPlanet(planet) {
// metalmine // metalmine
document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")"; document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")";
if (planet.Buildings.metalmine == undefined) { if (planet.Buildings.metalmine == undefined) {
document.getElementById("btnBuildMetalMine").innerHTML = "Build building";
document.getElementById("btnBuildMetalMine").innerHTML = `<div onclick="buildBuilding('metalmine')">Build building</div>`;
r = metalmineCost(1); r = metalmineCost(1);
document.getElementById("metalmineResources").innerHTML = printResources(r); document.getElementById("metalmineResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildMetalMine").innerHTML = "Build level " + (+ (planet.Buildings.metalmine) + + (1));
document.getElementById("btnBuildMetalMine").innerHTML = `<div onclick="buildBuilding('metalmine')">Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `</div>`;
r = metalmineCost((+ (planet.Buildings.metalmine) + + (1))); r = metalmineCost((+ (planet.Buildings.metalmine) + + (1)));
document.getElementById("metalmineResources").innerHTML = printResources(r); document.getElementById("metalmineResources").innerHTML = printResources(r);
} }
@ -46,11 +46,11 @@ function printPlanet(planet) {
// crystalmine // crystalmine
document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")"; document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")";
if (planet.Buildings.crystalmine == undefined) { if (planet.Buildings.crystalmine == undefined) {
document.getElementById("btnBuildCrystalMine").innerHTML = "Build building";
document.getElementById("btnBuildCrystalMine").innerHTML = `<div onclick="buildBuilding('crystalmine')">Build building</div>`;
r = crystalmineCost(1); r = crystalmineCost(1);
document.getElementById("crystalmineResources").innerHTML = printResources(r); document.getElementById("crystalmineResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildCrystalMine").innerHTML = "Build level " + (+ (planet.Buildings.crystalmine) + + (1));
document.getElementById("btnBuildCrystalMine").innerHTML = `<div onclick="buildBuilding('crystalmine')">Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `</div>`;
r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1))); r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1)));
document.getElementById("crystalmineResources").innerHTML = printResources(r); document.getElementById("crystalmineResources").innerHTML = printResources(r);
} }
@ -58,11 +58,11 @@ function printPlanet(planet) {
// deuteriummine // deuteriummine
document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")"; document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")";
if (planet.Buildings.deuteriummine == undefined) { if (planet.Buildings.deuteriummine == undefined) {
document.getElementById("btnBuildDeuteriumMine").innerHTML = "Build building";
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div onclick="buildBuilding('deuteriummine')">Build building</div>`;
r = deuteriummineCost(1); r = deuteriummineCost(1);
document.getElementById("deuteriummineResources").innerHTML = printResources(r); document.getElementById("deuteriummineResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildDeuteriumMine").innerHTML = "Build level " + (+ (planet.Buildings.deuteriummine) + + (1));
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div onclick="buildBuilding('deuteriummine')">Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `</div>`;
r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1))); r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1)));
document.getElementById("deuteriummineResources").innerHTML = printResources(r); document.getElementById("deuteriummineResources").innerHTML = printResources(r);
} }
@ -70,11 +70,11 @@ function printPlanet(planet) {
// energymine // energymine
document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")"; document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")";
if (planet.Buildings.energymine == undefined) { if (planet.Buildings.energymine == undefined) {
document.getElementById("btnBuildEnergyMine").innerHTML = "Build building";
document.getElementById("btnBuildEnergyMine").innerHTML = `<div onclick="buildBuilding('energymine')">Build building</div>`;
r = energymineCost(1); r = energymineCost(1);
document.getElementById("energymineResources").innerHTML = printResources(r); document.getElementById("energymineResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildEnergyMine").innerHTML = "Build level " + (+ (planet.Buildings.energymine) + + (1));
document.getElementById("btnBuildEnergyMine").innerHTML = `<div onclick="buildBuilding('energymine')">Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `</div>`;
r = energymineCost((+ (planet.Buildings.energymine) + + (1))); r = energymineCost((+ (planet.Buildings.energymine) + + (1)));
document.getElementById("energymineResources").innerHTML = printResources(r); document.getElementById("energymineResources").innerHTML = printResources(r);
} }
@ -82,11 +82,11 @@ function printPlanet(planet) {
// fusionreactor // fusionreactor
document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")"; document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")";
if (planet.Buildings.fusionreactor == undefined) { if (planet.Buildings.fusionreactor == undefined) {
document.getElementById("btnBuildFusionReactor").innerHTML = "Build building";
document.getElementById("btnBuildFusionReactor").innerHTML = `<div onclick="buildBuilding('fusionreactor')">Build building</div>`;
r = fusionreactorCost(1); r = fusionreactorCost(1);
document.getElementById("fusionreactorResources").innerHTML = printResources(r); document.getElementById("fusionreactorResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildFusionReactor").innerHTML = "Build level " + (+ (planet.Buildings.fusionreactor) + + (1));
document.getElementById("btnBuildFusionReactor").innerHTML = `<div onclick="buildBuilding('fusionreactor')">Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `</div>`;
r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1))); r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1)));
document.getElementById("fusionreactorResources").innerHTML = printResources(r); document.getElementById("fusionreactorResources").innerHTML = printResources(r);
} }
@ -94,11 +94,11 @@ function printPlanet(planet) {
// roboticsfactory // roboticsfactory
document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")"; document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")";
if (planet.Buildings.roboticsfactory == undefined) { if (planet.Buildings.roboticsfactory == undefined) {
document.getElementById("btnBuildRoboticsFactory").innerHTML = "Build building";
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div onclick="buildBuilding('roboticsfactory')">Build building</div>`;
r = roboticsfactoryCost(1); r = roboticsfactoryCost(1);
document.getElementById("roboticsfactoryResources").innerHTML = printResources(r); document.getElementById("roboticsfactoryResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildRoboticsFactory").innerHTML = "Build level " + (+ (planet.Buildings.roboticsfactory) + + (1));
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div onclick="buildBuilding('roboticsfactory')">Build level ` + (+ (planet.Buildings.roboticsfactory) + + (1)) + `</div>`;
r = roboticsfactoryCost((+ (planet.Buildings.roboticsfactory) + + (1))); r = roboticsfactoryCost((+ (planet.Buildings.roboticsfactory) + + (1)));
document.getElementById("roboticsfactoryResources").innerHTML = printResources(r); document.getElementById("roboticsfactoryResources").innerHTML = printResources(r);
} }
@ -106,11 +106,11 @@ function printPlanet(planet) {
// shipyard // shipyard
document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")"; document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")";
if (planet.Buildings.shipyard == undefined) { if (planet.Buildings.shipyard == undefined) {
document.getElementById("btnBuildShipyard").innerHTML = "Build building";
document.getElementById("btnBuildShipyard").innerHTML = `<div onclick="buildBuilding('shipyard')">Build building</div>`;
r = shipyardCost(1); r = shipyardCost(1);
document.getElementById("shipyardResources").innerHTML = printResources(r); document.getElementById("shipyardResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildShipyard").innerHTML = "Build level " + (+ (planet.Buildings.shipyard) + + (1));
document.getElementById("btnBuildShipyard").innerHTML = `<div onclick="buildBuilding('shipyard')">Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `</div>`;
r = shipyardCost((+ (planet.Buildings.shipyard) + + (1))); r = shipyardCost((+ (planet.Buildings.shipyard) + + (1)));
document.getElementById("shipyardResources").innerHTML = printResources(r); document.getElementById("shipyardResources").innerHTML = printResources(r);
} }
@ -118,11 +118,11 @@ function printPlanet(planet) {
// metalstorage // metalstorage
document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")"; document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")";
if (planet.Buildings.metalstorage == undefined) { if (planet.Buildings.metalstorage == undefined) {
document.getElementById("btnBuildMetalStorage").innerHTML = "Build building";
document.getElementById("btnBuildMetalStorage").innerHTML = `<div onclick="buildBuilding('metalstorage')">Build building</div>`;
r = metalstorageCost(1); r = metalstorageCost(1);
document.getElementById("metalstorageResources").innerHTML = printResources(r); document.getElementById("metalstorageResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildMetalStorage").innerHTML = "Build level " + (+ (planet.Buildings.metalstorage) + + (1));
document.getElementById("btnBuildMetalStorage").innerHTML = `<div onclick="buildBuilding('metalstorage')">Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `</div>`;
r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1))); r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1)));
document.getElementById("metalstorageResources").innerHTML = printResources(r); document.getElementById("metalstorageResources").innerHTML = printResources(r);
} }
@ -130,11 +130,11 @@ function printPlanet(planet) {
// crystalstorage // crystalstorage
document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")"; document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")";
if (planet.Buildings.crystalstorage == undefined) { if (planet.Buildings.crystalstorage == undefined) {
document.getElementById("btnBuildCrystalStorage").innerHTML = "Build building";
document.getElementById("btnBuildCrystalStorage").innerHTML = `<div onclick="buildBuilding('crystalstorage')">Build building</div>`;
r = crystalstorageCost(1); r = crystalstorageCost(1);
document.getElementById("crystalstorageResources").innerHTML = printResources(r); document.getElementById("crystalstorageResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildCrystalStorage").innerHTML = "Build level " + (+ (planet.Buildings.crystalstorage) + + (1));
document.getElementById("btnBuildCrystalStorage").innerHTML = `<div onclick="buildBuilding('crystalstorage')">Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `</div>`;
r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1))); r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1)));
document.getElementById("crystalstorageResources").innerHTML = printResources(r); document.getElementById("crystalstorageResources").innerHTML = printResources(r);
} }
@ -142,11 +142,11 @@ function printPlanet(planet) {
// deuteriumstorage // deuteriumstorage
document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")"; document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")";
if (planet.Buildings.deuteriumstorage == undefined) { if (planet.Buildings.deuteriumstorage == undefined) {
document.getElementById("btnBuildDeuteriumStorage").innerHTML = "Build building";
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div onclick="buildBuilding('deuteriumstorage')">Build building</div>`;
r = deuteriumstorageCost(1); r = deuteriumstorageCost(1);
document.getElementById("deuteriumstorageResources").innerHTML = printResources(r); document.getElementById("deuteriumstorageResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildDeuteriumStorage").innerHTML = "Build level " + (+ (planet.Buildings.deuteriumstorage) + + (1));
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div onclick="buildBuilding('deuteriumstorage')">Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `</div>`;
r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1))); r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1)));
document.getElementById("deuteriumstorageResources").innerHTML = printResources(r); document.getElementById("deuteriumstorageResources").innerHTML = printResources(r);
} }
@ -154,11 +154,11 @@ function printPlanet(planet) {
// ressearchlab // ressearchlab
document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")"; document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")";
if (planet.Buildings.ressearchlab == undefined) { if (planet.Buildings.ressearchlab == undefined) {
document.getElementById("btnBuildRessearchLab").innerHTML = "Build building";
document.getElementById("btnBuildRessearchLab").innerHTML = `<div onclick="buildBuilding('ressearchlab')">Build building</div>`;
r = ressearchlabCost(1); r = ressearchlabCost(1);
document.getElementById("ressearchlabResources").innerHTML = printResources(r); document.getElementById("ressearchlabResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildRessearchLab").innerHTML = "Build level " + (+ (planet.Buildings.ressearchlab) + + (1));
document.getElementById("btnBuildRessearchLab").innerHTML = `<div onclick="buildBuilding('ressearchlab')">Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `</div>`;
r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1))); r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1)));
document.getElementById("ressearchlabResources").innerHTML = printResources(r); document.getElementById("ressearchlabResources").innerHTML = printResources(r);
} }
@ -166,11 +166,11 @@ function printPlanet(planet) {
// alliancedepot // alliancedepot
document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")"; document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")";
if (planet.Buildings.alliancedepot == undefined) { if (planet.Buildings.alliancedepot == undefined) {
document.getElementById("btnBuildAllianceDepot").innerHTML = "Build building";
document.getElementById("btnBuildAllianceDepot").innerHTML = `<div onclick="buildBuilding('alliancedepot')">Build building</div>`;
r = alliancedepotCost(1); r = alliancedepotCost(1);
document.getElementById("alliancedepotResources").innerHTML = printResources(r); document.getElementById("alliancedepotResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildAllianceDepot").innerHTML = "Build level " + (+ (planet.Buildings.alliancedepot) + + (1));
document.getElementById("btnBuildAllianceDepot").innerHTML = `<div onclick="buildBuilding('alliancedepot')">Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `</div>`;
r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1))); r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1)));
document.getElementById("alliancedepotResources").innerHTML = printResources(r); document.getElementById("alliancedepotResources").innerHTML = printResources(r);
} }
@ -178,11 +178,11 @@ function printPlanet(planet) {
// missilesilo // missilesilo
document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")"; document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")";
if (planet.Buildings.missilesilo == undefined) { if (planet.Buildings.missilesilo == undefined) {
document.getElementById("btnBuildMissileSilo").innerHTML = "Build building";
document.getElementById("btnBuildMissileSilo").innerHTML = `<div onclick="buildBuilding('missilesilo')">Build building</div>`;
r = missilesiloCost(1); r = missilesiloCost(1);
document.getElementById("missilesiloResources").innerHTML = printResources(r); document.getElementById("missilesiloResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildMissileSilo").innerHTML = "Build level " + (+ (planet.Buildings.missilesilo) + + (1));
document.getElementById("btnBuildMissileSilo").innerHTML = `<div onclick="buildBuilding('missilesilo')">Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `</div>`;
r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1))); r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1)));
document.getElementById("missilesiloResources").innerHTML = printResources(r); document.getElementById("missilesiloResources").innerHTML = printResources(r);
} }
@ -190,11 +190,11 @@ function printPlanet(planet) {
// spacedock // spacedock
document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")"; document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")";
if (planet.Buildings.spacedock == undefined) { if (planet.Buildings.spacedock == undefined) {
document.getElementById("btnBuildSpacedock").innerHTML = "Build building";
document.getElementById("btnBuildSpacedock").innerHTML = `<div onclick="buildBuilding('spacedock')">Build building</div>`;
r = spacedockCost(1); r = spacedockCost(1);
document.getElementById("spacedockResources").innerHTML = printResources(r); document.getElementById("spacedockResources").innerHTML = printResources(r);
} else { } else {
document.getElementById("btnBuildSpacedock").innerHTML = "Build level " + (+ (planet.Buildings.spacedock) + + (1));
document.getElementById("btnBuildSpacedock").innerHTML = `<div onclick="buildBuilding('spacedock')">Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `</div>`;
r = spacedockCost((+ (planet.Buildings.spacedock) + + (1))); r = spacedockCost((+ (planet.Buildings.spacedock) + + (1)));
document.getElementById("spacedockResources").innerHTML = printResources(r); document.getElementById("spacedockResources").innerHTML = printResources(r);
} }
@ -210,3 +210,19 @@ axios.get(url + "/planets/" + planetid, config).then(function(res) {
}).catch(function(error) { }).catch(function(error) {
console.log(error); console.log(error);
}); });
function buildBuilding(building) {
console.log("build " + building);
const data = {
planetid: planetid,
building: building
}
axios.post(url + "/buildings", data, config).then(function(res) {
console.log("buildings", res.data);
planet = res.data.planet;
printPlanet(planet);
}).catch(function(error) {
console.log(error);
});
}

+ 53
- 53
calc.js

@ -7,10 +7,10 @@ function metalmineCost(lvl) {
}; };
// cost = base * 1.5^(lvl-1) // cost = base * 1.5^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.round(base.Energy * 1.5**(lvl-1));
cost.Metal = Math.floor(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.floor(base.Energy * 1.5**(lvl-1));
return cost; return cost;
} }
function crystalmineCost(lvl) { function crystalmineCost(lvl) {
@ -22,10 +22,10 @@ function crystalmineCost(lvl) {
}; };
// cost = base * 1.6^(lvl-1) // cost = base * 1.6^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 1.6**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 1.6**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 1.6**(lvl-1));
cost.Energy = Math.round(base.Energy * 1.6**(lvl-1));
cost.Metal = Math.floor(base.Metal * 1.6**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 1.6**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 1.6**(lvl-1));
cost.Energy = Math.floor(base.Energy * 1.6**(lvl-1));
return cost; return cost;
} }
function deuteriummineCost(lvl) { function deuteriummineCost(lvl) {
@ -37,10 +37,10 @@ function deuteriummineCost(lvl) {
}; };
// cost = base * 1.5^(lvl-1) // cost = base * 1.5^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.round(base.Energy * 1.5**(lvl-1));
cost.Metal = Math.floor(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.floor(base.Energy * 1.5**(lvl-1));
return cost; return cost;
} }
function energymineCost(lvl) { function energymineCost(lvl) {
@ -52,10 +52,10 @@ function energymineCost(lvl) {
}; };
// cost = base * 1.5^(lvl-1) // cost = base * 1.5^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.round(base.Energy * 1.5**(lvl-1));
cost.Metal = Math.floor(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.floor(base.Energy * 1.5**(lvl-1));
return cost; return cost;
} }
function fusionreactorCost(lvl) { function fusionreactorCost(lvl) {
@ -67,10 +67,10 @@ function fusionreactorCost(lvl) {
}; };
// cost = base * 1.8^(lvl-1) // cost = base * 1.8^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 1.8**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 1.8**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 1.8**(lvl-1));
cost.Energy = Math.round(base.Energy * 1.8**(lvl-1));
cost.Metal = Math.floor(base.Metal * 1.8**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 1.8**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 1.8**(lvl-1));
cost.Energy = Math.floor(base.Energy * 1.8**(lvl-1));
return cost; return cost;
} }
function roboticsfactoryCost(lvl) { function roboticsfactoryCost(lvl) {
@ -82,10 +82,10 @@ function roboticsfactoryCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.round(base.Energy * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }
function shipyardCost(lvl) { function shipyardCost(lvl) {
@ -97,10 +97,10 @@ function shipyardCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.round(base.Energy * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }
function metalstorageCost(lvl) { function metalstorageCost(lvl) {
@ -112,7 +112,7 @@ function metalstorageCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = 0; cost.Crystal = 0;
cost.Deuterium = 0; cost.Deuterium = 0;
cost.Energy = 0; cost.Energy = 0;
@ -127,10 +127,10 @@ function crystalstorageCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.round(base.Energy * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }
function deuteriumstorageCost(lvl) { function deuteriumstorageCost(lvl) {
@ -142,10 +142,10 @@ function deuteriumstorageCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.round(base.Energy * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }
function ressearchlabCost(lvl) { function ressearchlabCost(lvl) {
@ -157,10 +157,10 @@ function ressearchlabCost(lvl) {
}; };
// cost = base * 1.5^(lvl-1) // cost = base * 1.5^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.round(base.Energy * 1.5**(lvl-1));
cost.Metal = Math.floor(base.Metal * 1.5**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 1.5**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 1.5**(lvl-1));
cost.Energy = Math.floor(base.Energy * 1.5**(lvl-1));
return cost; return cost;
} }
@ -173,10 +173,10 @@ function alliancedepotCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.round(base.Energy * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }
function missilesiloCost(lvl) { function missilesiloCost(lvl) {
@ -188,10 +188,10 @@ function missilesiloCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.round(base.Energy * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }
function spacedockCost(lvl) { function spacedockCost(lvl) {
@ -203,9 +203,9 @@ function spacedockCost(lvl) {
}; };
// cost = base * 2^(lvl-1) // cost = base * 2^(lvl-1)
let cost = {}; let cost = {};
cost.Metal = Math.round(base.Metal * 2**(lvl-1));
cost.Crystal = Math.round(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.round(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.round(base.Energy * 2**(lvl-1));
cost.Metal = Math.floor(base.Metal * 2**(lvl-1));
cost.Crystal = Math.floor(base.Crystal * 2**(lvl-1));
cost.Deuterium = Math.floor(base.Deuterium * 2**(lvl-1));
cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }

BIN
images/buildings/alliancedepot.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.4 KiB

BIN
images/buildings/crystalmine.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.2 KiB

BIN
images/buildings/crystalstorage.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.7 KiB

BIN
images/buildings/deuteriummine.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.0 KiB

BIN
images/buildings/deuteriumstorage.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.8 KiB

BIN
images/buildings/fusionreactor.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.4 KiB

BIN
images/buildings/metalmine.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 1.6 KiB

BIN
images/buildings/metalstorage.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.5 KiB

BIN
images/buildings/missilesilo.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 1.8 KiB

BIN
images/buildings/ressearchlab.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.0 KiB

BIN
images/buildings/roboticsfactory.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.1 KiB

BIN
images/buildings/shipyard.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 1.8 KiB

BIN
images/buildings/solarmine.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 1.9 KiB

BIN
images/buildings/spacedock.png

Before After
Width: 120  |  Height: 120  |  Size: 313 B Width: 120  |  Height: 120  |  Size: 2.3 KiB

BIN
images/crystal.png

Before After
Width: 42  |  Height: 22  |  Size: 177 B Width: 42  |  Height: 22  |  Size: 282 B

BIN
images/deuterium.png

Before After
Width: 42  |  Height: 22  |  Size: 177 B Width: 42  |  Height: 22  |  Size: 279 B

BIN
images/energy.png

Before After
Width: 42  |  Height: 22  |  Size: 177 B Width: 42  |  Height: 22  |  Size: 249 B

BIN
images/metal.png

Before After
Width: 42  |  Height: 22  |  Size: 177 B Width: 42  |  Height: 22  |  Size: 310 B

+ 61
- 0
package-lock.json

@ -0,0 +1,61 @@
{
"name": "gogame-frontend",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"assertion-error": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
"dev": true
},
"chai": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz",
"integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==",
"dev": true,
"requires": {
"assertion-error": "^1.1.0",
"check-error": "^1.0.2",
"deep-eql": "^3.0.1",
"get-func-name": "^2.0.0",
"pathval": "^1.1.0",
"type-detect": "^4.0.5"
}
},
"check-error": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
"dev": true
},
"deep-eql": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
"dev": true,
"requires": {
"type-detect": "^4.0.0"
}
},
"get-func-name": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
"dev": true
},
"pathval": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=",
"dev": true
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
"dev": true
}
}
}

+ 15
- 0
package.json

@ -0,0 +1,15 @@
{
"name": "gogame-frontend",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha test/*.test.js"
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"chai": "^4.1.2"
}
}

+ 72
- 0
test/calc.test.js

@ -0,0 +1,72 @@
const chai = require('chai');
const calc = require('../calc.js');
const {expect} = chai;
describe('calc', () => {
it('encrypt and decrypt', () => {
// metalmine
expect(60).to.be.equal(calc.metalmineCost(1).Metal);
expect(15).to.be.equal(calc.metalmineCost(1).Crystal);
expect(0).to.be.equal(calc.metalmineCost(1).Deuterium);
expect(0).to.be.equal(calc.metalmineCost(1).Energy);
expect(90).to.be.equal(calc.metalmineCost(2).Metal);
expect(22).to.be.equal(calc.metalmineCost(2).Crystal);
expect(0).to.be.equal(calc.metalmineCost(2).Deuterium);
expect(0).to.be.equal(calc.metalmineCost(2).Energy);
expect(17515).to.be.equal(calc.metalmineCost(15).Metal);
expect(4378).to.be.equal(calc.metalmineCost(15).Crystal);
expect(0).to.be.equal(calc.metalmineCost(15).Deuterium);
expect(0).to.be.equal(calc.metalmineCost(15).Energy);
// crystalmine
expect(48).to.be.equal(calc.crystalmineCost(1).Metal);
expect(24).to.be.equal(calc.crystalmineCost(1).Crystal);
expect(0).to.be.equal(calc.crystalmineCost(1).Deuterium);
expect(0).to.be.equal(calc.crystalmineCost(1).Energy);
expect(76).to.be.equal(calc.crystalmineCost(2).Metal);
expect(38).to.be.equal(calc.crystalmineCost(2).Crystal);
expect(0).to.be.equal(calc.crystalmineCost(2).Deuterium);
expect(0).to.be.equal(calc.crystalmineCost(2).Energy);
expect(34587).to.be.equal(calc.crystalmineCost(15).Metal);
expect(17293).to.be.equal(calc.crystalmineCost(15).Crystal);
expect(0).to.be.equal(calc.crystalmineCost(15).Deuterium);
expect(0).to.be.equal(calc.crystalmineCost(15).Energy);
// deuteriummine
expect(225).to.be.equal(calc.deuteriummineCost(1).Metal);
expect(75).to.be.equal(calc.deuteriummineCost(1).Crystal);
expect(0).to.be.equal(calc.deuteriummineCost(1).Deuterium);
expect(0).to.be.equal(calc.deuteriummineCost(1).Energy);
expect(337).to.be.equal(calc.deuteriummineCost(2).Metal);
expect(112).to.be.equal(calc.deuteriummineCost(2).Crystal);
expect(0).to.be.equal(calc.deuteriummineCost(2).Deuterium);
expect(0).to.be.equal(calc.deuteriummineCost(2).Energy);
expect(65684).to.be.equal(calc.deuteriummineCost(15).Metal);
expect(21894).to.be.equal(calc.deuteriummineCost(15).Crystal);
expect(0).to.be.equal(calc.deuteriummineCost(15).Deuterium);
expect(0).to.be.equal(calc.deuteriummineCost(15).Energy);
// energymine
expect(75).to.be.equal(calc.energymineCost(1).Metal);
expect(30).to.be.equal(calc.energymineCost(1).Crystal);
expect(0).to.be.equal(calc.energymineCost(1).Deuterium);
expect(0).to.be.equal(calc.energymineCost(1).Energy);
expect(112).to.be.equal(calc.energymineCost(2).Metal);
expect(45).to.be.equal(calc.energymineCost(2).Crystal);
expect(0).to.be.equal(calc.energymineCost(2).Deuterium);
expect(0).to.be.equal(calc.energymineCost(2).Energy);
expect(21894).to.be.equal(calc.energymineCost(15).Metal);
expect(8757).to.be.equal(calc.energymineCost(15).Crystal);
expect(0).to.be.equal(calc.energymineCost(15).Deuterium);
expect(0).to.be.equal(calc.energymineCost(15).Energy);
});
});

+ 22
- 18
user.js

@ -1,7 +1,7 @@
const token = localStorage.getItem("token"); const token = localStorage.getItem("token");
console.log(token); console.log(token);
if (localStorage.getItem("token")===null) {
if (localStorage.getItem("token") === null) {
// redirect to dashboard // redirect to dashboard
window.location.href = "/index.html"; window.location.href = "/index.html";
} }
@ -20,20 +20,24 @@ let config = {
let user = {}; let user = {};
// get user data // get user data
axios.get(url + "/", config)
.then(function (res) {
console.log(res.data);
user = res.data.user;
console.log(user);
document.getElementById("name").innerHTML = user.Name;
document.getElementById("metal").innerHTML = user.Resources.Metal;
document.getElementById("crystal").innerHTML = user.Resources.Crystal;
document.getElementById("deuterium").innerHTML = user.Resources.Deuterium;
document.getElementById("energy").innerHTML = user.Resources.Energy;
if (localStorage.getItem("mainplanet")===null) {
localStorage.setItem("mainplanet", res.data.user.Planets[0]);
}
})
.catch(function (error) {
console.log(error);
});
function getUser() {
axios.get(url + "/", config).then(function(res) {
console.log(res.data);
user = res.data.user;
console.log(user);
document.getElementById("name").innerHTML = user.Name;
document.getElementById("metal").innerHTML = user.Resources.Metal;
document.getElementById("crystal").innerHTML = user.Resources.Crystal;
document.getElementById("deuterium").innerHTML = user.Resources.Deuterium;
document.getElementById("energy").innerHTML = user.Resources.Energy;
if (localStorage.getItem("mainplanet") === null) {
localStorage.setItem("mainplanet", res.data.user.Planets[0]);
}
}).catch(function(error) {
console.log(error);
});
}
getUser();
setInterval(getUser, 5000);

Loading…
Cancel
Save