示例#1
0
  public void paintComponent(Graphics g) {
    final Color bg = getBackground();
    final Insets insets = getInsets();

    if (shouldPaintBg) {
      super.paintComponent(g);

      if ((bg != null) && (bg.getAlpha() > 0)) {
        g.setColor(bg);
        g.fillRect(
            insets.left,
            insets.top,
            getWidth() - (insets.left + insets.right),
            getHeight() - (insets.top + insets.bottom));
      }
      if (!clear) {
        shouldPaintBg = false;
        setOpaque(true);
      }
    }
    if (pen != null) {
      if (pen.getAbsCoords()) {
        pen.paintIcon(this, g, 0, 0);
      } else {
        pen.paintIcon(this, g, insets.left, insets.top);
      }
    }
  }
示例#2
0
 int set(int pen, int fence, int player) {
   if (pen < 1 || pen > size) pen = 1;
   Pen p = get(pen);
   if (p.closed()) {
     fence = 0;
     boolean success = false;
     for (int i = pen + 1; i != pen; i++) {
       if (i > size) i = 1;
       if (i == pen) break;
       if (!get(i).closed()) {
         p = get(i);
         success = true;
         break;
       }
     }
     if (!success) return -1;
   }
   if (fence < 0 || fence >= sides) fence = 0;
   int[] f = p.fences;
   if (f[fence] != 0) {
     for (int i = fence + 1; i != fence; i++) {
       if (i >= sides) i = 0;
       if (fence == i) break;
       if (f[i] == 0) {
         fence = i;
         break;
       }
     }
   }
   int score = 0;
   pp.players.get(player - 1).moves.add(new int[] {p.id(), fence});
   Pen[] both = new Pen[] {p, p.n(fence)};
   int[] fs = new int[] {fence, (fence + sides / 2) % sides};
   for (int i = 0; i < 2; i++) {
     int[] f2 = both[i].fences;
     f2[fs[i]] = player;
     if (PigPen.output && both[i].id != -1)
       PigPen.out.println("F: " + both[i].id + " " + fs[i] + " " + player);
     if (both[i].remaining() == 0) {
       score = 1;
       both[i].winner = player;
       scores[player]++;
       if (PigPen.output) PigPen.out.println("W: " + both[i].id + " " + player);
     }
   }
   return score;
 }
  /* (non-Javadoc)
   * @see maptool.model.drawing.Drawable#draw(java.awt.Graphics2D, maptool.model.drawing.Pen)
   */
  public void draw(Graphics2D g, Pen pen, int translateX, int translateY) {
    if (pen == null) {
      pen = Pen.DEFAULT;
    }

    Stroke oldStroke = g.getStroke();
    g.setStroke(new BasicStroke(pen.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    Composite oldComposite = g.getComposite();
    if (pen.isEraser()) {
      g.setComposite(AlphaComposite.Clear);
    }

    if (pen.getBackgroundMode() == Pen.MODE_SOLID) {
      Color bgColor = new Color(pen.getBackgroundColor());
      g.setColor(bgColor);
      drawBackground(g, translateX, translateY);
    }

    if (pen.getForegroundMode() == Pen.MODE_SOLID) {
      Color color = new Color(pen.getColor());
      g.setColor(color);
      draw(g, translateX, translateY);
    }

    g.setComposite(oldComposite);
    g.setStroke(oldStroke);
  }