Esempio n. 1
0
 /**
  * add one trap to the Maze at a random location.
  *
  * <p>This requires Cave.setTrap(Trap);
  *
  * @param atrap the Trap
  * @return true if successful
  */
 public boolean addATrap(Trap atrap) {
   Cave c = getRandomEmptyCave();
   if (c != null) {
     c.setTrap(atrap);
     return true;
   } else return false;
 }
Esempio n. 2
0
 /**
  * add each Creature in an array to the Maze, at randomly chosen locations.
  *
  * <p>This requires Cave.setInitialOccupant(Creature)
  *
  * @param cr array of Creatures
  * @return true if ALL creatures successfully added, else false
  */
 public boolean populateMaze(Creature[] cr) {
   boolean OK = true;
   for (int i = 0; i < cr.length; i++) {
     Cave space = getRandomEmptyCave();
     // OK &= cr[i].moveToNewCave(space);
     OK &= space.setInitialOccupant(cr[i]);
   }
   return OK;
 }
Esempio n. 3
0
 /**
  * Return a randomly chosen Cave with no occupant or trap. Or return null if no such Cave found.
  *
  * <p>This requires Cave.hasOccupant() and Cave.hasTrap()
  *
  * @return the Cave
  */
 private Cave getRandomEmptyCave() {
   int count = 0;
   Cave cv;
   boolean OK, test;
   // pick Cave at random until we get an empty one, or until we give up
   do {
     cv = getRandomCave();
     test = cv.hasOccupant() || cv.hasTrap();
     OK = (++count < 10 * rooms.length);
   } while (test & OK);
   if (test) return null;
   else return cv;
 }
Esempio n. 4
0
 /**
  * specify two Caves as mutual neighbours; Each is an exit of the other.
  *
  * <p>This requires Cave.addExit(Cave)
  *
  * @param from
  * @param to
  */
 private void join2(Cave from, Cave to) {
   from.addExit(to);
   to.addExit(from);
 }
Esempio n. 5
0
 /**
  * specify one Cave as an exit from another Cave.
  *
  * <p>This requires Cave.addExit(Cave)
  *
  * @param from
  * @param to
  */
 private void join(Cave from, Cave to) {
   from.addExit(to);
 }
 public void setCaveElement(CaveElement caveElement) {
   cave.fireElementHolderWillChange(this);
   this.caveElement = caveElement;
   cave.fireElementHolderChanged(this);
 }