用于存储游戏得分和历史记录的良好数据模型
我正在开发一个小游戏(我正在使用Play!框架)。
在这个游戏中,玩家回答技术问题,回答正确即可获得积分。 除此之外,他们还可能赢得一些奖励,从而获得额外的积分。 这与 SO 徽章类似,只不过玩家会因该奖励而赢得积分。
我想知道存储用户得分及其历史记录的最佳方式是什么,特别是因为我希望能够显示上周、上个月等的“最佳玩家”? 这些“顶部”将类似于“SO 中的周声誉排名”(例如:https://stackoverflow.com /users?tab=reputation&filter=week)
今天,我有:
- 一个
User
实体,其中有一个score
属性,用于存储当前分数用户的; - 一个
QuestionHistory
实体,其中放置用户回答的每个问题,该实体具有以下属性:user
、answeredOn
、CorrectAnswer< /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 ascore
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 apointsAwarded
, 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这绝对是计算积分的更好方法,因为您正在管理活动,并且您是“面向未来的”,以防您想要扩展奖励用户的活动。
是的,您可能会发现更复杂的设计来做到这一点。但你提出的方法很简单而且有效,所以......去吧:)
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 :)