Turns spent building?

Started by Sharptooh, May 19, 2013, 05:07:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sharptooh

At the top of the build page, the game helpfully states:

QuoteYou can build x Structures per turn.

Unfortunately I'm often not bothered enough to work out how many turns building "y" number of structures can take, so it's mostly guesswork (I appreciate this is an easy thing to work out using a calculator, but I doubt many players bother doing so).

I was wondering if it might be a good idea to include a dynamic counter at the bottom of the page?

QuoteBuilding the above will take z turns

taekwondokid42

Given that the buffs page is already dynamic, adding something on the buildings shouldn't be any different.

Maybe I'll code something this week.

Firetooth

Sharp's already done something, he should probably post that before anybody codes anything else.
Quote from: Sevah on January 02, 2018, 03:51:57 PM
I'm currently in top position by a huge margin BUT I'm intentionally dropping down to the bottom.

Sharptooh

Added the code that Firetooth just described, got bored yesterday and I need to improve my JavaScript so I decided to try this:



function valueChanged (evt) {
    var structures = 0;

    for(var i = 0; i < boxNumber; i++) {
        structures += parseInt(buildTextBoxes[i].value, 10);   
    }
   
    document.getElementById('build-turns').innerHTML = Math.round(structures/59);
}

var buildPage = document.getElementById('build-page');
var buildTextBoxes = buildPage.getElementsByClassName('input_text');
var boxNumber = buildTextBoxes.length;

for(var i = 0; i < boxNumber; i++) {
    buildTextBoxes[i].onchange = valueChanged;
}


"59" needs replacing with the number of structures you can build per turn (you can echo that with PHP or add some HTML to enable getting the value with JavaScript)

Other than that, all you'd need to do is add a span where you want the counter to appear:

Quote
<span id="build-turns"></span>

It isn't great, it currently only calculates when the selected input loses focus, and it doesn't validate to check if the user has entered numbers, but it works.