View Full Version : My Application - Structure(Logic) Help Needed

01-10-2008, 03:38 PM
Hey All,

So I'm Making a text based game and it is going very well thanks to the terrific help I have been getting on this forum :thumbsup:.

Anyway I have currently hit a road block! The basics of my game is complete (attacking, resource collection, buying units ect...) so I want to add civilizations. Each civilization will have different bonuses. For example civ 1 will add 2 attack points to all units, and civ 2 will make villgers collect 5% more resources.

I'm not sure how to do this. Please tell me if my thought process is logical, if not I would appreciate some tips!

My Plan: add a civilization field to my database in my members table. When a user logs in store his/her civilization in a session. Add if statements to my ArmyUnit class that will increase attack power if it retrieves the correct civilization from the session.

PS: If anyone wants to help me develop this game send me a private message :-)

01-10-2008, 05:54 PM
It depends on how customizable it should be.

Adding if statements to each unit's code that checks for a specific civilization would work fine.

But you could also consider setting up a table specifically for this, that lists bonuses. It could be very generic: Unit ID, Civ. ID, Bonus Amount, Type

For instance, Civ. A gets a 5% bonus resource collection for Peons.


So Peons would check the database for all Peon entries with type equal to 'RESOURCE', compare all Civ. IDs to the current one, if A is listed, it will add the 'Bonus Amount' to the result. In this case it is, and it updates the total resources.

This allows for easy finetuning. And you can have temporary special events with bonuses without having to modify code. But you have to remember the impact on the database.

I can't think of a clean solution for doing it per login. You could load all bonuses at login for the current civilization, and store them in the session. Then have the units check a singleton class (static) for the bonuses, instead of them querying the database. As long as the number of bonuses is small this shouldn't create a huge impact on sessions.