Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm just trying to figure out how to set up the code for a game like risk...

I would like it to be extensible, so that I can have multiple maps (ie- World, North America, Eurasia, Africa) so hardcoding in the map doesn't seem to make a whole lot of sense

I'm a bit confused on how/where items should be stored/accessed.

Here are the objects I see the game theoretically using: -Countries/Territories -Cities (Can be contained within territories) -Capitols -Connections -Continents -Map -Troops

At the moment, I feel like: -A map should have a list of continents and countries. The continents would be more of a 'logical' thing where the continents would just be lists of countries that are checked for bonuses at the start of turns -Countries should have a list of countries that they're connected to for the connections

What I can't figure out is: Where do I store the troops? Do I have an object for every single troop or do I just store the number of troops on a country object as an integer?

What about capitols and cities? Do those just have a reference to the country they reside in?

Is there anything I'm not seeing here that's going to screw me over in the long run with the way that I'm thinking about things now?

Any advice would be appreciated.

share|improve this question
    
when you store the troops, if you did it just as a number how would you know what player owns those troops? might want to include that in the object –  TMP Sep 19 '12 at 15:35
    
The troops would most likely get stored on the country and the owner of the country would be the one that owns those troops. –  jyanks Sep 20 '12 at 4:25
add comment

2 Answers

up vote 3 down vote accepted

I would keep data tables (in a file most likely), then read at the start and stored into classes, using IDs, something like:

Continents: 
ID, Display 
-------------------
NA, North America 
SA, South America 
EU, Europe
AS, Asia 
etc

Countries:
ID, Display, Continent ID, Capital City ID (see below for City list)
------------------
CA, Canada, NA, OT
US, United States, NA, WA
MX, Mexico, NA, MC
RS, Russia, EU, MO // Ha, EU or AS (I Googled it, they didn't even know!)
etc

Country Connection:
ID, Connected To
-------------------
CA, US
CA, RS
US, CA
US, MX
MX, US
etc

Technically, since MX is connected to US, therefore you don't need the 'redundant' entry saying US is connected to MX. But this style is easy for looking up connections based on the current country you are querying, and not have to check all entries etc. Also, as a bonus feature, this way lets you define 'one way' relationships for whatever reason. US can access MX, but maybe MX can't access US (terrain issues, country capabilities such as no navy presence, etc).

For cities, the ID should be unique across the entire world, no duplicates, so a four letter number / code would be recommended:

Cities:
ID, Country ID, Display
-----------------------
TO, CA, Toronto
OT, CA, Ottawa
DT, US, Detroit
NY, US, New York
MC, MX, Mexico City
MO, RS, Moscow
etc

If you want to track which cities connect to other cities (spanning country borders too):

City Connection:
TO, OT // Toronto connects to Ottawa
TO, DT // Toronto connects to Detroit
etc

Then to keep track of troops, track each player separately, using perhaps dynamic lists, such as (and update when new countries are lost / acquired):

Player Troops:
Player ID, Country ID, Qty
------------------
01, CA, 5 // Player 01 has 5 troops in Canada
01, US, 7 // Player 01 has 7 troops in the US
02, MX, 14 // Player 02 has 14 troops in Mexico
etc

If you want to track troops in cities rather than countries, use the city id instead. If there is only one style of troop, the above works. But if you have multiple troop styles (navy, land, air force) then give each style an ID, and update the above to something like:

01, NV, CA, 5 // Player 01 has 5 NAVY troops in Canada
01, AF, CA, 14 // Player 01 has 14 AIRFORCE troops in Canada
etc

You could even store each countries' borders as polygon lines in a table, for displaying, or checking if a country is clicked, or highlighting, etc.

[EDIT] Thinking over this I think I would create a 'troops' class, and a 'player' class that has an instance of a 'troop' object. The troop class would have no reference to any player. I was thinking too 'databasey' at the time!

share|improve this answer
add comment

Slydog's answer answers most of your questions, i guess. I would prefer to have this answer as a comment, as it may not contribute to what you are looking for here but I don't have the permissions to comment and I don't want that to stop me from giving my contribute to eventually help you.

Anyway, if you need a database with polygon information about countries borders, etc, there are a couple online. For example this: http://thematicmapping.org/downloads/world_borders.php

share|improve this answer
    
Great resource! Ha, in my first answer I ever made, I wanted to make it a comment too, but didn't have the permissions yet. It even got a few votes! –  Doug.McFarlane Sep 19 '12 at 17:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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