Exemplo n.º 1
0
  /** Saves the options the user has selected to disk */
  protected void saveOptions() {
    levelFactoryAllowed.saveAllowedBlocks(blocksAllowed);

    int val = 0;
    try {
      String str = textFields[0].getText();
      if (str != null) {
        val = Integer.valueOf(str).intValue();
        levelFactoryAllowed.saveNumberOfEmptyBlocks(val);
      }

    } catch (Exception ex) {
    }
    try {
      String str = textFields[1].getText();
      if (str != null) {
        val = Integer.valueOf(str).intValue();
        levelFactoryAllowed.saveNumberOfStartBlocks(val);
      }

    } catch (Exception ex) {
    }
    try {
      String str = textFields[2].getText();
      if (str != null) {
        val = Integer.valueOf(str).intValue();
        levelFactoryAllowed.saveTimeUntilWater(val);
      }

    } catch (Exception ex) {
    }
    try {
      String str = textFields[3].getText();
      if (str != null) {
        val = Integer.valueOf(str).intValue();
        levelFactoryAllowed.saveWaterSpeed(val);
      }

    } catch (Exception ex) {
    }
    try {
      String str = textFields[4].getText();
      if (str != null) {
        val = Integer.valueOf(str).intValue();
        levelFactoryAllowed.saveLeftToFill(val);
      }

    } catch (Exception ex) {
    }
  }
Exemplo n.º 2
0
  public void init(GameEnvironmentInterface environ) {
    this.environment = environ;
    this.contAllowed = new BlockContainerData(offsetX + 1, offsetY + 20, 3, 10, blockSize);
    this.contNotAllowed =
        new BlockContainerData(offsetX + 1 + 6 * blockSize, offsetY + 20, 3, 10, blockSize);
    levelFactoryAllowed =
        new LevelFactory(environment, contAllowed, LevelFactory.GameType.UntilWaterStopped);
    levelFactoryNotAllowed =
        new LevelFactory(environment, contNotAllowed, LevelFactory.GameType.UntilWaterStopped);

    int rightColumnX =
        contNotAllowed.getDrawingPositionX(0) + contNotAllowed.getSizeX() * blockSize + 10;
    buttons = new EButton[4];
    buttons[0] = EButton.create("Save");
    buttons[0].getComponent().setBounds(rightColumnX, offsetY + 20, 73, 25);
    buttons[1] = EButton.create("Exit");
    buttons[1].getComponent().setBounds(rightColumnX, offsetY + 50, 73, 25);
    buttons[2] = EButton.create("-->");
    buttons[2]
        .getComponent()
        .setBounds(offsetX + contAllowed.getSizeX() * blockSize + 10, offsetY + 50, 73, 25);
    buttons[3] = EButton.create("<--");
    buttons[3]
        .getComponent()
        .setBounds(offsetX + contAllowed.getSizeX() * blockSize + 10, offsetY + 80, 73, 25);
    if (buttons != null) {
      for (int i = 0; i < buttons.length; i++) {
        buttons[i].addActionListener(this);
        environment.getScreenHandler().add(buttons[i].getComponent());
      }
    }
    textFields = new TextField[5];
    textFields[0] = new TextField(String.valueOf(levelFactoryAllowed.getNumberOfEmptyBlocks()), 2);
    textFields[0].setBounds(rightColumnX + 150, 100 + 3, 40, 18);
    textFields[0].setBackground(Color.white);
    textFields[1] = new TextField(String.valueOf(levelFactoryAllowed.getNumberOfStartBlocks()), 2);
    textFields[1].setBounds(rightColumnX + 150, 100 + 28, 40, 18);
    textFields[1].setBackground(Color.white);
    textFields[2] = new TextField(String.valueOf(levelFactoryAllowed.getTimeUntilWater()), 2);
    textFields[2].setBounds(rightColumnX + 150, 100 + 53, 40, 18);
    textFields[2].setBackground(Color.white);
    textFields[3] = new TextField(String.valueOf(levelFactoryAllowed.getWaterSpeed()), 2);
    textFields[3].setBounds(rightColumnX + 150, 100 + 78, 40, 18);
    textFields[3].setBackground(Color.white);
    textFields[4] = new TextField(String.valueOf(levelFactoryAllowed.getLeftToFill()), 2);
    textFields[4].setBounds(rightColumnX + 150, 100 + 103, 40, 18);
    textFields[4].setBackground(Color.white);
    for (int i = 0; i < textFields.length; i++) {
      environment.getScreenHandler().add(textFields[i]);
    }

    selectedBlock = null;
    blocksAllowed = levelFactoryAllowed.getAllowedBlocks();
    blocksNotAllowed = levelFactoryNotAllowed.getNotAllowedBlocks();
    bExit = false;
    mouseListener =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if ((e.getModifiers() & e.BUTTON1_MASK) != 0) {
              handleLeftMouseClicked(
                  environment.getScreenHandler().getScreenX(e.getX()),
                  environment.getScreenHandler().getScreenY(e.getY()));
            }
          }
        };
    environment.getScreenHandler().getContainer().setBackground(Color.black);
    environment.getScreenHandler().getContainer().requestFocus();
    environment.getScreenHandler().getContainer().addMouseListener(mouseListener);
  }