如何创建内部数据库
游戏,例如Nintendo DS游戏,必须存储其对象的数据,例如RPG需要存储动物寓言、武器和咒语的数据。
我想知道用 C++ 创建游戏数据库并使用面向对象功能的最佳方法。
示例:
具有以下表格的 RPG:
- 职业(名称、种族、能力、攻击力、防御力,...)
- 种族(名称,...)
- 能力(名称,...)
- 技能(姓名、种族、力量……)
- 学习(职业、等级、技能……)
每个职业都属于一个种族。 “人类游侠”和“精灵游侠”是不同的职业。并非所有种族都可以参加一个课程。 能力是在战斗之外使用的(小偷可以撬门),技能是在战斗中使用的。 技能是一个种族发明的,但其他种族也可以学习。 “人类空手道”可以向“猫人”学习“虎拳攻击”。 班级升级后可以学习新技能。
玩家可以雇佣随机生成的雇佣兵。雇佣兵数据存储在玩家的保存文件中。
- 雇佣兵(姓名、职业、等级、个性……)
它可以存储为静态数据。每个表都可以存储为结构数组,其中数组索引是表中每一行的键。
我必须创建一个函数来用每行的数据初始化每个数组位置。但我认为它可以在内存中静态初始化而无需函数。
编辑数据库的简单方法很重要,因为许多属性值需要测试和平衡。
Games, such as Nintendo DS games, have to store data of their objects, for example, RPG needs to store data of bestiary, weapons and spells.
I want to know the best way to create a game database in C++ and use object-oriented features.
Example:
A RPG with the following tables:
- Class (Name, Race, Ability, Atk, Def, ...)
- Race (Name, ...)
- Ability (Name, ...)
- Skill (Name, Race, Power, ...)
- Learning (Class, Level, Skill, ...)
Each class belongs to a race. "Human ranger" and "Elf ranger" are different classes. A class is not available to all races.
Abilities are used outside battles (thieves can lockpick doors), and skills are for battles.
Skills are invented by a race, but other races can learn it. A "human karateka" can learn "Tiger Fist Attack" from "cat men".
A class can learn new skills when level up.
The player can hire mercenaries, that are randomly generated. Mercenaries data is stored in player's save file.
- Mercenary (Name, Class, Level, Personality, ...)
It could be stored as static data. Each table could be stored as an array of structs, where the array index is the key of each line in the table.
I would have to create a function to initialize each array position with data of each line. But I think that it can be statically initialized in memory without a function.
An easy way to edit database is important, because many attribute values need to be tested and balanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用 SQLite。它是分布最广泛的嵌入式数据库,并且可以很好地集成到多种语言中。
正如您的帖子开始解释的那样,您可以使用自己的 C++ 代码自行完成此任务,但 SQLite 很好地解决了该问题,并且您可以获得许多开箱即用的优势(排序、聚合等)。
Look into using SQLite. It is the most widely distributed embedded database and integrates very well into many languages.
As your posts begins to explain, you could accomplish this yourself with your own C++ code, but SQLite solves the problem very well and you get many advantages out of the box (sorting, aggregating, etc).