简体   繁体   English

刽子手游戏需要数据库吗?

[英]Does hangman game needs a database?

I am trying to design a hangman game in lucidchart.我正在尝试在 lucidchart 中设计一个刽子手游戏。 Just start to thinking about the data.刚开始考虑数据。 If I decide to store them in database, what kinds of columns do I need?如果我决定将它们存储在数据库中,我需要哪些类型的列?

I can think of columns:我可以想到列:

(1) word: To store the actual word; (2) numberOfWrongGuesses: To store the wrong guess number (3) currentWord: The word currently has guessed etc.

One problem is once the user done the game or prepare to start a new game, the database needs to be cleaned up right?一个问题是一旦用户完成游戏或准备开始新游戏,数据库需要清理吗?

Not necessary, you can create a js file with let object like this:不是必须的,你可以使用 let object 创建一个 js 文件,如下所示:

data.js数据.js

const words = [
    { id: 1, name: 'spring' },
    { id: 2, name: 'promise' },
];

after you import this file to your html file.将此文件导入 html 文件后。

If I decide to store them in database, what kinds of columns do I need?如果我决定将它们存储在数据库中,我需要哪些类型的列?

It depends on how you want the game to work, not just gameplay (guessing the current word) but also managing what happens once the current game is finished - did you want to keep score, etc?这取决于您希望游戏如何运行,不仅仅是游戏玩法(猜测当前单词),还取决于当前游戏完成后会发生什么 - 您是否想保持得分等?

I don't know how Lucid chart works (what sort of runtime, API and programming environment it supports; or how users will interact with it, can it maintain state, etc), but you may be able to run the game entirely in-memory and not need a database at all.我不知道 Lucid 图表是如何工作的(什么样的运行时,API 和它支持的编程环境;或者用户将如何与之交互,它是否可以维护 state 等),但你可以完全在 -内存,根本不需要数据库。

Before diving straight into the physical columns, do a logical design on paper or a whiteboard.在直接进入物理列之前,先在纸上或白板上进行逻辑设计。

One problem is once the user done the game or prepare to start a new game, the database needs to be cleaned up right?一个问题是一旦用户完成游戏或准备开始新游戏,数据库需要清理吗?

That also depends on how you want the game to work.这也取决于您希望游戏如何运行。 It also depends how many people will be playing this - if two people play it at once, they'll need their own separate set of data.这也取决于有多少人会玩这个——如果两个人同时玩,他们将需要自己的单独数据集。

Cleaning up the data helps keep the database size smaller over time, but it also means you wouldn't be able to track a players history, or allow you to see things like "hardest 5 letter words of all time" etc.清理数据有助于随着时间的推移使数据库大小保持较小,但这也意味着您将无法跟踪玩家的历史记录,或者让您看到“有史以来最难的 5 个字母单词”等内容。

In general: Start with an analysis of what you want the application to do.一般来说:首先分析您希望应用程序做什么。 Only after that, you can decide if you need persistent storage, and if a database would be the best persistent storage for your application.只有在那之后,您才能决定是否需要持久存储,以及数据库是否是您应用程序的最佳持久存储。

Note that databases are used for persistent storage.请注意,数据库用于持久存储。 Since you are thinking about wiping the database after each game, this makes me think you do not need a database.由于您正在考虑在每场比赛后擦除数据库,这让我认为您不需要数据库。

In this case, I think that you might not need any storage at all.在这种情况下,我认为您可能根本不需要任何存储空间。 Since you mention Javascript, you might be building a game that runs in the browser.由于您提到 Javascript,您可能正在构建一个在浏览器中运行的游戏。 Perhaps cookies would be enough to keep track of the score of your user.也许 cookies 足以跟踪用户的分数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM