コード例 #1
0
  /**
   * Paints the display of the world, the 9 X 9 grid, which is determined by the locations of each
   * enemy, room, power up, and player.
   *
   * @param number - the input that the user specifies. Used for the look method.
   */
  public void paint(int number) {
    panel.removeAll();
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        int counter = 0;
        if (i == engine.getPlayerRow() && j == engine.getPlayerCol()) {
          counter++;
        }

        for (int r = 0; r < 9; r++) {
          if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) {
            counter++;
          }
        }

        for (int p = 0; p < 3; p++) {
          if (engine.isPowerupActivated(p)) {
            if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p)) {
              counter++;
            }
          }
        }

        for (int e = 0; e < 6; e++) {
          if (i == engine.getEnemyRow(e) && j == engine.getEnemyCol(e) && engine.isEnemyAlive(e)) {
            counter++;
          }
        }
        if (counter > 0) {
          int limit = 0;
          for (int r = 0; r < 9; r++) {
            if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) {
              panel.add(engine.getRoomPic(r));
            }
          }
          if (i == engine.getPlayerRow() && j == engine.getPlayerCol() && limit < 1) {
            panel.add(engine.getSpyPicture());
            limit++;
          }
          for (int e = 0; e < 6; e++) {
            if (i == engine.getEnemyRow(e)
                && j == engine.getEnemyCol(e)
                && limit < 1
                && engine.isEnemyAlive(e)) {
              JLabel imgEnemy = engine.getEnemyPic(e);
              panel.add(imgEnemy);
              engine.hideEnemy(e);
              limit++;
            }
          }

          for (int p = 0; p < 3; p++) {
            if (engine.isPowerupActivated(p)) {
              if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p) && limit < 1) {
                panel.add(engine.getPowerUpPic(p));
                engine.hidePowerup(p);
                limit++;
              }
            }
          }
        } else {
          if (number == 1) {
            if (i == engine.getPlayerRow() - 1 && j == engine.getPlayerCol()) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else if (i == engine.getPlayerRow() - 2 && j == engine.getPlayerCol()) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else // fog
            {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg"));
              panel.add(imgEmpty);
            }
          } else if (number == 2) {
            if (i == engine.getPlayerRow() + 1 && j == engine.getPlayerCol()) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else if (i == engine.getPlayerRow() + 2 && j == engine.getPlayerCol()) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else // fog
            {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg"));
              panel.add(imgEmpty);
            }
          } else if (number == 3) {
            if (i == engine.getPlayerRow() && j == engine.getPlayerCol() - 1) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else if (i == engine.getPlayerRow() && j == engine.getPlayerCol() - 2) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else // fog
            {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg"));
              panel.add(imgEmpty);
            }
          } else if (number == 4) {
            if (i == engine.getPlayerRow() && j == engine.getPlayerCol() + 1) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else if (i == engine.getPlayerRow() && j == engine.getPlayerCol() + 2) {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
              panel.add(imgEmpty);
            } else // fog
            {
              JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg"));
              panel.add(imgEmpty);
            }
          } else // fog
          {
            JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg"));
            panel.add(imgEmpty);
          }
        }
        panel.validate();
      }
    }
  }
コード例 #2
0
  /**
   * Prints the debug version of the display, which so to speak is the mode used to debug the
   * system. This will reveal all enemies and power ups.
   *
   * @param number - the number that the player inputs in order to look around.
   */
  public void debugPaint(int number) {
    panel.removeAll();
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        int counter = 0;
        if (i == engine.getPlayerRow() && j == engine.getPlayerCol()) {
          counter++;
        }

        for (int r = 0; r < 9; r++) {
          if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) {
            counter++;
          }
        }

        for (int p = 0; p < 3; p++) {
          if (engine.isPowerupActivated(p)) {
            if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p)) {
              counter++;
            }
          }
        }

        for (int e = 0; e < 6; e++) {
          if (i == engine.getEnemyRow(e) && j == engine.getEnemyCol(e) && engine.isEnemyAlive(e)) {
            counter++;
          }
        }
        if (counter > 0) {
          int limit = 0;
          for (int r = 0; r < 9; r++) {
            if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) {
              engine.revealRoom(r);
              panel.add(engine.getRoomPic(r));
            }
          }
          if (i == engine.getPlayerRow() && j == engine.getPlayerCol() && limit < 1) {
            panel.add(engine.getSpyPicture());
            limit++;
          }
          for (int e = 0; e < 6; e++) {
            if (i == engine.getEnemyRow(e)
                && j == engine.getEnemyCol(e)
                && limit < 1
                && engine.isEnemyAlive(e)) {
              engine.revealEnemy(e);
              JLabel imgEnemy = engine.getEnemyPic(e);
              panel.add(imgEnemy);
              limit++;
            }
          }
          for (int p = 0; p < 3; p++) {
            if (engine.isPowerupActivated(p)) {
              if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p) && limit < 1) {
                engine.revealPowerup(p);
                panel.add(engine.getPowerUpPic(p));
                limit++;
              }
            }
          }
        } else {
          JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg"));
          panel.add(imgEmpty);
        }

        panel.revalidate();
      }
    }
  }