Coding in Java

T

Terentius

Guest
I was thinking of doing the game like, as a Map: the regions that contain a group of uniformly colored territories are the keys, and the values to those keys is a Set of the territores in that region. I was going to make a Territories class that would contain the territory's name, the region it belongs to, the player occupying it, how many units that player has, and some other stuff.
 
N

Nightstalkers

Guest
Know anything about applet coding and hierarchy structures?
 
T

Terentius

Guest
Applets? Sort of. The guy who sits next to me in class is doing Space Invaders, and he's using an html applet I think.

Heirarchy structures? No.
 
E

EricBess

Guest
Well, I don't know Java, but I know quite a bit about object oriented programming.

I think you are doing fine with a Territories class, but rather than have the territory know what region it is from, you should additionally have a region class.

Are you familiar with linked lists? Does java have a concept of a dynamic array? I suppose since you know the largest number of territories in a region, you can do it with a normal array, but the idea is that at the beginning of each turn, look at each region and determine if all territories in that region are controlled by the turn player. If so, the region class will be able to tell how many additional armies the player receives.

You will need some sort of a list construct anyway, because each territory instance should contain a list of adjacent territories.

You may also want a player class, which tracks a list of all territories a player controls. Yet one more reason for a linked list structure.

Note on linked lists...Don't make a linked list of territories. Make a linked list of nodes where each node points to a territory. That way, you can have multiple linked lists containing the same territory without having to duplicate data (which would NOT be a good idea).

If little of this makes sense because you are not familiar with linked lists, they you will probably need to do a lot more checking each turn to process all of the territories.

For example, each turn, initialize an array of regions to all 0's, then as you process the territories, if the player controls the territory, increment the appropriate region by 1. After looking at all territories, check the counts against the known number of territories in each region to see if the player receives the extra armies.

I don't know how much this helps because I don't know your experience level. The underlying concepts of Risk should actually be quite easy to program if the structures are put together correctly.
 
Top