Broswer Games - Javascript question

Soldato
Joined
20 Oct 2002
Posts
6,212
Location
UK
Hello,

Im looking at creating a standards complient, cross platform, browser based game for my final year project for uni... I've been looking at some online games a fair bit recently and am a bit unsure as to how some aspects of them work (im a bit of a Javascript novice!).

could anyone enlighten me, via pseudo code or just a brief description:

How do the buildings get upgraded in a basic game like Ikarium or Travian?

I assume the building levels are held in a database, against a specific city ID... once the upgrade process starts the cities resources are changed and a counter starts... once finished the level of the building changes, an update is performed on the database and new functions are enabled at that building based on its level... ?

i've researched javascript counters which are passed a date and time, down to the second.. the script then counts the Days, Hours, Minutes, Seconds until it reaches 0... the bit that confuses me is, how does the clients machine know, when completion is... would i be correct in saying the completion date is calculated in advance using something like previous levels build time * 1.2... stored in the database... requested... passed into the counter and the counter presented to the user?

the more i think about the whole process, especially 'battle reports' the more im starting to think i've bitten off more than i can chew.

thanks :)
 
sorry to drag it back up again but if anybody has some insight into this it would be greatly appreciated!

thanks,
 
still looking / thinking / planning if anybody has any resources or sites/forums that'd be worth me checking out?

Thanks,
 
You would write the page in asp/php/.net whatever, not Javascript and get it to write out a bit of javascript which updated the client in however many seconds you wanted.
You could even get the timer to make a nice little graphic change every second to show the progress.

Simon
 
yeah i'd most probably write the pages in PHP as im most comfortable with this... but wouldnt each players building levels need to be stored in a database ?

the user would surely start a process involving javascript which counted down the seconds, against the servers 'game' clock and upon reaching 0 would do a database write? would that be how it would work?
 
There would need to be a lot of thought put into the structure of the database but I think essentially you have the basic idea right.

Levels and such are stored in the database anything to do with counting down would be javascript which is passed an end date from the database which was worked out an stored when the user clicked "upgrade"
 
DB would have tables which stored users profiles, current buildings, buildings in progress and date/time new building would be complete.
User click a button to buy the item/house/upgrade whatever.
PHP writes to DB the new building in progress and works out how long it will take.
PHP then writes a new page out saying "You have 10 seconds to wait" or whatever, which can be made to tick down with javascript if required.
If the user hangs around on the page for the 10 seconds, the javascript kicks off a refresh of the page. That's all it does.
The PHP page, when it loads, checks the current time on the server against the DB to show any buildings that have passed the upgrade time; removes them from the building in progress table and adds them to the users buildings table. Then displays the page.

Simon
 
Back
Top Bottom