-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?

4

1 回答 1

2

您可以将每个 Territory 实例的邻居存储在实例中,如下所示:

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

或将所有领土映射到他们的邻居,如下所示:

HashMap<Territory , List<Territory>> neighbours;
于 2015-03-25T21:47:45.847 回答