title: Running different methods within an object depending on the 'type' of object
body: <p>I'm trying to manage the power-ups in my game.</p>
  
  <p>Lets say I have 7 'platforms' in my game and I want to randomly spawn a power-up with a max of 1 per platform (this is a vertically scrolling 'infinite' type game).</p>
  
  <p>So, I have 5 different power-ups and I could do something like this (Where PowerUp is a valid class) - The '7' being passed into the constructor here is the number of sprites in the individual objects (ie, they are batches of sprites) - 7 so we can place one on each platform and just turn them on and off as required (I have a 'drawable' boolean array which allows me to do this for individual sprites in a batch).</p>
  
  <pre><code>PowerUP powerUp1 = new PowerUp(7);
  PowerUP powerUp2 = new PowerUp(7);
  PowerUP powerUp3 = new PowerUp(7);
  PowerUP powerUp4 = new PowerUp(7);
  PowerUP powerUp5 = new PowerUp(7);
  </code></pre>
  
  <p>I then simply add them to a list of objects to be drawn:</p>
  
  <pre><code>powerUpsList.add(powerUp1); //etc...
  </code></pre>
  
  <p>I can then do something like so:</p>
  
  <pre><code>(for int i = 0; i &lt; powerUpsList.size();i++){
  
      if (powerUpsList.get(i).hasBeenCollected();
              powerUpsList.get(i).runPowerUp(); //Carry out the specific code for this powerup if it has been activated
  }
  </code></pre>
  
  <p>The only issue I have with this is that I'm, in effect creating 35 sprites (5 batches of 7) - more when I add more powreups.  I will <strong>only</strong> ever use a maximum of 7 sprites at once.</p>
  
  <p>Therefore, what I'm trying to do is something like this:</p>
  
  <pre><code> powerUp = new PowerUp(7);
  </code></pre>
  
  <p>Then, when I spawn a powerup, after getting it's type randomly- (so, powerUp1 for example), instead of simply turning the relevant ones on within the relevant batch, I am changing the properties of the specific sprite within the batch.  So if the platform number at time of spawn is 7, I set the frame for the 7th sprite in the batch to the relevant one and then I want to run the code.</p>
  
  <p>However, I seem to have to use a switch statement to switch on the objects enum before I can run the relevant logic.</p>
  
  <pre><code>switch (PowerUpType){
  
      case PowerUpType.powerup1: {logicForPowerUp1;break}
      case PowerUpType.powerup2: {logicForPowerUp2;break}
  
      //etc
  
  }
  </code></pre>
  
  <p>Is there any way I can run the logic cleanly depending on the enum of the object using this batch of 7 sprites?  I can't seem to find a way to do this and using a switch, honestly, I find messy.</p>