-1

I am still brand new to playing with Databases and was wanting to create a tracking database for a few games like clash of clans.

I am unsure of how to structure some tables.

Here is the end result: Select a user User inputs levels of buildings. this is stored in a table.

the tricky part(at least for me) is determining what buildings and what levels are available based upon the user's current levels.

Example: Current level of user is TH7 and Laboratory level 5 and spell factory 3

Spells available at th7 are A B C. But with Factory level 3 only spells are A B and with the Laboratory Spell A can reach a maximum of 3 and Spell B can reach a Maximum of level 2.

My thought is 1 giant table of all permutations of all buildings and prerequisites. But that doesn't seem right. Is that over simplified?

Keep in mind there are mulitple buildings of the same kind i.e. 5 archer towers, 5 cannons, etc.

my queries would be something like Get player current levels for prereqs lookup all building available for current TH level. determine what buildings and levels are missing. Display those.

there is a nice webpage already doing this (clasofclans-tracker) but want to recreate it for my own usage and adopt for other games. More for a learning exercise than anything else.

1 Answer 1

1

I'm not familiar with Clash of Clans, but I can work with your example.

Current level of user is TH7 and Laboratory level 5 and spell factory 3

Spells available at TH7 are A B C. But with Factory level 3 only spells are A B and with the Laboratory Spell A can reach a maximum of 3 and Spell B can reach a Maximum of level 2.

First, we'll create the object tables. In your example, you named User, Laboratory, Spell, and Factory. Generally, table names are singular.

User
----
User ID
User Name
User Game Name
User Password
User Level
...

Laboratory
----------
Laboratory ID
Laboratory Name
...

Spell
-----
Spell ID
Spell Name
User Level Available
Factory Level Available
...

Factory
-------
Factory ID
Factory Name
...

We've created a table for each object. The primary key for these tables is an auto-generated integer we call the ID.

Now, these tables by themselves aren't all that useful. We need to create junction tables that associate the user with the other components of the game.

The first junction table we'll discuss is the UserLaboratory table.

UserLaboratory
--------------
User ID
Laboratory ID
Laboratory Level

This table associates (joins) a user with a laboratory. The laboratory level is valid for a particular user and a particular laboratory. The primary key of this table, as you might guess is (User ID, Laboratory ID).

In your example, the Laboratory Level is 5.

The next junction table we'll discuss is the UserFactory table.

UserFactory
-----------
User ID
Factory ID
Factory Level

This table is almost identical to the UserLaboratory table, except that it deals with factories.

In your example, the Factory Level is 3.

I think at this point you can see how to create the remaining junction tables.

This is the process for creating any database.

  • Extract out all of the object tables.
  • Make sure that the object tables define one and only one object.
  • Create all of the junction tables.

Not the answer you're looking for? Browse other questions tagged or ask your own question.