Redwall: Warlords

Discussion => Development => Topic started by: Sharptooh on May 19, 2013, 05:07:17 PM

Title: Turns spent building?
Post by: Sharptooh on May 19, 2013, 05:07:17 PM
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
Title: Re: Turns spent building?
Post by: taekwondokid42 on May 19, 2013, 06:59:17 PM
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.
Title: Re: Turns spent building?
Post by: Firetooth on May 20, 2013, 06:33:20 AM
Sharp's already done something, he should probably post that before anybody codes anything else.
Title: Re: Turns spent building?
Post by: Sharptooh on May 20, 2013, 01:18:49 PM
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.