用于存储游戏得分和历史记录的良好数据模型

发布于 2024-11-27 14:25:53 字数 1495 浏览 2 评论 0原文

我正在开发一个小游戏(我正在使用Play!框架)。

在这个游戏中,玩家回答技术问题,回答正确即可获得积分。 除此之外,他们还可能赢得一些奖励,从而获得额外的积分。 这与 SO 徽章类似,只不过玩家会因该奖励而赢得积分。

我想知道存储用户得分及其历史记录的最佳方式是什么,特别是因为我希望能够显示上周、上个月等的“最佳玩家”? 这些“顶部”将类似于“SO 中的周声誉排名”(例如:https://stackoverflow.com /users?tab=reputation&filter=week)

今天,我有:

  • 一个 User 实体,其中有一个 score 属性,用于存储当前分数用户的;
  • 一个 QuestionHistory 实体,其中放置用户回答的每个问题,该实体具有以下属性:useransweredOnCorrectAnswer< /code> 等(我可以添加 pointsAwarded,但目前,所有问题都给出相同数量的分数)。

感谢 QuestionHistory 实体,我能够计算一名玩家在给定时间段内赢得的分数。 但是,它不包括奖项获得的分数。

我正在考虑用另一个实体替换 QuestionHistory 实体,例如 UserActivity,它将存储该用户的任何活动:

  • 当他回答问题时,以及结果;
  • 当玩家提交新问题时;
  • 当他获奖时;
  • 有了

该实体的结构可能如下所示:

@Entity
public class PlayerActivity extends Model {

    public User user;
    public Date activityDate;
    public ActivityType type; // Define the type of activity: "QUESTION_ANSWERED", "AWARD_RECEIVED", "QUESTION_SUBMITTED", etc.
    public int score; // Points won by this activity.

}

这样的实体,我还可以显示活动历史记录,例如 SO 网站上提供的活动历史记录(例如:https://stackoverflow.com/users/22656/jon-skeet?tab=activity

您对这个新提议有何看法,或者是否有更聪明的方法的这样做?

I am developing a little game (I'm using Play! framework).

In this game, the players answer technical questions, and win points when they answer correctly.
In addition to that, they may win some awards, which give additional points.
This is similar to the SO badges, except that the player wins points for that awards.

I am wondering what is the best way to store user score and the history of them, especially since I want to be able to display "Top player" for last week, for last month, etc.?
These "tops" will be similar to the "Week reputation ranking in SO" (ex: https://stackoverflow.com/users?tab=reputation&filter=week)

Today, I have:

  • A User entity, where I have a score attribute, which stores the current score of the user;
  • A QuestionHistory entity, where I put every question answered by the user, which has the following properties: user, answeredOn, correctAnswer, etc. (I can add a pointsAwarded, but for the moment, all questions give the same amount of points).

Thanks to QuestionHistory entity, I am able to calculate the score won by one player for a given time period.
However, it will not include the score received by the awards.

I was thinking of replacing the QuestionHistory entity by another entity, for example UserActivity, which will store any activity for this user:

  • when he answers a question, with the result;
  • when the player submit a new question;
  • when he wins an award;
  • etc.

The structure of this entity may look like:

@Entity
public class PlayerActivity extends Model {

    public User user;
    public Date activityDate;
    public ActivityType type; // Define the type of activity: "QUESTION_ANSWERED", "AWARD_RECEIVED", "QUESTION_SUBMITTED", etc.
    public int score; // Points won by this activity.

}

With such entity, I would be also able to display an activity history like the one provided on SO site (ex: https://stackoverflow.com/users/22656/jon-skeet?tab=activity)

What do you think of that new proposition, or is there a smater way of doing that?

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

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

发布评论

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

评论(1

别念他 2024-12-04 14:25:53

我认为这绝对是计算积分的更好方法,因为您正在管理活动,并且您是“面向未来的”,以防您想要扩展奖励用户的活动。

是的,您可能会发现更复杂的设计来做到这一点。但你提出的方法很简单而且有效,所以......去吧:)

I think this is definitely a better way to calculate the points, as you are managing events and you are "future proof" in case you want to extend the activities that reward users.

Yes, probably you may find more convoluted designs to do this. But the one you propose is simple and it works, so... go for it :)

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