/* @(#)GameShapes.java 25 September 2007 */ import edu.neu.ccs.*; import edu.neu.ccs.gui.*; import edu.neu.ccs.util.*; import java.awt.*; import java.awt.geom.*; /** *

Class GameShapes constructs shapes * for the Concentration game.

*/ public class GameShapes { /** Prevent instantiation. */ private GameShapes() { } /** *

Returns the regular polygon shape with * the given number of vertices, * and the given jump between vertices.

* *

The value of vertices is forced to at least 3.

* *

Uses RegularShape.star.

*/ public static Shape regularStar (double x, double y, double r, int vertices, int jump) { return RegularShape.star(x, y, r, vertices, jump); } /** *

Returns a polygon vertex as a float[] * for use in the automatic shape tools.

* *

The angle in degrees is measured clockwise from * the vertical (north).

*/ public static float[] makeVertex (double x, double y, double r, double degrees) { double s = MathUtilities.sindeg(degrees); double c = MathUtilities.cosdeg(degrees); double xx = x + r * s; double yy = y - r * c; return new float[] { (float) xx, (float) yy }; } /** *

Returns the regular wavygon shape with * the given number of outer and inner vertices.

* *

A wavygon is defined as a closed curve * with the given number of vertices * on an outer circle of the given radius r * together with an equal number of vertices * mixed in on an inner circle of radius r/2. * This makes a wavygon a curved star.

* *

The value of vertices is forced to at least 3.

*/ public static Shape regularWavygon (double x, double y, double r, int vertices) { if (vertices < 3) vertices = 3; float[][] data = new float[2 * vertices][2]; double degrees = 0; double delta = 180.0 / vertices; double inner = r / 2; int j = 0; for (int i = 0; i < vertices; i++) { data[j] = makeVertex(x, y, r, degrees); degrees += delta; j++; data[j] = makeVertex(x, y, inner, degrees); degrees += delta; j++; } return new AutomaticShape (data, null, Tangent.chordStrategy(1.0f / 4.0f), Path.BEZIER_CUBIC); } /** *

Returns a shape consisting of radial spokes, * one for each of the given number of vertices.

* *

The value of vertices is forced to at least 1.

*/ public static Shape regularSpokes (double x, double y, double r, int vertices) { if (vertices < 1) vertices = 1; Shape[] shapes = new Shape[vertices]; double degrees = 0; double delta = 360.0 / vertices; for (int i = 0; i < vertices; i++) { float[] vertex = makeVertex(x, y, r, degrees); shapes[i] = new Line2D.Double(x, y, vertex[0], vertex[1]); degrees += delta; } return Path.append(null, shapes, false); } /**

Returns the filled game shapes for Concentration.

*/ public static Shape[] getFilledGameShapes() { return new Shape[] { new XCircle(50, 50, 46), new XSquare(50, 50, 46), regularStar(50, 50, 46, 3, 1), regularStar(50, 50, 46, 4, 1), regularStar(50, 50, 46, 5, 1), regularStar(50, 50, 46, 6, 1), regularStar(50, 50, 46, 5, 2), regularStar(50, 50, 46, 6, 2), regularStar(50, 50, 46, 7, 3), regularStar(50, 50, 46, 8, 3), regularWavygon(50, 50, 46, 3), regularWavygon(50, 50, 46, 4), regularWavygon(50, 50, 46, 5), regularWavygon(50, 50, 46, 6), regularWavygon(50, 50, 46, 7), regularWavygon(50, 50, 46, 8) }; } /**

Returns the stroke game shapes for Concentration.

*/ public static Shape[] getStrokeGameShapes() { return new Shape[] { regularSpokes(50, 50, 41, 5), regularSpokes(50, 50, 41, 6), regularSpokes(50, 50, 41, 7), regularSpokes(50, 50, 41, 8) }; } }