I am in the process of building an iPhone app with a RoR 3 web service on the back end. The app is a fairly simple peer-to-peer game. I would really appreciate it if s开发者_StackOverflow中文版omeone could share some pointers and tips on how to best divide the operations between the web service and locally on the iPhone.
For example, chess or backgammon, is the current state of the game being constantly saved and retrieved from the server? or is it stored locally on the iPhones of the players?
Thanks!
This will vary wildly depending on how you want to program the application and what your needs are. You could constantly save and retrieve game state from the server, you could synchronize game state at certain intervals determined by game play, or you could run mostly local. It all depends on your requirements. In general cell networks should be considered slow and unreliable (even though this isn't always true). Keeping data transfer to the minimum required to accomplish your goals makes your app feel more responsive and users happier (especially those in poor coverage areas and those who do not have unlimited data plans).
That depends on whether it's a game against another player or against a computer opponent. If it's against another player, then the state would be updated on and retrieved from the server. If it's against a built-in AI, there would be no reason to send that state to the server, unless your AI is inside your webservice instead of including it in the actual application. It's really a design decision based on what you're trying to accomplish. Generally I would recommend keeping as much as possible local to the app, unless there's a reason to do it on the server, but if there's any competitive aspect to your game, you definitely want to keep control of any calculations on your server. Keep in mind that someone can always try to decompile your application or call your webservices directly passing in false data.
精彩评论