为成就系统设计MySQL表 [英] Designing MySQL table for Achievements system

查看:154
本文介绍了为成就系统设计MySQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为成就系统创建一个数据库(就像您在暴雪游戏中看到的一样).我希望有一个GUI显示游戏中所有成就的当前进度,这意味着我需要查询用户所有成就的进度才能填充GUI.我计划取得约100项成就.

I am creating a database for an achievement system (like something you would see in a Blizzard game). I would like to have a GUI that displays the current progress of all achievements in the game which means I will need to query the progress of all achievements for a user in order to populate the GUI. I plan on having somewhere around 100 achievements.

这带来了一个设计问题. 设计数据库和查询代码以查询约100位字段的进度的最佳方法是什么?

This brings about a design question. What is the best way to design the database and querying code to query the progress of ~100 bit fields?

蛮力方法似乎是获取整个成就行,然后对该行中的每个字段进行一些硬编码的字符串比较,以确定我们要处理的成就.

It seems like the brute force method would be to get the entire row of achievements and then for each field in the row do some hardcoded string comparison to determine which achievement we are dealing with.

另一种可能的解决方案可能是根据表的列索引创建一个较大的switch语句,并针对每种情况处理每一项成就(要求不修改表,否则您必须重构很多C ++代码).

Another possible solution may be to have a big switch statement based on the column index of the table and handle each achievement for each case (requires not modifying the table or you have to refactor a lot of C++ code).

我很好奇,听到你们为此设计的其他任何设计. 谢谢!

I'm curious to hear any other designs you guys may have for this. Thanks!

推荐答案

我建议使用3个表来构建解决方案.这些表是用户,成就和用户成就.在用户表中将使用u_id标识用户.将在成就表中使用a_id标识成就.然后,您可以通过在user_achievements表中插入一行来跟踪用户的成就,该行包括用于标识用户的u_id和用于标识成就的a_id. user_achievements表还将包含一列,该列将为给定用户指定该成就的完成百分比.

I suggest building a solution using 3 tables. These tables are users, achievements and user_achievements. A user would be identified with a u_id in the users table. An achievement would be identified with a a_id in the achievements table. You would then keep track of users achievements by inserting a row in the user_achievements table that includes a u_id to identify the user and a a_id to identify the achievement. The user_achievements table would also contain a column that would specify the % completion of that achievement for the given user.

这篇关于为成就系统设计MySQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