/**
   * Gestion des événements des divers éléments du panel (menu, bouttons, etc.).
   *
   * @param ae l'événement associé à une action
   */
  public void actionPerformed(ActionEvent ae) {
    Object source = ae.getSource();
    Tower tour = null;

    if (source == bTourArcher) tour = new Tower_Archer();
    else if (source == bTourCanon) tour = new Tower_Canon();
    else if (source == bTourAntiAerienne) tour = new Tower_AntiAerial();
    else if (source == bTourDeGlace) tour = new Tower_Ice();
    else if (source == bTourDeFeu) tour = new Tower_Fire();
    else if (source == bTourDAir) tour = new Tower_Air();
    else if (source == bTourDeTerre) tour = new Tower_Earth();
    else if (source == bTourElectrique) tour = new Tower_Electric();
    else return;

    tour.setProprietaire(jeu.getJoueurPrincipal());

    edpt.tourSelectionnee(tour, Panel_InfoTour.MODE_ACHAT);
    edpt.setTourAAcheter(tour);
  }
 public void paintComponent(Graphics g) { // display
   if (isFirst) {
     myWidth = getWidth();
     myHeight = getHeight();
     define();
     isFirst = false;
   }
   g.clearRect(0, 0, getWidth(), getHeight());
   room.draw(g); // draw map
   store.draw(g); // draw sidebar
   // b.draw(g);
   theMinion.draw(g);
   if (to != null) { // tower selected movement
     to.draw(g, xval, yval, to);
   }
   for (Tower i : tplace) {
     i.draw(g, i);
   }
 }
Beispiel #3
0
  /** Called after a new tower is added. Redraws the city. */
  private void redraw() {
    towerLayer.removeAll(); // clear the view
    // OPTIM...you don't need to removeAll...just use setBounds and then revalidate! or?

    for (int i = 0; i < towers.size(); i++) {
      Tower t = (Tower) towers.get(i);
      for (int j = 0; j < t.floors.size(); j++) {
        Tower.Floor f = t.getFloor(j);
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridwidth = 1; // f.getComponents().length;
        gbc.gridheight = 1;
        gbc.fill = java.awt.GridBagConstraints.NONE; // NONE
        gbc.anchor = java.awt.GridBagConstraints.CENTER;
        gbc.weightx = 1.0; // 0.
        gbc.weighty = 1.0; // 0.
        gbc.insets = FIELD_INSETS;
        gbc.gridx = i;
        gbc.gridy = maxDegree - f.getDegree();
        towerLayer.add(f, gbc);
      }
    }
    towerLayer.revalidate();
  }
Beispiel #4
0
  /**
   * Add <CODE>newguy</CODE> to the list of all fields in this city
   *
   * @param newguy the NumberField to add
   * @see #allFields
   */
  protected void addField(NumberField newguy) {
    boolean fatal = false;
    if (population >= MAX_POPULATION) {
      GiANT.gui.appendConsoleText(
          "\nUnable to add numberfield; maximum population of " + MAX_POPULATION + " reached.",
          true);
      fatal = true;
    } else if (allFields.contains(newguy)) {
      GiANT.gui.appendConsoleText(
          "\nUnable to add numberfield. It duplicates one already displayed.", true);
      fatal = true;
    }

    if (fatal) return;
    // we will need to know all subfields of this cat...
    determineSubfields(newguy);
    // System.err.println("entering addField()");
    // TODO do not allow duplicate (isomorphic) numberfields to be added

    boolean homeless = true; // we have yet to find a place for newguy
    boolean redraw = false;
    // update maxDegree
    final int newDeg = newguy.getDegree();
    if (newDeg > maxDegree) {
      maxDegree = newDeg;
      redraw = true;
    }

    // search all towers, left to right
    towers:
    for (int i = 0; i < towers.size(); i++) {
      Tower t = (Tower) towers.get(i);

      // boolean flags for existence of [proper] superfields / subfields
      boolean hasSuper = false;
      boolean hasSub = false;

      final int insert = t.findInsertionIndex(newguy);

      boolean hasEqual = false;
      Tower.Floor f = null;
      if (insert == t.getHeight()) {
        // nothing to check; we are outside of the current tower array
      } else {
        f = t.getFloor(insert);
        if (f.getDegree() == newDeg) hasEqual = true;
      }

      Tower.Floor above = null;
      Tower.Floor below = null;
      if (insert == 0) { // we are at the top of the tower
        hasSuper = true; // super is C
        int fetch = 0;

        if (hasEqual) fetch = 1;

        if (fetch >= t.getHeight()) {
          hasSub = true; // there are no towers below, sub is Q
        } else {
          below = t.getFloor(fetch);
          if (below.allSubfieldsOf(newguy)) hasSub = true;
        }
      } else if (insert == t.getHeight()) { // we are at the very bottom of the tower
        hasSub = true; // sub is Q itself

        above = t.getFloor(t.getHeight() - 1);

        if (above.allSuperFieldsOf(newguy)) hasSuper = true;
      } else { // we are somewhere WITHIN the tower
        if (hasEqual) {
          above = t.getFloor(insert - 1);
          if (insert == t.getHeight() - 1) hasSub = true; // sub is Q
          else below = t.getFloor(insert + 1);
        } else {
          above = t.getFloor(insert - 1);
          below = t.getFloor(insert);
        }

        if (above.allSuperFieldsOf(newguy)) hasSuper = true;
        if (hasSub) {
          // do nothing
        } else { // test for the same
          if (below.allSubfieldsOf(newguy)) hasSub = true;
        }
      }

      if (hasSub && hasSuper) {
        if (hasEqual) // kkl
        if (!f.allSubfieldsOf(
              newguy)) // could also use allSuperfieldsOf(), we need to make sure all fields this
                       // floor are isomorphic to newguy...
          continue towers; //
        homeless = false;
        t.add(insert, hasEqual, newguy);
        break towers;
      }
    }

    if (homeless) { // then build a new tower for newguy
      Tower newT = newTower();
      newT.add(0, false, newguy);
    }

    population++; // one more citizen!
    allFields.add(newguy); // add him to the set of all fields
    // if(redraw) //OPTIM
    redraw();
    GiANT.gui.repaint();
    // System.err.println("exiting addField()");
  }
