-4

I'm trying to make a game similar to Risk where each territory on the map is an object of a class I made, Territory. In order to create the game map I would like each Territory object to be linked to the other territories that would be adjacent on the game board. Is there a way in Java to create some kind of data structure that can store all the objects and with links to their "neighbors"? Or is there a way to have objects store references to other objects like you could with pointers in C?

Brent
  • 23
  • 1
  • 4

1 Answers1

2

You can either have the neighbours of every instance of Territory stored in the instance like this:

public class Territory{
     private ArrayList<Territory> neighbours;
}

or map all territorys to their neighbours like this:

HashMap<Territory , List<Territory>> neighbours;