简体   繁体   中英

Real time game development

I want to develop a real time game for Android with libgdx. I need to update some variables even dough the game is not running.

For example I want the money to be increased 10 credits per hour (real life hour) so that you can go out of the game and come back an hour later and get that money anyway.

How can I do that?

Thanks

For real time, no need to setup your own server. Just use one of the public time server. Download NtpMessage.java and SntpClient.java from ntp site . Then run SntpClient.java with a ntp port. eg

java SntpClient 0.pool.ntp.org

You can use the code of SntpClient class and tweak if you need to.

When user gets out of game (pause state), get the time from ntp and save it. Once the user launches your game, get the time again and compare.

How about these two possible solutions (easy vs. difficult)

The difficult one... To have a full control, you need to implement the logic in a server and have your application connect to it to get the credits (expensive but excellent solution). Your app will not hold permanent data. Your app will only be used for display, interaction, send/receive data from server.

The easy one...To simply use your app along with phone time. This solution costs much less but your app will be vulnerable against phone time manipulations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM