您将如何设计一个数据库来存储迷宫和在同一迷宫中玩的游戏?
我的任务是设计一个数据库来存储迷宫和在这些迷宫中玩的游戏。
迷宫本质上是一个网格,包含奖品和陷阱。作业并不更具体:它要求我们找到某种通用规则来表达游戏中发生的事件以及这些事件的规则。
我已经写下了它的一个简单的概念架构:
根据我对作业的描述,您认为这是一个很好的解决方案吗?我该如何改进它?
I have an assignment to design a database for storing mazes and games played on these mazes.
A maze is essentially a grid, containing prizes and traps. The assignment isn't more specific: it asks us to find some kind of general rules to express events that occur in game and rules for these events.
I've put down a simple conceptual schema of it:
Do you think that, based on my description of the assignment, this is a good solution? How can I improve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以迷宫是一个网格,每个节点都包含数据。
每个节点包含几个东西:
1)其他节点的链接列表
2)该节点可用的项目列表
其他一切都可以表示为这些。
这表明有一个表 MAZE,其中包含有关迷宫的基本数据,如 ID、名称、描述等。
然后有一个表 NODE,包含有关该节点的数据。 ID、名称、坐标和 MAZE_ID
第三个项目,包含 ID、ITEM_NAME、NODE_ID、ITEM_TYPE,也许还有其他内容。
为了加速查找操作,您可能需要一个仅包含 MAZE_ID 和 NODE_ID 以及两个表的外键的链接表 MAZE_NODE,以及一个具有类似 NODE_ID 和 ITEM_ID 字段的 NODE_ITEM 表。
可能需要其他列和表来保存不特定于数据层次结构的信息(例如有关项目统计信息、节点处的环境条件等的信息)。
这只是迷宫的一个非常基本的数据结构。
对于传说故事,你至少需要包含文本、章节、每章启动条件等的表格。
这几乎与迷宫无关,尽管条件可能包括玩家位于迷宫中的特定位置,或者告诉他去特定位置。
So a maze is a grid, with each node containing data.
Each node contains several things:
1) a list of links to other nodes
2) a list of items available at that node
Everything else can be expressed as those.
That suggests a table MAZE, containing basic data about the maze like its ID, NAME, DESCRIPTION, etc.
Then there's a table NODE, containing data about the node. ID, NAME, COORDINATES, and MAZE_ID
3rd ITEM, with ID, ITEM_NAME, NODE_ID, ITEM_TYPE, and maybe other things.
To speed up lookup operations, you might want a link table MAZE_NODE containing just MAZE_ID and NODE_ID with foreign keys to both tables, and a NODE_ITEM table with similarly NODE_ID and ITEM_ID fields.
Other columns and tables may be needed to hold information not specific to the data hierarchy (like information about the stats of items, environment conditions at nodes, etc.).
And that's just a very basic data structure for the maze.
For the lore story, you'd at the very least need tables with texts, chapters, conditions under which each chapter is launched, etc. etc.
This is pretty much independent of the maze, though the conditions might include the player being in a specific location in the maze, or telling him to go to a specific location.
您应该将任务分成
考虑到(2)您可以使用关系数据库记录事件,甚至包括在列出列的单个表中英雄的移动:
(不要为每个游戏创建一个表;)
考虑 (1):
您应该将迷宫存储为网格。这可以通过描述其类型的每个网格单元的例如单字节的阵列(能够存储wall、free、加上254个项目)来实现。这取决于您存储此数组的位置,但如果您将其存储在数据库中,请不要尝试将迷宫和单元格拆分到不同的表中(您描述的 1:n 关系),只需将迷宫作为 BLOB 存储在表中,其中包含所有迷宫中的斑点。
You should separate the tasks into
Considering (2) you are fine with a relational database logging events even including movement of your hero in a single table listing the columns:
(Do not create a table per game ;)
Considering (1):
You should store the maze as a grid. This can be implemented by an array of e.g. single bytes (capable of storing wall, free, plus 254 items) per grid-cell describing its type. It is up to you where you store this array but if you store it in a database do not try to split maze and cells into different tables (the 1:n relationship you described), just store the maze as a BLOB in table which contains the BLOBs of all your mazes.