Exemple #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;
   }
 }
Exemple #2
0
  /** Draw all the game graphics */
  public void draw() {
    Graphics g = environment.getScreenHandler().getCurrentGraphics();
    g.clearRect(
        0,
        0,
        environment.getScreenHandler().getWidth(),
        environment.getScreenHandler().getHeight());
    int gameSizeX = (contAllowed.getSizeX() + contNotAllowed.getSizeX() + 3) * blockSize + 2;
    int gameSizeY = contAllowed.getSizeY() * blockSize + 2;
    g.setColor(Color.white);
    g.drawString(
        "Allowed:", contAllowed.getDrawingPositionX(0), contAllowed.getDrawingPositionY(0) - 3);
    g.drawString(
        "Not allowed:",
        contNotAllowed.getDrawingPositionX(0),
        contNotAllowed.getDrawingPositionY(0) - 3);
    g.setColor(Color.blue);
    g.drawRect(
        contAllowed.getDrawingPositionX(0),
        contAllowed.getDrawingPositionY(0),
        contAllowed.getSizeX() * contAllowed.getSquareSize(),
        contAllowed.getSizeY() * contAllowed.getSquareSize());
    g.drawRect(
        contNotAllowed.getDrawingPositionX(0),
        contNotAllowed.getDrawingPositionY(0),
        contNotAllowed.getSizeX() * contNotAllowed.getSquareSize(),
        contNotAllowed.getSizeY() * contNotAllowed.getSquareSize());

    if (blocksAllowed != null) {
      for (int i = 0; i < blocksAllowed.length; i++) {
        blocksAllowed[i].draw(g);
      }
    }
    if (blocksNotAllowed != null) {
      for (int i = 0; i < blocksNotAllowed.length; i++) {
        blocksNotAllowed[i].draw(g);
      }
    }

    if (selectedBlock != null) {
      g.setColor(Color.white);
      BlockContainerInterface cont;
      if (selectedAllowed) {
        cont = contAllowed;
      } else {
        cont = contNotAllowed;
      }
      g.drawRect(
          selectedBlock.getMovingDrawingPosX(),
          selectedBlock.getMovingDrawingPosY(),
          cont.getSquareSize(),
          cont.getSquareSize());
    }

    g.setColor(Color.white);
    int rightColumnX =
        contNotAllowed.getDrawingPositionX(0) + contNotAllowed.getSizeX() * blockSize + 10;
    g.drawString("Number of empty blocks:", rightColumnX, 100 + 15);
    g.drawString("Number of start blocks:", rightColumnX, 100 + 40);
    g.drawString("Initial time until water:", rightColumnX, 100 + 65);
    g.drawString("Initial water speed:", rightColumnX, 100 + 90);
    g.drawString("Initial blocks to fill:", rightColumnX, 100 + 115);
    rightColumnX = offsetX + gameSizeX + 20;
    g.setColor(Color.red);
    g.drawString("by Erland Isaksson", rightColumnX, offsetY + gameSizeY);
    environment.getScreenHandler().paintComponents(g);
  }