# HG changeset patch # User Matti Hamalainen # Date 1296226776 -7200 # Node ID b8fd19e2d87989308e7cc1e2653b54dd1e21dbae # Parent 1785f66a7bebe31f7cce11f34d0c088ffdb8d1e0 Indentation. diff -r 1785f66a7beb -r b8fd19e2d879 game/Piece.java --- a/game/Piece.java Fri Jan 28 16:53:06 2011 +0200 +++ b/game/Piece.java Fri Jan 28 16:59:36 2011 +0200 @@ -13,79 +13,83 @@ public class Piece { - static final int numConnections = 8; - static final int minRotation = 0; - static final int maxRotation = 3; - int currRotation; - int[] connections; - PieceType type, oldType; + static final int numConnections = 8; + static final int minRotation = 0; + static final int maxRotation = 3; + int currRotation; + int[] connections; + PieceType type, oldType; - boolean rotationChanged, rotationActive, - typeChanged, typeActive; - double currAngle, newAngle; + boolean rotationChanged, rotationActive, + typeChanged, typeActive; + double currAngle, newAngle; - - public Piece(PieceType ptype) - { - // Initialize - connections = new int[numConnections]; - type = ptype; + public Piece(PieceType ptype) + { + // Initialize + connections = new int[numConnections]; + type = ptype; - rotationChanged = false; - typeChanged = false; - rotationActive = false; - typeActive = false; + rotationChanged = false; + typeChanged = false; + rotationActive = false; + typeActive = false; + currRotation = 0; + currAngle = 0; - currRotation = 0; - // Initialize connections between endpoints of the paths inside the piece - for (int i = 0; i < numConnections; i++) - connections[i] = -1; + // Initialize connections between endpoints of the paths inside the piece + for (int i = 0; i < numConnections; i++) + connections[i] = -1; - Random rnd = new Random(); - for (int i = 0; i < numConnections; i++) - { - int tmp = rnd.nextInt(numConnections); - if (connections[tmp] < 0 && connections[i] < 0) - { - connections[i] = tmp; - connections[tmp] = i; - } - } - } - - public Piece() - { - this(PieceType.NONE); - } + Random rnd = new Random(); + for (int i = 0; i < numConnections; i++) + { + while (connections[i] < 0) + { + int tmp = rnd.nextInt(numConnections); + if (connections[tmp] < 0) + { + connections[i] = tmp; + connections[tmp] = i; + } + } + } + } + + public Piece() + { + this(PieceType.NONE); + } - public void setType(PieceType ptype) - { - oldType = type; - type = ptype; - } + public void setType(PieceType ptype) + { + typeChanged = (oldType != ptype); + oldType = type; + type = ptype; + } - public int getConnection(int in) - { - return connections[in]; - } + public int getConnection(int in) + { + return connections[in]; + } - public void rotate(boolean dir) - { - if (type != PieceType.NORMAL) - return; + public void rotate(boolean dir) + { + if (type != PieceType.NORMAL) + return; - newRotation = currRotation + (dir ? 1 : -1); + newRotation = currRotation + (dir ? 1 : -1); - if (newRotation < minRotation) - newRotation = maxRotation; - else if (currRotation > maxRotation) - newRotation = minRotation; + if (newRotation < minRotation) + newRotation = maxRotation; + else if (currRotation > maxRotation) + newRotation = minRotation; - rotationDir = dir; - rotationChanged = true; - } + rotationDir = dir; + rotationChanged = true; + } public Point2D getPoint(double x, double y, double dim, int index) {