在 Objective-C 游戏中使用枚举或抽象基类

发布于 2024-10-22 02:49:09 字数 470 浏览 5 评论 0原文

上下文: 在游戏中,完成每个级别后,会根据玩家表现存储评级:差、好、优秀。 评级随后用于评估整个游戏。

问题: 评级对象是否应该包含作为枚举 {RatingPoor、RatingGood、RatingExcellent} 的评级选择,或者我应该创建一个带有子类 RatingPoor、RatingGood、RatingExcellent 的抽象基类评级。

其他详细信息
评级没有复杂的行为,它们只是以非常低的频率(例如每分钟)根据游戏统计数据生成的。他们被分配到一个集合,并在游戏结束时进行平均,以生成排名(如学员、飞行员、上尉、海军上将)。在关卡结束时,评级会显示为图标(想想星星,就像《愤怒的小鸟》中的那样)。当玩家暂停或暂停游戏时,它们也会被存储。

在这种情况下,我也希望知道如何决定枚举与子类。

Context:
In a game, when each level is completed, a Rating is stored based on player performance: Poor, Good, Excellent.
The ratings are later used to evaluate the game play as a whole.

Question:
Should the Rating object contain a rating choice as an enum {RatingPoor, RatingGood, RatingExcellent} or should I make an abstract base class Rating with subclasses RatingPoor, RatingGood, RatingExcellent.

Other details
Ratings don't have complex behaviors, they are just generated from play stats at a very low frequency like every minute. They're assigned to a collection and averaged at the end of a game to generate a Rank (like Cadet, Pilot, Captain, Admiral). At the end of a level, the rating is shown as an icon (think stars, like in Angry Birds). They also get stored when the player pauses or suspends the game.

I would also appreciate knowing how to decide on enum vs. subclass, given this context.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

这种情况很基本,您应该只使用enum。当某些东西可以用整数(模式,设置,或者在您的情况下,评级)表示时,我通常使用enum。仅当您的评级包含其他属性或关系时才需要子类。

This situation is basic enough that you should just use an enum. I typically use enum's when something can be represented by an integer (a mode, a setting, or in your case, a rating,). A subclass is only necessary if your ratings would include additional attributes or relationships.

辞慾 2024-10-29 02:49:09

我认为子类对于这种情况来说太过分了,因为听起来您没有为每个评级附加任何特定的方法。我会使用枚举。

我不是软件设计方面的专家,但我通常会错误地使用最简单的数据结构来完成工作——一般来说,如果问题不需要你有处理数据的方法,那么类将是比必要的更重量级。

I think that a subclass would be overkill for this situation, as it doesn't sound like you're attaching any particular methods to each rating. I would use an enum.

I'm no expert in software design, but I generally err towards using the simplest data structures that will get a job done-- in general, if the problem doesn't require you to have methods travelling with the data, a class would be more heavyweight than necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文