0

I want to add a trail to a player on a grid, similar to that of the game "Snake." However, when I go to make an array list, I get an error. Here is the code for creating it.

ArrayList<Integer, Integer> trail = new ArrayList<Integer, Integer>();

I get the error "Incorrect number of arguments."

How am I supposed to make this to keep track of which coordinates have been gone over by the player?

Dave
  • 4,282
  • 2
  • 19
  • 24
Kinoscorpia
  • 368
  • 3
  • 6
  • 18

4 Answers4

4

Make a class Pair which will look like something like this:

class Pair {
    public int x, y;
} 

or you can use predefined java.awt.Point class. Then in your code use

ArrayList<Pair> 

instead of

ArrayList<Integer, Integer>.
Jimmy
  • 276
  • 1
  • 8
1

Array list only takes one arguement. You can refer to this link here.

Solution to your problem is you can use hash map or double dimension array as per your requirement.

Community
  • 1
  • 1
thestrongenough
  • 225
  • 2
  • 14
0

ArrayList takes only one argument, like this:

 ArrayList<Integer> trail = new ArrayList<Integer>();

If you need to store a key and a value, use HashMap

HashMap<Integer, Integer> trail = new HashMap<Integer, Integer>();
vinitius
  • 3,212
  • 2
  • 17
  • 22
0

You can also make a Arraylist of integer array like new Arraylist;

Erwin Kraan
  • 268
  • 3
  • 8