Beispiel #5
0
  /**
   * Draw the lines connecting fields on the desktop. These lines represent super-/subfield
   * relations.
   *
   * @param g The Graphics context on which to draw the lines
   * @see #linesLayer
   */
  private void drawLines(Graphics g) {
    java.awt.Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(
        java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);

    final Point Q = getCenterLocation(QLabel);

    for (int i = 0; i < towers.size(); i++) {
      Tower t = (Tower) towers.get(i);
      g2.setColor(COLORS[i % COLORS.length]);
      boolean bottom = false;
      for (int j = 0; j < t.floors.size(); j++) {
        if (j == t.floors.size() - 1) bottom = true;
        Tower.Floor f = (Tower.Floor) t.getFloor(j);
        // iterate over all fields this floor
        Component[] fields = f.getComponents();
        for (int k = 0; k < fields.length; k++) {
          NumberField a = (NumberField) fields[k]; // line origin
          Point p1 = getCenterLocation(a.getCenterComponent()); // get center

          for (int l = 0; l < towers.size(); l++) {
            if (i == l) // use different colors for drawing within/without towers
            g2.setStroke(IN_LINE);
            else g2.setStroke(OUT_LINE);
            Tower t2 = (Tower) towers.get(l);
            // pen color changes according to destination tower
            // that way all 'sets of subsets' are monochrome
            // g2.setColor(COLORS[l % COLORS.length]);
            floors:
            for (int m = 0; m < t2.floors.size(); m++) {
              Tower.Floor f2 = (Tower.Floor) t2.getFloor(m);
              // iterate over all fields this floor
              boolean done = false;
              Component[] fields2 = f2.getComponents();
              for (int n = 0; n < fields2.length; n++) {
                NumberField b = (NumberField) fields2[n]; // line destination
                if (i == l & j == m) { // we are within a floor{
                  if (k == n) ; // do nothing (don't draw to yourself)
                  else { // to do, maybe have different lines for isomorphy?
                    Point p2 = getCenterLocation(b.getCenterComponent()); // get center
                    g2.drawLine(p1.x, p1.y, p2.x, p2.y);
                    done = true;
                  }
                } else if (a.hasSubfield(b) && !a.subfieldHasProperSubfield(b)) {
                  Point p2 = getCenterLocation(b.getCenterComponent()); // get center
                  g2.drawLine(p1.x, p1.y, p2.x, p2.y);
                  done = true;
                }
              }
              // go to the next tower; only need to draw to ONE floor per tower
              if (done) break floors;
            }
          }
          if (bottom && a.hasNoProperSubfields()) { // bottom of tower, no lines out of tower...
            g2.setColor(COLORS[i % COLORS.length]);
            g2.setStroke(IN_LINE);
            g2.drawLine(p1.x, p1.y, Q.x, Q.y); // then draw to Q!
          }
        }
      }
    }
  }