Let's say I have a 2D array that represents a board game. I have a list of "values" (keys) (1, 2, 3 ... 12) that represent positions in the array that are relative to the current position.
For example, in array[1][1]
, the key 1 represents the position left array[1][0]
while the key 2 might represent the position left and above it array [0][0]
.
Is there any way to store these two data (I'd like to avoid a bunch of if-statements every time I use the values) in a HashMap? Or, in any data structure? Is this the right time to create an enum?
I tried this, which clearly doesn't work.
int row = 3;
int col = 5;
HashMap<Integer,String> markMap = new HashMap<>();
markMap.put(1,"col-1");
String location = markMap.get(1);
grid[row][(int)location] = 500;