Beispiel #1
0
 /**
  * Starts Game.
  *
  * @param pTUI - runs parallel TUI if true
  */
 public void startGame(boolean pTUI) {
   getGraphics().drawImage(imgBackground, 0, 0, getWidth(), getHeight(), this);
   if (pTUI) {
     new TUI(landscape);
   }
   landscape.addAnObserver(this);
   action = ACTION_NORMAL;
   up = false;
   right = false;
   left = false;
   shoot = false;
   player.pause(PAUSE_LONG);
   requestFocus();
   landscape.start();
   new Thread() {
     public void run() {
       while (player.getHealth() > 0 && !player.isInGoal()) {
         player.pause(PAUSE_SHORT);
         if (up) {
           action = ACTION_JUMP;
           landscape.jump();
         }
         if (right) {
           action = ACTION_RIGHT;
           landscape.right();
         }
         if (left) {
           action = ACTION_LEFT;
           landscape.left();
         }
         if (shoot) {
           action = ACTION_SHOOT;
           landscape.shoot();
         }
       }
       if (player.isInGoal()) {
         JOptionPane.showMessageDialog(
             gui, "You won!", "Congratulations!", JOptionPane.INFORMATION_MESSAGE);
       } else if (player.getHealth() == 0) {
         JOptionPane.showMessageDialog(gui, "Player died!", "Game over!", JOptionPane.OK_OPTION);
       }
       main.reset();
     }
   }.start();
 }