Pregunta

I decided to write a web browser game. But my mind comes sick when I try to think how to code the resources shown of each player when this display the website.

For example:

User 1 have 500 gold now, and produces +100 gold each hour, how can I show the real resources when the user open the website?

What is the best way?

I think that update all the database of each user adding resources every second is suicidal.

The think is that I have no idea how to code.

Any ideas?

Thanks

¿Fue útil?

Solución

When a user interacts with your website, look at the date of the last time you updated its gold amount. If it's more than 1 hour, increment the amount of gold of the number of hours passed since it's last interaction, and update the stored date.

You may do some optimisation on this principle to avoid testing it at each user request during a session (use a cache, of store the date in the session).

Update: store the next update time instead of the last, to avoid multiple calculations (that is to say store the timestamp of the current update + 1 hour). And then compare current time to the stored time.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top