为成就系统设计MySQL表

编程入门 行业动态 更新时间:2024-10-10 02:20:08
本文介绍了为成就系统设计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表

本文发布于:2023-08-03 14:49:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成就   系统   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!