Exemplo n.º 1
0
  /**
   * Start button listener. Checks if all inputs are valid, if yes creates a new simulator view with
   * the inputs.
   */
  public void startButton() {
    if (mapFile != null && redBrain != null && blackBrain != null) {
      if ((MapInterpreter.mapchecker(mapFile.getAbsolutePath()))
          && AntBrainInterpreterCoryn.antBrainChecker(blackBrain.getAbsolutePath())
          && AntBrainInterpreterCoryn.antBrainChecker(redBrain.getAbsolutePath())) {
        try {

          new DisplayFrame(
              new World(
                  mapFile.getAbsolutePath(),
                  redBrain.getAbsolutePath(),
                  blackBrain.getAbsolutePath()));
        } catch (Exception e) {
          selectMap.getCaptionLabel().set(e.getMessage());
        }
      }
    } else if (mapMap != null && redBrain != null && blackBrain != null) {
      if (AntBrainInterpreterCoryn.antBrainChecker(blackBrain.getAbsolutePath())
          && AntBrainInterpreterCoryn.antBrainChecker(redBrain.getAbsolutePath())) {
        try {

          new DisplayFrame(
              new World(
                  mapMap,
                  new AntBrain(redBrain.getAbsolutePath(), AntColour.RED),
                  new AntBrain(blackBrain.getAbsolutePath(), AntColour.BLACK)));
        } catch (Exception e) {

        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Select map button listener. Activates a file picker on click, and checks if the map is valid.
   * If not makes the button red, else green.
   */
  public void selectMap() {
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      boolean mapTest = false;
      try {
        mapTest = MapInterpreter.mapchecker(file.getAbsolutePath());
      } catch (Exception e) {

      }
      if (mapTest) {
        selectMap.getCaptionLabel().set(shortText(file.getName(), 30));
        selectMap.getCaptionLabel().getStyle().setMarginLeft(10);
        setButtonGreen(selectMap);
        mapFile = file;
        mapMap = null;
        createMap.unlock();
        setButtonGrey(createMap);
        createMap.getCaptionLabel().setText("Random Map").getStyle().setMarginLeft(22);

      } else {
        selectMap.getCaptionLabel().set("Wrong Map");
        setButtonRed(selectMap);
      }
      checkStart();
    }
  }
Exemplo n.º 3
0
 /** Checks if all inputs are valid, if yes sets the start button green else red. */
 public void checkStart() {
   if (mapFile != null && redBrain != null && blackBrain != null) {
     if ((MapInterpreter.mapchecker(mapFile.getAbsolutePath()))
         && AntBrainInterpreterCoryn.antBrainChecker(blackBrain.getAbsolutePath())
         && AntBrainInterpreterCoryn.antBrainChecker(redBrain.getAbsolutePath())) {
       startButton.unlock();
       setButtonGreen(startButton);
     } else {
       setButtonRed(startButton);
       startButton.lock();
     }
   } else if (mapMap != null && redBrain != null && blackBrain != null) {
     if (AntBrainInterpreterCoryn.antBrainChecker(blackBrain.getAbsolutePath())
         && AntBrainInterpreterCoryn.antBrainChecker(redBrain.getAbsolutePath())) {
       startButton.unlock();
       setButtonGreen(startButton);
     } else {
       setButtonRed(startButton);
       startButton.lock();
     }
   }
 }