在游戏结束时,需要更新和获取最新得分。
设计一个工具类,只有类方法,这样外部就能很方便地获取和更新值。
/**
* This is a help class, using to operate the user information conveniencely
*/
class RecordTool {
public:
/**
* Get the best score with a key, store in the UserDefault
*/
static int getBestScore();
/**
* Update a new score in the local UserDefault
*
* @param bestScore The new value of score
*/
static void setBestScore(int bestScore);
};
#endif /* defined(__EngryBird__RecordTool__) */
这种写法有很多好处,比如外部不需要传key,由内部控制,这样就不会全工程散落了,维护起来就简单多了。
实现是很简单的,是使用UserDefault来管理的,这个类是引擎提供的,跟IOS的NSUserDefault的使用是很像的,毕竟引擎是由2d而来的。

本文介绍了一个用于游戏得分管理的工具类RecordTool,该类提供静态方法以方便地获取和更新用户的最佳得分。通过使用引擎提供的UserDefault类进行管理,简化了整个项目的得分维护工作。
1211

被折叠的 条评论
为什么被折叠?



