title: Collision Detection returning a value derived from the image filename
body: <p>I'm currently in the process of building a small Asteroids style game which is intended for use by the kids at a local junior school. The aim is to help them with their times-tables.</p>
  
  <p>A randomly generated question is displayed on-screen, (example: 6 * ? = 12), and a number of star images with numbers on them are floating around, waiting to be be shot at! You control a ship and fly around hunting the correct answer.</p>
  
  <p>Bullets collide with the stars and a test needs to be performed to see if the user has shot the correct answer or not.</p>
  
  <p>The star's filenames are simply "1.png", "2.png" etc, and I have a small function to return the first character of the filename, and convert it to an int:</p>
  
  <pre><code>public rightAnswer() {
  
      String filename = "12.png";     //would be passed as parameters 
      int coefficient = 2;            //
      int answer = 24;                //
  
      char first = filename.charAt(0);
      char second = filename.charAt(1);       
      int target;
  
      if (second != '.') {    //dealing only with 1 or 2-digit numbers        
  
          String both = String.valueOf(first) + String.valueOf(second);           
          target = Integer.parseInt(both);
      }
      else {
          target = Character.digit(first, 10);
      }
  
      if (target * coefficient == answer) {
          System.out.println("Answer is correct! (target = " + target + ")");
      }
      else {
          System.out.println("Wrong! (target = " + target + ")");
      }
  }
  </code></pre>
  
  <p>While writing I got struck by a problem. I can't figure out how to retrieve the filename of the collided star to pass it to the above test function.</p>
  
  <p>edit: </p>
  
  <p>taking a shot at Enno Shioji's solution, I've come to this:</p>
  
  <pre><code>//star map
  Map&lt;ImageEntity, Integer&gt; star_number = new HashMap&lt;ImageEntity, Integer&gt;();
  
  //later, while loading the images into the game...
  for (int n = 0; n &lt; 10; n++) {          // 10 loops
  
          stars[n] = new ImageEntity(this);
          String filename = (n+2) + ".png";   // 2- 12 range
          stars[n].load(filename);
  
          star_number.put(stars[n], n+2);
      }
  
  //then later again, run when collision is detected between a bullet and a star...
  public boolean correctAnswer(ImageEntity star, int expectedAnswer) {
  
      if (star_number.get(star) == expectedAnswer) 
          return true;
  
      else return false;
  }
  </code></pre>
  
  <p>Is this looking right? </p>