开发者

Implementation/Design Advice for Simple iPhone Game

Problem

I am creating a score calculator for a certain cards game. 开发者_运维知识库It gets quite complicated in terms of navigation and view controllers.

Basically, what I need is a way to track the current score, 4 players' objects instantiated upon startup and a way to track the progress of the game (the game has 4 sort of "levels" or "cycles").

Possible Solutions

So what I am thinking of doing is to create a Singleton class for the score manager. I also created a Player object which I will probably instantiate in the AppDelegate class and keep it passing them in an array upon new VC loads.

Continue Last Game

I would like the app to store the last game if the app has been terminated, and an option to resume it upon startup. I will have to keep track of: players' names, each player's score, as well as a detailed score sheet for each round played.

My Questions

  • Is my solution to create 4 players' objects in the AppDelegate and pass them along VC's upon each VC push a good solution? If not, how do games usually implement a Player object? I've created games in the past using C++ and Java but there were all too simple and the "game manager" was only one class, so I never had to deal with passing the Players objects around before. Furthermore, if a player hits "Back" and the navigation controller pops an item off its stack, will the player object still be instantiated in the previous VC? If not, will I also have to pass it when the "back" button is hit?

  • I will probably have the score management also track the progress of the game, or where the game is at using a Singleton class. Is that a good design decision?

  • To store the names, scores and the whole score sheet, is it advisable to just use NSUserDefault or would it be better to use a plist, especially since I need to track the score sheet?

Any implementation advice is highly appreciated.


Good question. I like your idea of implementing the game. The only concept I won't suggest you to implement is to create the players in your AppDelegate. There is no harm in doing so, but it is also not a good practice to alter your AppDelegate. Instead what you may do is create a separate class, say Player.h and Player.m (Player.mm in case you are using Box2d). Do the stuff you wish to do and call the class variables and functions in your scene.
Secondly, the idea of using PList over NSUserDefault will be more efficient when you wish to store large amount of data and vice verse, if you want to store small data. This is a good discussion which might help you for the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