@Override
 public int loop() {
   if (window.isVisible()) {
     return 1000;
   }
   return -1;
 }
Ejemplo n.º 2
0
  // The main method which starts the program. Goes in a loop while the window is still open and
  // while in the loop it displays certain JPanels depending on the variable mode
  public static void main(String[] args) {
    // Creates a Bomberman object
    Bomberman bomberman = new Bomberman();

    // Loads all the images and sprites
    bomberman.load();

    // Loops while the window is open
    while (window.isVisible()) {
      // Depending on mode, a certain JPanel will be made visible by calling a method
      switch (mode) {
        case 1:
          bomberman.options();
          break;
        case 2:
          bomberman.rules();
          break;
        case 3:
          bomberman.controls();
          break;
        case 4:
          bomberman.credits();
          break;
        case 5:
          if (game) bomberman.newGame();
          break;
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  public void actionPerformed(ActionEvent e) {
    AbstractButton button = (AbstractButton) e.getSource();
    try {
      if (button == btnQuit) {
        sendCommand(Command.QUIT);
        socket.close();
        socket = null;
        setButtonStatus(false);
      } else if (button == btnConnection) {
        if (socket == null) connect();
        else if (socket.isConnected()) {
          sendCommand(Command.QUIT);
          Thread.sleep(1000);
          socket.close();

          connect();
        }
      } else if (button == btnReset) {
        sendCommand(Command.RESET);
      } else if (button == btnShutdown) {
        sendCommand(Command.DISPOSE);
      } else if (button == btnSpeed1) {
        sendSpeed(1);
      } else if (button == btnSpeed2) {
        sendSpeed(2);
      } else if (button == btnSpeed3) {
        sendSpeed(3);
      } else if (button == btnSpeed4) {
        sendSpeed(4);
      } else if (button == btnSpeed5) {
        sendSpeed(5);
      } else if (button == btnCamera) {
        if (videoFrame == null || !videoFrame.isVisible()) {
          showVideo();
        } else {
          hideVideo();
        }
      } else if (commandMap.containsKey(button)) {
        sendCommand(commandMap.get(button));
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Ejemplo n.º 4
0
 /**
  * Provides information on visibility of the Canvas.
  *
  * @return true if canvas is visible, false otherwise
  */
 public boolean isVisible() {
   return frame.isVisible();
 }