Browse Source

add points and countdown

master
arnaucube 5 years ago
parent
commit
73748aac6c
5 changed files with 49 additions and 23 deletions
  1. +3
    -0
      buildings.html
  2. +37
    -21
      buildings.js
  3. +4
    -1
      calc.js
  4. +2
    -0
      dashboard.html
  5. +3
    -1
      user.js

+ 3
- 0
buildings.html

@ -62,9 +62,12 @@
<div class="col-sm-10"> <div class="col-sm-10">
User Name: <span id="name"></span> User Name: <span id="name"></span>
<br> <br>
Points: <span id="points"></span>
<br>
Planet Name: <span id="planetname"></span> Planet Name: <span id="planetname"></span>
<br><br> <br><br>
<div id="currentBuild"></div> <div id="currentBuild"></div>
<div id="countdown"></div>
<br> <br>
<table> <table>

+ 37
- 21
buildings.js

@ -1,14 +1,13 @@
function secondsToTime(secs)
{
var h = Math.floor(secs / (60 * 60));
function secondsToTime(secs) {
var h = Math.floor(secs / (60 * 60));
var divisor_for_minutes = secs % (60 * 60);
var m = Math.floor(divisor_for_minutes / 60);
var divisor_for_minutes = secs % (60 * 60);
var m = Math.floor(divisor_for_minutes / 60);
var divisor_for_seconds = divisor_for_minutes % 60;
var s = Math.ceil(divisor_for_seconds);
var divisor_for_seconds = divisor_for_minutes % 60;
var s = Math.ceil(divisor_for_seconds);
return h + "h " + m + "m " + s + "s";
return h + "h " + m + "m " + s + "s";
} }
function printNeededResources(r) { function printNeededResources(r) {
@ -54,6 +53,21 @@ function printResources(r) {
document.getElementById("energy").innerHTML = r.Energy; document.getElementById("energy").innerHTML = r.Energy;
} }
function coundown(t) {
document.getElementById("countdown").innerHTML = `
Countdown: <b>` + secondsToTime(t) + `</b>`;
let timer = setInterval(function() {
if (t > 0) {
t--;
document.getElementById("countdown").innerHTML = `
Countdown: <b>` + secondsToTime(t) + `</b>`;
} else {
clearInterval(timer);
getUser();
}
}, 1000);
}
function printBuildings(planet) { function printBuildings(planet) {
let r = {}; let r = {};
let resrourcesHtml = {}; let resrourcesHtml = {};
@ -65,8 +79,10 @@ function printBuildings(planet) {
<br> <br>
Finishes at: <b>` + planet.CurrentBuild.Ends + `</b> Finishes at: <b>` + planet.CurrentBuild.Ends + `</b>
` `
coundown(planet.CurrentBuild.CountDown);
} else { } else {
document.getElementById("currentBuild").innerHTML = ""; document.getElementById("currentBuild").innerHTML = "";
document.getElementById("countdown").innerHTML = "";
} }
// metalmine // metalmine
@ -82,7 +98,7 @@ function printBuildings(planet) {
document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")"; document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")";
document.getElementById("btnBuildMetalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('metalmine')">Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `</div>`; document.getElementById("btnBuildMetalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('metalmine')">Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `</div>`;
r = metalmineCost((+ (planet.Buildings.metalmine) + + (1))); r = metalmineCost((+ (planet.Buildings.metalmine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.metalmine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + ` document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -108,7 +124,7 @@ function printBuildings(planet) {
document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")"; document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")";
document.getElementById("btnBuildCrystalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalmine')">Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `</div>`; document.getElementById("btnBuildCrystalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalmine')">Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `</div>`;
r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1))); r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.crystalmine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + ` document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -134,7 +150,7 @@ function printBuildings(planet) {
document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")"; document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")";
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriummine')">Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `</div>`; document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriummine')">Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `</div>`;
r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1))); r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.deuteriummine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + ` document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -160,7 +176,7 @@ function printBuildings(planet) {
document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")"; document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")";
document.getElementById("btnBuildEnergyMine").innerHTML = `<div class="allowed" onclick="buildBuilding('energymine')">Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `</div>`; document.getElementById("btnBuildEnergyMine").innerHTML = `<div class="allowed" onclick="buildBuilding('energymine')">Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `</div>`;
r = energymineCost((+ (planet.Buildings.energymine) + + (1))); r = energymineCost((+ (planet.Buildings.energymine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.energymine) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + ` document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -186,7 +202,7 @@ function printBuildings(planet) {
document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")"; document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")";
document.getElementById("btnBuildFusionReactor").innerHTML = `<div class="allowed" onclick="buildBuilding('fusionreactor')">Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `</div>`; document.getElementById("btnBuildFusionReactor").innerHTML = `<div class="allowed" onclick="buildBuilding('fusionreactor')">Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `</div>`;
r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1))); r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.fusionreactor) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + ` document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -238,7 +254,7 @@ function printBuildings(planet) {
document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")"; document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")";
document.getElementById("btnBuildShipyard").innerHTML = `<div class="allowed" onclick="buildBuilding('shipyard')">Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `</div>`; document.getElementById("btnBuildShipyard").innerHTML = `<div class="allowed" onclick="buildBuilding('shipyard')">Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `</div>`;
r = shipyardCost((+ (planet.Buildings.shipyard) + + (1))); r = shipyardCost((+ (planet.Buildings.shipyard) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.shipyard) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + ` document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -264,7 +280,7 @@ function printBuildings(planet) {
document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")"; document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")";
document.getElementById("btnBuildMetalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('metalstorage')">Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `</div>`; document.getElementById("btnBuildMetalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('metalstorage')">Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `</div>`;
r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1))); r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.metalstorage) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + ` document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -290,7 +306,7 @@ function printBuildings(planet) {
document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")"; document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")";
document.getElementById("btnBuildCrystalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalstorage')">Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `</div>`; document.getElementById("btnBuildCrystalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalstorage')">Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `</div>`;
r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1))); r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.crystalstorage) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + ` document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -316,7 +332,7 @@ function printBuildings(planet) {
document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")"; document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")";
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriumstorage')">Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `</div>`; document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriumstorage')">Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `</div>`;
r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1))); r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.deuteriumstorage) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + ` document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -342,7 +358,7 @@ function printBuildings(planet) {
document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")"; document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")";
document.getElementById("btnBuildRessearchLab").innerHTML = `<div class="allowed" onclick="buildBuilding('ressearchlab')">Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `</div>`; document.getElementById("btnBuildRessearchLab").innerHTML = `<div class="allowed" onclick="buildBuilding('ressearchlab')">Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `</div>`;
r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1))); r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.ressearchlab) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + ` document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -368,7 +384,7 @@ function printBuildings(planet) {
document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")"; document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")";
document.getElementById("btnBuildAllianceDepot").innerHTML = `<div class="allowed" onclick="buildBuilding('alliancedepot')">Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `</div>`; document.getElementById("btnBuildAllianceDepot").innerHTML = `<div class="allowed" onclick="buildBuilding('alliancedepot')">Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `</div>`;
r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1))); r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.alliancedepot) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + ` document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -394,7 +410,7 @@ function printBuildings(planet) {
document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")"; document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")";
document.getElementById("btnBuildMissileSilo").innerHTML = `<div class="allowed" onclick="buildBuilding('missilesilo')">Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `</div>`; document.getElementById("btnBuildMissileSilo").innerHTML = `<div class="allowed" onclick="buildBuilding('missilesilo')">Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `</div>`;
r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1))); r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.missilesilo) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + ` document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + `
<br> <br>
@ -420,7 +436,7 @@ function printBuildings(planet) {
document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")"; document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")";
document.getElementById("btnBuildSpacedock").innerHTML = `<div class="allowed" onclick="buildBuilding('spacedock')">Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `</div>`; document.getElementById("btnBuildSpacedock").innerHTML = `<div class="allowed" onclick="buildBuilding('spacedock')">Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `</div>`;
r = spacedockCost((+ (planet.Buildings.spacedock) + + (1))); r = spacedockCost((+ (planet.Buildings.spacedock) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.spacedock) + + (1)));
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printNeededResources(r); resrourcesHtml = printNeededResources(r);
document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + ` document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + `
<br> <br>

+ 4
- 1
calc.js

@ -1,4 +1,4 @@
const universespeed = 1;
const universespeed = 5;
function metalmineCost(lvl) { function metalmineCost(lvl) {
const base = { const base = {
@ -214,6 +214,9 @@ function spacedockCost(lvl) {
function constructionTime(r, roboticsLvl) { function constructionTime(r, roboticsLvl) {
const naniteLvl = 1; const naniteLvl = 1;
if(isNaN(roboticsLvl)) {
roboticsLvl=0;
}
// T(h) = (metal + crystal) / (2500 * (1+roboticsLvl) * 2^naniteLvl * universespeed) // T(h) = (metal + crystal) / (2500 * (1+roboticsLvl) * 2^naniteLvl * universespeed)
tHours = (r.Metal + r.Crystal) / (2500 * (1 + roboticsLvl) * 2**naniteLvl * universespeed); tHours = (r.Metal + r.Crystal) / (2500 * (1 + roboticsLvl) * 2**naniteLvl * universespeed);
return Math.floor(tHours * 3600); return Math.floor(tHours * 3600);

+ 2
- 0
dashboard.html

@ -62,6 +62,8 @@
<div class="col-sm-4"> <div class="col-sm-4">
<h3>Dashboard</h3> <h3>Dashboard</h3>
User Name: <span id="name"></span> User Name: <span id="name"></span>
<br>
Points: <span id="points"></span>
</div> </div>

+ 3
- 1
user.js

@ -26,6 +26,7 @@ function getUser() {
user = res.data.user; user = res.data.user;
console.log(user); console.log(user);
document.getElementById("name").innerHTML = user.Name; document.getElementById("name").innerHTML = user.Name;
document.getElementById("points").innerHTML = Math.floor(user.Points/1000);
// if (localStorage.getItem("mainplanet") === null) { // if (localStorage.getItem("mainplanet") === null) {
@ -42,6 +43,7 @@ let planetid = localStorage.getItem("mainplanet");
let planet = {}; let planet = {};
// get user data // get user data
function getPlanet() { function getPlanet() {
planetid = localStorage.getItem("mainplanet");
axios.get(url + "/planets/" + planetid, config).then(function(res) { axios.get(url + "/planets/" + planetid, config).then(function(res) {
console.log("planet", res.data); console.log("planet", res.data);
planet = res.data.planet; planet = res.data.planet;
@ -57,4 +59,4 @@ function getPlanet() {
} }
getUser(); getUser();
setInterval(getUser, 5000);
setInterval(getUser, 10000);

Loading…
Cancel
Save