简体   繁体   English

IOS游戏 - 生命再生

[英]IOS Game - Life Regeneration

I have a IOS / cocos2d game with a php/mysql server where a user is given 5 lives at the start. 我有一个带有php / mysql服务器的IOS / cocos2d游戏,一开始就给用户5个生命。 Users can connect on any device to play via their Facebook account. 用户可以通过他们的Facebook帐户连接任何设备进行播放。

Each time they play a game, one life is used up. 每次他们玩游戏,一个人的生命就会消耗殆尽。 Lives regenerate once every 10 minutes, regardless of whether app is active, resigned or terminated. 无论应用程序是处于活动状态,已暂停还是终止,生命每10分钟重新生成一次。

I understand that I can use NSTimer or CCDelayTime to "regenerate" lives while the app is active, but how can I get this to persist while the app is minimized or closed? 我知道我可以在应用程序处于活动状态时使用NSTimer或CCDelayTime来“重生”生命,但是如何在应用程序最小化或关闭时保持这种状态? Should I implement this on the server side? 我应该在服务器端实现这个吗?

Since you want the life information to be available across all devices, you must therefore store the information on the server. 由于您希望所有设备都可以使用生命信息,因此必须将信息存储在服务器上。 If you just wanted the data to persist on a single device you could use NSUserDefaults for when the app isn't active. 如果您只是希望数据在单个设备上保留,则可以在应用程序未处于活动状态时使用NSUserDefaults

Should I implement this on the server side? 我应该在服务器端实现这个吗?

I think that you should handle this on the server side for two main reasons: 我认为你应该在服务器端处理这个问题主要有两个原因:

  1. You say that your app can be played from more than one device. 您说您的应用可以从多个设备播放。 The number of remaining lives should be the same whatever the device you are playing from so it needs to be kept in a unique place. 无论您正在玩什么设备,剩余生命的数量都应该相同,因此需要将其保存在一个独特的地方。

  2. Also keeping the number of lives on the server side will prevent you from users trying to hack your app by changing locally the number of remaining lives. 同时保持服务器端的生命数量将阻止用户尝试通过本地更改剩余生命的数量来破解您的应用程序。

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

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