aspose file tools*
The moose likes Game Development and the fly likes Game database for this situation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Game database for this situation?" Watch "Game database for this situation?" New topic
Author

Game database for this situation?

Chris Hericks
Greenhorn

Joined: Oct 26, 2012
Posts: 12
I am working on a pet project to practice reinforcing the concepts of organization and architecture of a large scale application. In this case, I decided to make a simplistic turn-based castle manager game. I am seeking some advice as to how to store information about certain aspects of the game. For example, there may be a variety of enemies that attack the castle, all extending Enemy.class (around 50 maybe?). While each enemy object may only hold a handful of values (health/strength/defense/etc.) my gut is telling me that it would be impractical and a waste of time to write out 50 explicit classes for each and every enemy that the player may encounter. Instead, I was thinking of creating a database of information for the program to pull information from. My google searches have led me to believe that it may be a good idea to implement an embedded database such as H2 to fill this role, however I just want to make sure that I am on the right track. Thoughts on this would be greatly appreciated.
Piet Souris
Ranch Hand

Joined: Mar 08, 2009
Posts: 700
    
  11
hi Chris,

a late reaction, so chances are it is no longer relevant, but here goes.

Isn't a database just about the HOW of the problem? What about the WHAT?
If there are 50 types of enemies, then you have to deal with that. A database will
not solve this problem for you automatically.
I must admit that I have no knowledge of H2 databases, though.

Greetz,
Piet
Chris Hericks
Greenhorn

Joined: Oct 26, 2012
Posts: 12
I appreciate that you tried to help me with my inquiry, however:

Piet Souris wrote:
Isn't a database just about the HOW of the problem? What about the WHAT?
If there are 50 types of enemies, then you have to deal with that. A database will
not solve this problem for you automatically.


Sooooo... this tells me what exactly? I could extract no relevant information from this response that could help me with my question. I do not expect to add the database to the program and expect all of my problems to be solved, and I understand that I will need to learn quite a bit about the operation and management of a database in order to get one to operate as I wish. What I am seeking is a confirmation that I am on the right path to solving the problem I pose in my first post, and advice towards unforeseen difficulties.

You will need to be more explicit about the point that you are trying to get across if you want me to understand you.

And as an afternote, I am working with MySQL Lite now.
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 251
    
    1
Oh dear, an even later reply

You just want one class for enemies.

Each enemy would have a set of different characteristics that define them ie aggression, bravery, stamina, whether they will stay in a city, join up with other enemies etc etc. These can be held in a database table if you wish but they could just as easily be held in arrays. The advantage of this approach is that you can continually tune their behaviour without having to change code, you can also get the program to detect which types of enemies are doing better and so therefore spawn that type more often than those that die off more quickly.


Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

You may want to read up on some design patterns. The Head First series has a good, accessible one. I think the very first chapter talks about something similar to this, regarding ducks and how they fly or quack. A rubber duck has a different quacking behavior than a decoy duck.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 251
    
    1
I believe that having multiple classes (even nicely defined hierarchical classes) is going to be a poor choice next to just controlling things via data (whether array or database) because:
  • Having a 100 different types of enemy is no more complicated than half a dozen - having 100 different classes is very messy
  • Enemy characteristics can be mixed and matched via the data but how do you combine an artillery class with a vehicle class without adding yet another class for tank?
  • No recoding each time you add a new enemy
  • Less overall code
  • it's simpler
  • Less testing as the same core code gets used by all enemies
  • No "recompile - test - release" loop each time you add a new data line
  • New enemies can have any mixture of features you want as opposed to just those in your parent class


  • I could probably go on ;)
    Chris Hericks
    Greenhorn

    Joined: Oct 26, 2012
    Posts: 12
    Glad to see that this thread is getting some traction.

    Mich Robinson wrote:Each enemy would have a set of different characteristics that define them ie aggression, bravery, stamina, whether they will stay in a city, join up with other enemies etc etc. These can be held in a database table if you wish but they could just as easily be held in arrays.


    This was my thought too. However if the values were held in arrays, wouldn't they need to be an explicit part of you code? This would result in a huge class file solely responsible for creating the huge array of data each time that the program was run? My gut is telling me that it would be an inefficient way of doing things, and that a database table of values would be a much better solution.

    I will look into patterns later today when I get some time.
    Mich Robinson
    Ranch Hand

    Joined: Jun 28, 2009
    Posts: 251
        
        1
    Chris Hericks wrote:if the values were held in arrays, wouldn't they need to be an explicit part of you code?
    If you have a lot of data then simply put the data in a file and read it in.

    Chris Hericks wrote:This would result in a huge class file solely responsible for creating the huge array of data each time that the program was run?
    I tend to just use the data to define how one "type of thing" functions and then use loops to create multiple instances of that type of thing. A loop can quickly define millions of a given type of thing.

    Chris Hericks wrote:My gut is telling me that it would be an inefficient way of doing things, and that a database table of values would be a much better solution.
    I actually design databases for a living and the phrase "using a sledge hammer to crack a nut" keeps springing into my mind but at the end of the day it's obviously your problem to solve how you wish and if you really want to use a database then that's entirely your choice.


     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Game database for this situation?