title: JAVA: Make objects from a 2d array
body: <p>I'm making this game called Rush Hour (where you move the red car).</p>
  
  <p>So far I made a 2D array which reads levels from a text file. Now next up I want to transform the values from the text file to objects so I can start working with coordinates to move them.</p>
  
  <p>To explain my code below a bit: First I'm making a 2D array 6x6, the users gets to choose a difficulty level and depending on what chose they make it will load one of the 4 levels.txt (beginner, intermediate, advanced or expert).</p>
  
  <p>After you picked your level it will load the level in the 2D array (I'll provide a level below the code so you'd have an idea). When the level is loaded it adds a "0" to everything (It looks more user friendly in my eyes) and separates values with the | sign.</p>
  
  <p>So now I think I need to make objects from the values I just read in my 2D array in order to move them (correct me if I'm wrong), I need to check if the values around the numbers match or don't match and if they match I need to combine them.</p>
  
  <p>How do I proceed with this? Thanks in advance</p>
  
  <p>My code so far:</p>
  
  <pre><code>public class Bord {
  private static String[][] bordArray = new String[6][6];
  
  public static void kiesLevel() {
      System.out.println("\nKies moeilijkheidsgraad\n1) Beginner\n2) Intermediate\n3) Advanced\n4) Expert");
      Scanner keyboardScanner = new Scanner(System.in);
      int keuze = keyboardScanner.nextInt();
      switch (keuze) {
          case 1:
              beginner();
              break;
          case 2:
              intermediate();
              break;
          case 3:
              advanced();
              break;
          case 4:
              expert();
              break;
          default:
              throw new NumberFormatException("Geef een geldige invoer");
      }
  }
  
  public static void beginner() {
      leesBordIn("c:/users/Glenn/desktop/beginner.txt");
  
  }
  
  public static void intermediate() {
      leesBordIn("d:/intermediate.txt");
  
  }
  
  public static void advanced() {
      leesBordIn("d:/advanced.txt");
  
  }
  
  public static void expert() {
      leesBordIn("d:/expert.txt");
  
  }
  
  private static void leesBordIn(String filename) {
      try {
          BufferedReader br = new BufferedReader(new FileReader(filename));
          String line = null;
          int r = 0;
          while ((line = br.readLine()) != null) {
              for (int c = 0; c &lt; bordArray[r].length; c++) {
                  if (line.toCharArray()[c] == '0') {
                      bordArray[r][c] = "  ";
                  } else {
                      String characterstring = Character.toString(line.toCharArray()[c]);
                      if (characterstring.length() != 2) {
                          characterstring = "0" + characterstring;
                      }
                      bordArray[r][c] = characterstring;
                  }
                  System.out.print("|" + bordArray[r][c]);
              }
              if (r == 2) {
                  System.out.println("=");
              } else {
                  System.out.println("|");
              }
              r++;
          }
  
  
      } catch (FileNotFoundException e) {
          e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      } catch (IOException e) {
          e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Exmaple of a level:</p>
  
  <pre><code>220007
  300807
  311807
  300800
  400066
  405550
  </code></pre>
  
  <p>Output example:</p>
  
  <pre><code>|02|02|  |  |  |07|
  |03|  |  |08|  |07|
  |03|01|01|08|  |07=
  |03|  |  |08|  |  |
  |04|  |  |  |06|06|
  |04|  |05|05|05|  |
  </code></pre>