Pac-Man Level as a 2D Array

Consider the state of a Pac-Man level:

Pac-Man level

Now, consider the level in terms of a 2D grid:

Pac-Man level

Each horizontal row may be treated as an array of ints:

Pac-Man level

cell contents code
empty 0
small pellet 1
large pellet 2
cherry 3
wall 4
ghost area 5
int[] row0 = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; //top wall

int[] row1 = { 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 }; //next row from top

A 2D array can thus be used to represent the entire level:

int[][] level = {

  { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
  { 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },  
  { 4, 1, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 1, 4, 4, 1, 4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 1, 4 },
  { 4, 2, 4, 0, 0, 4, 1, 4, 0, 0, 0, 4, 1, 4, 4, 1, 4, 0, 0, 0, 4, 1, 4, 0, 0, 4, 2, 4 }, 

  ...rest not shown!...

};
Interested in how the grid overlay was produced? Download this Processing sketch and run with Processing.
Michael Ferraro <mferraro@balstaff.org>