简体   繁体   中英

How would I construct this database?

I have coded a battleships game and I am now trying to make it so that before the user can guess the position of the ships they must get a maths question correct. I then want the difficult of the questions being asked to adapt with the ability of the user. I believe that the best way to do this is by creating a table of math questions arranged in columns of difficulty. For example the first question will be a random question from column 5; if the user gets it correct then the next question will be asked from column 6, and if incorrect from column 4. I have never created a database before and I need help on how to do it.

Create a table called Question with the following columns:

  • Name - uniquely identifies the question.
  • Text - the text of the question that the user will see.
  • ExpectedAnswer - the expected answer to the question; as these are math questions I assume you expect the user to enter a numeric answer, which you can then compare to the expected answer.
  • Difficulty - the difficulty of the question.

By making Difficulty a column, you do not need to have multiple columns of questions. This is an example of database " normalization ". It allows you to run a query like this:

select Name, Text, ExpectedAnswer from Question where Difficulty = 'Hard'

You also need to have some way of not repeating questions. For example, keep a list of questions you have already asked, then you can use the query:

select Name, Text, ExpectedAnswer from Question where Difficulty = 'Hard' and Name not in listOfPreviouslyAskedQuestions.

You will need to work out how to pass listOfPreviouslyAskedQuestions into the database query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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