简体   繁体   English

实时游戏开发

[英]Real time game development

I want to develop a real time game for Android with libgdx. 我想用libgdx为Android开发一款实时游戏。 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. 例如,我希望这笔钱每小时增加10学分(实际生活时间),这样你就可以退出游戏并在一小时后回来并获得这笔钱。

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 . ntp站点下载NtpMessage.java和SntpClient.java。 Then run SntpClient.java with a ntp port. 然后使用ntp端口运行SntpClient.java。 eg 例如

java SntpClient 0.pool.ntp.org java SntpClient 0.pool.ntp.org

You can use the code of SntpClient class and tweak if you need to. 您可以使用SntpClient类的代码并根据需要进行调整。

When user gets out of game (pause state), get the time from ntp and save it. 当用户退出游戏(暂停状态)时,从ntp获取时间并保存。 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. 此解决方案的成本要低得多,但您的应用程序将容易受到手机时间操作的影响

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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