Beispiel #1
0
 /**
  * Add block to the specified container
  *
  * @param cont Block container that the blocks should be added to
  * @param blocks Array of blocks that the blocks should be added to
  * @param block Blocks that should be added
  * @return Updated copy of the array in the blocks parameter
  */
 protected PipeBlock[] addBlock(
     BlockContainerInterface cont, PipeBlock blocks[], PipeBlock block) {
   boolean bAdded = false;
   for (int x = 0; !bAdded && x < cont.getSizeX(); x++) {
     for (int y = 0; !bAdded && y < cont.getSizeY(); y++) {
       boolean bFound = false;
       for (int i = 0; i < blocks.length; i++) {
         if (x == blocks[i].getPosX() && y == blocks[i].getPosY()) {
           bFound = true;
         }
       }
       if (!bFound) {
         bAdded = true;
         block.init(cont, x, y);
       }
     }
   }
   if (bAdded) {
     PipeBlock[] ret = new PipeBlock[blocks.length + 1];
     for (int i = 0; i < blocks.length; i++) {
       ret[i] = blocks[i];
     }
     ret[blocks.length] = block;
     return ret;
   } else {
     return blocks;
   }
 }
  public void init(BlockContainerInterface cont, int x, int y) {

    PipePart[][] parts = new PipePart[size][size];
    for (int i = 0; i < size; i++) {
      parts[i] = new PipePart[size];
      for (int j = 0; j < size; j++) {
        parts[i][j] = new PipePartNone(environment);
      }
    }

    parts[2][1] = new PipePartLeftRight(environment);
    parts[1][1] = new PipePartRightUp(environment);
    parts[1][0] = new PipePartUpDown(environment);

    super.init(cont, parts, x, y);
  }