Advertisement
Haulien

Untitled

Sep 21st, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. public int addCreature(Creature newCreature) {
  2. // if the passed in creature creature doesn't exist, don't add it
  3. if ( newCreature == null )
  4. {
  5. return -1;
  6. }
  7.  
  8. // if we already contain the creature, don't attempt to add it
  9. if (findCreature(newCreature.getName()) != null) {
  10. return -1;
  11. }
  12.  
  13. // make some room
  14. increaseArray();
  15.  
  16. // assume increaseArray() increases by one
  17. // and the new element is empty...
  18.  
  19. // add the new creature to the list
  20. creatureList[creatureList.length-1] = newCreature;
  21. return creatureList.length-1;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement