A typical approach to storing "old school" game boards is to use a multidimensional char or int array . Using Matt's great little graph , you can see that there are 21 by 21 squares on the board:
int board[21][21] = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, {1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1}, /* ... and so on, for all 21 lines .. */ }};
It doesn't really matter which numbers you choose for walls and paths. The "pathway" positions initially contain the code for "contains a point". Since paccy consumes dots, save the new value on the board in position to indicate that the dot was consumed, but it is still the square of the path. Matt recommended -1 for walls, 0 for a point without a point, and 1 for a point - which is quite a plan, as it allows your wall collision routines to simply search
if (board[pac.x][pac.y] > 0) { /* still in bounds */ } else { /* collided against a wall */ }
The downside is -1 , which looks more uncomfortable in the array initializer.
If this were done in C, it would be quite simple to โimproveโ it with char board[21][21] instead of int board[21][21] and save the playing field as a string C:
char board[21][21] = " XXXXXXXXXXXXXXXXXXX " " XXX " " X XX XXX X XXX XX X " " XX " " X XX X XXXXX X XX X " " XXXXX " " XXXX XXX X XXX XXXX " " XXXX " "XXXXX X XXXXX X XXXXX" " XX " "XXXXX X XXXXX X XXXXX" " XXXX " " XXXX X XXXXX X XXXX " " XXX " " X XX XXX X XXX XX X " " XXXX " " XX XX XXXXX XX XX " " XXXXX " " X XXXXXX X XXXXXX X " " XX " " XXXXXXXXXXXXXXXXXXX";
This is a lot easier to read in the source code, takes up less memory, and your wall collision routines might look like this:
if (board[pac.x][pac.y] == 'X') { /* collided with a wall */ } else { /* still in bounds */ }
(Although the final NUL that the compiler will insert at the end of the line means that the lower right square can never be used for a path or wall - it can take a bit of work, but it's not so pretty.)
I donโt remember enough Java to do this job in Java, but I'm sure you can figure out something if it looks convincing enough.