コード例 #1
0
  /**
   * Colors every unit depending on its owner.
   *
   * @param x the x
   * @param y the y
   */
  private void colorSquareByOwner(int x, int y) {
    JPanel currentSquare = squares[x][y];
    Entity currentEntity = matrix[x][y];

    if (board.isFortress(x, y) || board.isMountainPass(x, y)) {
      if (board.getUnit(x, y) == null) {
        currentSquare.setBackground(COLOR_EMPTY);
        return;
      } else {
        currentEntity = board.getUnit(x, y);
      }
    }
    int owner = currentEntity.getOwner();

    switch (owner) {
      case 0:
        if (!board.isArsenal(x, y)
            && (board.isFighter(x, y) && !((Fighter) currentEntity).isConnected()))
          currentSquare.setBackground(COLOR_PLAYER0);
        else currentSquare.setBackground(COLOR_COM_PLAYER0);
        break;
      case 1:
        if (!board.isArsenal(x, y)
            && (board.isFighter(x, y) && !((Fighter) currentEntity).isConnected()))
          currentSquare.setBackground(COLOR_PLAYER1);
        else currentSquare.setBackground(COLOR_COM_PLAYER1);
        break;
    }
  }
コード例 #2
0
ファイル: SniperRing.java プロジェクト: m15399/TacticalRPG
  public SniperRing(double size, Entity spatialParent) {

    fade = LOW_FADE;

    getPosition().setParent(spatialParent.getPosition());

    getPosition().setScale(size / 2.6, size);
  }
コード例 #3
0
  private ListTerm[] coordinateGroup(
      int group, List<List<Vertex>> actualZones, List<Vertex> bestZone) {
    ListTerm positions = new ListTermImpl();
    ListTerm agents = new ListTermImpl();

    String[] missions;
    if (group == 1) {
      missions = new String[] {"mOccupyZone1", "mRepairZone1"};
    } else if (group == 2) {
      missions = new String[] {"mOccupyZone2", "mRepairZone2"};
    } else {
      missions = new String[] {"mOccupyZone1", "mRepairZone1", "mOccupyZone2", "mRepairZone2"};
    }

    List<Entity> coworkers = model.getCoworkersWithMission(Arrays.asList(missions));

    Graph graph = model.getGraph();

    List<Vertex> groupZone = null;
    if (bestZone != null && !bestZone.isEmpty()) {
      for (List<Vertex> zone : actualZones) {
        if (graph.hasAtLeastOneVertexOnZone(zone, bestZone)) {
          groupZone = zone;
          continue;
        }
      }
    } else if (actualZones != null && !actualZones.isEmpty()) {
      groupZone = actualZones.get(0);
    }

    List<Vertex> targets = new ArrayList<Vertex>();
    if (groupZone == null || groupZone.isEmpty()) {
      if (bestZone != null && !bestZone.isEmpty()) {
        targets.addAll(bestZone);
      }
    } else {
      if (bestZone != null && !bestZone.isEmpty()) {
        bestZone.removeAll(groupZone);
        targets.addAll(bestZone);
      }

      // zone neighbors
      List<Vertex> zoneNeighbors = model.getZoneNeighbors(groupZone);
      // order neighbors by vertex value
      Collections.sort(zoneNeighbors, comparator);

      targets.addAll(zoneNeighbors);
    }

    if (targets.isEmpty()) {
      return new ListTerm[] {agents, positions};
    }

    for (Entity coworker : coworkers) {
      if (coworker.getStatus().equals(Percept.STATUS_DISABLED)) {
        continue;
      }
      Vertex target = null;
      Vertex agentPosition = coworker.getVertex();
      if (bestZone.contains(agentPosition)
          && model.isFrontier(agentPosition)) { // the agent is part of the best zone's frontier
        List<Entity> agsOnSameVertex = model.getCoworkersOnSameVertex(coworker);
        if (!agsOnSameVertex.isEmpty()) { // if there are other agents on the same vertex
          boolean canMove = true;
          for (Entity ag : agsOnSameVertex) {
            if (ag.getId() > coworker.getId()) {
              canMove = false; // only the agent with the lower id can move
              break;
            }
          }
          if (!canMove) {
            continue;
          }
        } else {
          if (model.hasActiveCoworkersOnNeighbors(
              coworker)) { // go to a free neighbor if has two or more coworkers on neighbors
            Vertex neighbor = model.getFreeNeighborOutOfZone(agentPosition);
            if (null != neighbor) {
              agents.add(ASSyntax.createString(coworker.getName()));
              positions.add(ASSyntax.createString("vertex" + neighbor.getId()));
            }
            continue;
          } else {
            continue; // the agent must not move if he is in the frontier and has no other agent on
                      // the same vertex
          }
        }
      }

      if (null != targets && !targets.isEmpty()) {
        //				target = model.closerVertex(agentPosition, targets);
        target = targets.get(0);
        if (null != target) {
          targets.remove(target);
        }
      }

      if (null != target) {
        agents.add(ASSyntax.createString(coworker.getName()));
        positions.add(ASSyntax.createString("vertex" + target.getId()));
      }
    }
    return new ListTerm[] {agents, positions};
  }
