visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java
changeset 253 ee02205edf13
parent 252 2769784e86da
child 254 1273bfb0e2e7
     1.1 --- a/visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java	Sun Sep 05 07:07:35 2010 +0200
     1.2 +++ b/visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java	Sun Sep 05 11:04:26 2010 +0200
     1.3 @@ -37,12 +37,10 @@
     1.4  import java.awt.Font;
     1.5  import java.awt.Graphics;
     1.6  import java.awt.Graphics2D;
     1.7 -import java.awt.GridLayout;
     1.8  import java.awt.Rectangle;
     1.9  import java.awt.event.MouseEvent;
    1.10  import java.awt.event.MouseMotionListener;
    1.11  import java.awt.image.BufferedImage;
    1.12 -import javax.swing.JComponent;
    1.13  import javax.swing.JFrame;
    1.14  import javax.swing.JPanel;
    1.15  
    1.16 @@ -128,7 +126,7 @@
    1.17              int row = 8 - p.getRow();
    1.18              final boolean isCurrent = p == board.getCurrentPlayer();
    1.19              final Color currentColor = colors[cnt];
    1.20 -            drawPlayer(g, column, row, currentColor, isCurrent);
    1.21 +            drawPlayer(g, column, row, currentColor, isCurrent, false);
    1.22              cnt++;
    1.23          }
    1.24  
    1.25 @@ -145,7 +143,7 @@
    1.26          }
    1.27      }
    1.28  
    1.29 -    private void drawPlayer(Graphics2D g, int column, int row, final Color currentColor, final boolean isCurrent) {
    1.30 +    private void drawPlayer(Graphics2D g, int column, int row, final Color currentColor, final boolean isCurrent, boolean allowedMove) {
    1.31          int fifth = fieldSize / 10;
    1.32          int diametr = fieldSize - fifth * 4;
    1.33          final Rectangle r = new Rectangle(
    1.34 @@ -155,8 +153,13 @@
    1.35              diametr
    1.36          );
    1.37          if (currentColor == null) {
    1.38 -            g.setColor(Color.BLACK);
    1.39 -            g.drawOval(r.x, r.y, r.width, r.height);
    1.40 +            if (allowedMove) {
    1.41 +                g.setColor(Color.BLACK);
    1.42 +                g.drawOval(r.x, r.y, r.width, r.height);
    1.43 +            } else {
    1.44 +                g.drawLine(r.x, r.y, r.x + r.width, r.y + r.height);
    1.45 +                g.drawLine(r.x, r.y + r.height, r.x + r.width, r.y);
    1.46 +            }
    1.47          } else {
    1.48              g.setColor(currentColor);
    1.49              g.fillOval(r.x, r.y, r.width, r.height);
    1.50 @@ -166,7 +169,7 @@
    1.51              }
    1.52          }
    1.53      }
    1.54 -
    1.55 +    
    1.56      private void drawFence(Orientation orient, int column, int row, Graphics2D g, boolean fill) throws IllegalStateException {
    1.57          int fifth = fieldSize / 10;
    1.58          int w, h;
    1.59 @@ -217,7 +220,12 @@
    1.60          if (outOfX && outOfY) {
    1.61              x = (e.getX() - xdelta) / fieldSize;
    1.62              y = (e.getY() - ydelta) / fieldSize;
    1.63 -            drawPlayer(d2, x, y, null, false);
    1.64 +            Move m = board.findMove(board.getCurrentPlayer(), x, 8 - y);
    1.65 +            if (m == null) {
    1.66 +                drawPlayer(d2, x, y, null, false, false);
    1.67 +            } else {
    1.68 +                drawPlayer(d2, x, y, null, false, true);
    1.69 +            }
    1.70              getGraphics().drawImage(img, 0, 0, null);
    1.71              return;
    1.72          }