Ejemplo n.º 1
0
  // This method starts a newGame by initializing everything that is necessary before calling the
  // game() method
  public void newGame() {
    // Calls the loadMap method to load the map for the game
    loadMap();

    // Calls the createPlayers method to create the players needed for the game
    createPlayers();

    // Starts the powerup manager to make powerups
    pum.startPowerUps();

    // Makes the gamePanel the only visible panel
    gamePanel.setVisible(true);
    optionsPanel.setVisible(false);
    rulesPanel.setVisible(false);
    controlsPanel.setVisible(false);
    creditsPanel.setVisible(false);
    titlePanel.setVisible(false);

    // Resets some variables needed to play the game
    winPlayer = 5;
    deadPlayers = 0;

    // Calls the game() method to play the game
    game();
  }
Ejemplo n.º 2
0
 // This method makes only the credits panel visible
 public void credits() {
   // Makes only the creditsPanel visible
   gamePanel.setVisible(false);
   optionsPanel.setVisible(false);
   rulesPanel.setVisible(false);
   controlsPanel.setVisible(false);
   creditsPanel.setVisible(true);
   titlePanel.setVisible(false);
 }
Ejemplo n.º 3
0
  // The constructor which sets up all the JFrame, Canvas, JPanels, and sets the buffer strategy.
  public Bomberman() {
    // makes the Canvas visible
    setVisible(true);

    // Creates window and sets it up
    window = new JFrame("BOMBERMAN");
    window.setBounds(0, 0, WIDTH, HEIGHT);
    window.setResizable(false);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.addKeyListener(this);
    setBounds(0, 0, WIDTH, HEIGHT);
    window.getContentPane().setLayout(new CardLayout());

    // Creates the menu bar
    window.setJMenuBar(new Menu());

    // Creates an option panel that has all the options
    optionsPanel = new Options();
    window.getContentPane().add(optionsPanel, "OptionsPanel");

    // Creates a title panel which is the title screen
    titlePanel = new JPanel();
    titlePanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    titlePanel.setLayout(new GridLayout(1, 1));
    titlePanel.add(
        new JLabel(new ImageIcon(getClass().getClassLoader().getResource("titleScreen.png"))));
    window.getContentPane().add(titlePanel, "TitlePanel");

    // Creates and sets up the game panel where the game is played on
    gamePanel = new JPanel();
    gamePanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    gamePanel.setLayout(null);
    gamePanel.add(this);
    window.getContentPane().add(gamePanel, "GamePanel");

    // Creates a rules screen panel which is the rules screen
    rulesPanel = new JPanel();
    rulesPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    rulesPanel.setLayout(new GridLayout(1, 1));
    rulesPanel.add(new JLabel(new ImageIcon(getClass().getClassLoader().getResource("rules.png"))));
    window.getContentPane().add(rulesPanel, "RulesPanel");

    // Creates a controls screen panel which is the controls screen
    controlsPanel = new JPanel();
    controlsPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    controlsPanel.setLayout(new GridLayout(1, 1));
    controlsPanel.add(
        new JLabel(new ImageIcon(getClass().getClassLoader().getResource("controls.png"))));
    window.getContentPane().add(controlsPanel, "ControlsPanel");

    // Creates a controls screen panel which is the controls screen
    creditsPanel = new JPanel();
    creditsPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    creditsPanel.setLayout(new GridLayout(1, 1));
    creditsPanel.add(
        new JLabel(new ImageIcon(getClass().getClassLoader().getResource("credits.png"))));
    window.getContentPane().add(creditsPanel, "CreditsPanel");

    // Makes certain panels visible/invisible
    gamePanel.setVisible(false);
    optionsPanel.setVisible(false);
    rulesPanel.setVisible(false);
    controlsPanel.setVisible(false);
    creditsPanel.setVisible(false);
    titlePanel.setVisible(true);
    window.setVisible(true);

    // double buffering
    createBufferStrategy(2);
    bs = getBufferStrategy();
  }