コード例 #1
0
ファイル: Engine.java プロジェクト: hammerhead399/GRE4KA
  /**
   * Toggle Debug mode, if debug is currently off switch the visible field of all game objects to
   * true.All game objects will be visible. Else switch all of them to false, except for spy and
   * rooms.
   */
  public void toggleDebugMode() {
    if (debug == false) {

      briefCaseRoom.setSymbol("*");

      for (Square[] locations : map) {
        for (Square location : locations) {
          location.setVisible(true);
        }
      }

      // Activate the PowerUps also, in case of ninja step on it
      for (PowerUp powerUp : powerUps) {
        powerUp.setVisible(true);
      }
      debug = true;
    } else {
      briefCaseRoom.setSymbol("R");

      for (Square[] locations : map) {
        for (Square location : locations) {
          location.setVisible(false);
        }
      }

      spy.setVisible(true);

      for (Square[] locations : map) {
        for (Square location : locations) {
          if (isRoom(location)) {
            location.setVisible(true);
          }
        }
      }

      debug = false;
      assignSpyVisibility();
    }
  }
コード例 #2
0
ファイル: Engine.java プロジェクト: hammerhead399/GRE4KA
  /**
   * This method allows the spy to see ahead 2 squares. Remove the darkness mark "X", and switch the
   * visibility of ninjas, powerups to true if they are nearby.
   */
  public void assignSpyVisibility() {
    int row = spy.getRow();
    int col = spy.getCol();

    // Traverse through the spyVisibilityLocations array to switch
    // visibility location from previous turn to false.
    if (!spyVisibilityLocations.isEmpty()) {
      for (Square a : spyVisibilityLocations) {
        if (a.getSymbol().equals(" ")) {
          a.setSymbol("X");
          a.setVisible(false);
        }
        if (isNinja(a) || isPowerUp(a)) {
          a.setVisible(false);
        }
      }
      spyVisibilityLocations.clear();
    }

    for (int i = 0; i < map.length; ++i) {
      for (int j = 0; j < map[i].length; ++j) {

        // looks at the 8 squares right next to the spy
        if (abs(spy.getRow() - i) < 2 && abs(spy.getCol() - j) < 2) {

          // Check for ninjas and powerups near by to switch their
          // visibility to true.
          if (isNinja(map[i][j])) {
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          }

          if (isPowerUp(map[i][j])) {
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          }

          if (map[i][j].getSymbol().equals("X")) {
            map[i][j].setSymbol(" ");
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          } else {
            map[i][j].getSymbol();
          }
        }

        // looks two spaces left and right
        if (j == spy.getCol() && abs(spy.getRow() - i) < 3) {
          if (isNinja(map[i][j])) {
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          }

          if (isPowerUp(map[i][j])) {
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          }

          if (map[i][j].getSymbol().equals("X")) {
            map[i][j].setSymbol(" ");
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          } else {
            map[i][j].getSymbol();
          }
        }

        // looks two spaces up and down
        if (i == spy.getRow() && abs(spy.getCol() - j) < 3) {
          if (isNinja(map[i][j])) {
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          }

          if (isPowerUp(map[i][j])) {
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          }

          if (map[i][j].getSymbol().equals("X")) {
            map[i][j].setSymbol(" ");
            map[i][j].setVisible(true);
            spyVisibilityLocations.add(map[i][j]);
          } else {
            map[i][j].getSymbol();
          }
        }
      }
    }

    // If the spy stands next to a room, switch the visibility of the square
    // behind the room to false.

    if (col == 0) {
      Square behindRoom = null;

      if (isRoom(map[row][col + 1])) {
        behindRoom = map[row][col + 2];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }

        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }
    } else if (col == 8) {
      Square behindRoom = null;

      if (isRoom(map[row][col - 1])) {
        behindRoom = map[row][col - 2];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }
        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }
    } else {
      Square behindRoom = null;

      if (isRoom(map[row][col + 1])) {
        behindRoom = map[row][col + 2];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }

        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }

      if (isRoom(map[row][col - 1])) {
        behindRoom = map[row][col - 2];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }
        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }
    }

    if (row == 0) {
      Square behindRoom = null;

      if (isRoom(map[row + 1][col])) {
        behindRoom = map[row + 2][col];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }

        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }
    } else if (row == 8) {
      Square behindRoom = null;

      if (isRoom(map[row - 1][col])) {
        behindRoom = map[row - 2][col];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }

        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }
    } else {
      Square behindRoom = null;

      if (isRoom(map[row + 1][col])) {
        behindRoom = map[row + 2][col];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }

        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }

      if (isRoom(map[row - 1][col])) {
        behindRoom = map[row - 2][col];

        if (behindRoom.getSymbol().equals(" ")) {
          behindRoom.setSymbol("X");
          behindRoom.setVisible(false);
        }

        if (isNinja(behindRoom) || isPowerUp(behindRoom)) {
          behindRoom.setVisible(false);
        }
      }
    }
  }