コード例 #4
0
  /** Displays the GUI. */
  public void displayGUI() {
    for (int j = 0; j < Board.HEIGHT; j++) {
      for (int i = 0; i < Board.WIDTH; i++) {

        JPanel currentSquare = squares[i][j];
        Entity currentEntity = matrix[i][j];
        // squares[i][j].setBackground(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));
        currentSquare.removeAll();

        if (currentEntity == null) currentSquare.setBackground(COLOR_EMPTY);
        else {
          switch (displayMode) {
            case DISPLAY_UNITS:
              displayUnit(i, j);
              break;
            case DISPLAY_ATTACK:
              resetSelectedSquare();
              displayAttackPotential(i, j);
              break;
            case DISPLAY_DEFENCE:
              resetSelectedSquare();
              displayDefencePotential(i, j);
              break;
            case DISPLAY_DEFENCE_MINUS_ATTACK:
              resetSelectedSquare();
              displayDefenceMinusAttackPotential(i, j);
              break;
            default:
              resetSelectedSquare();
              break;
          }

          if (currentEntity instanceof Mountain) currentSquare.setBackground(COLOR_MOUTAIN);

          if (currentEntity.canContain()) currentEntity = board.getUnit(i, j);

          if (displayMode != DISPLAY_DEFENCE_MINUS_ATTACK) colorSquareByOwner(i, j);
          if (currentEntity instanceof MovableEntity
              && displayMode != DISPLAY_ATTACK_EVAL_TEAM0
              && displayMode != DISPLAY_ATTACK_EVAL_TEAM1
              && displayMode != DISPLAY_DEFENCE_EVAL_TEAM0
              && displayMode != DISPLAY_DEFENCE_EVAL_TEAM1
              && displayMode != DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM0
              && displayMode != DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM1) {
            MovableEntity currentMovable = ((MovableEntity) currentEntity);
            if (currentMovable.canBeKilled()) {
              ((JLabel) currentSquare.getComponent(0))
                  .setText("(" + ((JLabel) currentSquare.getComponent(0)).getText() + ")");
            }
            if (currentMovable.mustRetreat()) {
              ((JLabel) currentSquare.getComponent(0))
                  .setText("[" + ((JLabel) currentSquare.getComponent(0)).getText() + "]");
            }
          }
        }
      }
    }

    if (selectedSquare != null) drawPossibleMovement(selectedSquare.x, selectedSquare.y);
    else drawCommunications();

    if (displayMode == DISPLAY_ATTACK_EVAL_TEAM0) displayAttackEvaluator(0);
    if (displayMode == DISPLAY_ATTACK_EVAL_TEAM1) displayAttackEvaluator(1);

    if (displayMode == DISPLAY_DEFENCE_EVAL_TEAM0) displayDefenceEvaluator(0);
    if (displayMode == DISPLAY_DEFENCE_EVAL_TEAM1) displayDefenceEvaluator(1);
    if (displayMode == DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM0)
      displayDefenceMinusAttackEvaluator(0);
    if (displayMode == DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM1)
      displayDefenceMinusAttackEvaluator(1);

    this.repaint();
    this.setVisible(true);
  }