1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pom.xml Mon May 25 09:07:15 2009 +0200
1.3 @@ -0,0 +1,43 @@
1.4 +<?xml version="1.0" encoding="UTF-8"?>
1.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1.6 + <modelVersion>4.0.0</modelVersion>
1.7 + <packaging>pom</packaging>
1.8 + <groupId>org.apidesign</groupId>
1.9 + <artifactId>all-quoridor</artifactId>
1.10 + <version>1.0</version>
1.11 + <repositories>
1.12 + <repository>
1.13 + <id>netbeans</id>
1.14 + <url>http://bits.netbeans.org/maven2/</url>
1.15 + </repository>
1.16 + </repositories>
1.17 + <!--
1.18 + <scm>
1.19 + <connection>scm:hg:http://source.apidesign.org/hg/lookup</connection>
1.20 + <url>http://source.apidesign.org/hg/lookup</url>
1.21 + </scm>
1.22 + -->
1.23 + <licenses>
1.24 + <license>
1.25 + <name>GPL 2 with classpath Exception</name>
1.26 + <url>http://www.openjdk.org/legal/gplv2+ce.html</url>
1.27 + <distribution>repo</distribution>
1.28 + </license>
1.29 + <license>
1.30 + <name>CDDL 1</name>
1.31 + <url>http://www.sun.com/cddl/cddl.html</url>
1.32 + <distribution>repo</distribution>
1.33 + </license>
1.34 + </licenses>
1.35 + <organization>
1.36 + <name>API Design</name>
1.37 + <url>http://apidesign.org</url>
1.38 + </organization>
1.39 + <modules>
1.40 + <module>quoridor</module>
1.41 + <module>visidor</module>
1.42 + </modules>
1.43 + <name>Quoridor related projects</name>
1.44 + <description>Master project that agregates all quoridor related functionality.
1.45 + </description>
1.46 +</project>
2.1 --- a/quoridor/pom.xml Mon May 25 08:46:19 2009 +0200
2.2 +++ b/quoridor/pom.xml Mon May 25 09:07:15 2009 +0200
2.3 @@ -5,13 +5,14 @@
2.4 <artifactId>quoridor</artifactId>
2.5 <packaging>jar</packaging>
2.6 <url>http://quoridor.xelfi.cz</url>
2.7 + <parent>
2.8 + <groupId>org.apidesign</groupId>
2.9 + <artifactId>all-quoridor</artifactId>
2.10 + <relativePath>..</relativePath>
2.11 + <version>1.0</version>
2.12 + </parent>
2.13 <!--
2.14 - <parent>
2.15 - <groupId>xelfi.cz</groupId>
2.16 - <artifactId>quoridor</artifactId>
2.17 - <relativePath>..</relativePath>
2.18 <version>2.0</version>
2.19 - </parent>
2.20 <ciManagement>
2.21 <system>hudson</system>
2.22 <url>http://hudson.apidesign.org/hudson/job/lookup</url>
2.23 @@ -67,7 +68,7 @@
2.24 </dependency>
2.25 </dependencies>
2.26 <name>Quoridor Library</name>
2.27 - <description>Quoridor library provides API to play the Quoridor game.</description>
2.28 + <description>Quoridor library provides non-visual API to play the Quoridor game.</description>
2.29 <version>1.0</version>
2.30 </project>
2.31
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/visidor/pom.xml Mon May 25 09:07:15 2009 +0200
3.3 @@ -0,0 +1,51 @@
3.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3.5 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3.6 + <modelVersion>4.0.0</modelVersion>
3.7 + <groupId>org.apidesign</groupId>
3.8 + <artifactId>visidor</artifactId>
3.9 + <packaging>jar</packaging>
3.10 + <version>1.0</version>
3.11 + <name>visidor</name>
3.12 + <url>http://maven.apache.org</url>
3.13 + <parent>
3.14 + <groupId>org.apidesign</groupId>
3.15 + <artifactId>all-quoridor</artifactId>
3.16 + <relativePath>..</relativePath>
3.17 + <version>1.0</version>
3.18 + </parent>
3.19 + <build>
3.20 + <plugins>
3.21 + <plugin>
3.22 + <groupId>org.apache.maven.plugins</groupId>
3.23 + <artifactId>maven-compiler-plugin</artifactId>
3.24 + <version>2.0.2</version>
3.25 + <configuration>
3.26 + <source>1.5</source>
3.27 + <target>1.5</target>
3.28 + </configuration>
3.29 + </plugin>
3.30 + </plugins>
3.31 + </build>
3.32 + <dependencies>
3.33 + <dependency>
3.34 + <groupId>junit</groupId>
3.35 + <artifactId>junit</artifactId>
3.36 + <version>3.8.1</version>
3.37 + <scope>test</scope>
3.38 + </dependency>
3.39 + <dependency>
3.40 + <groupId>org.apidesign</groupId>
3.41 + <artifactId>quoridor</artifactId>
3.42 + <version>1.0</version>
3.43 + </dependency>
3.44 + <dependency>
3.45 + <groupId>org.netbeans.api</groupId>
3.46 + <artifactId>org-netbeans-api-visual</artifactId>
3.47 + <version>RELEASE65</version>
3.48 + </dependency>
3.49 + </dependencies>
3.50 +</project>
3.51 +
3.52 +
3.53 +
3.54 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java Mon May 25 09:07:15 2009 +0200
4.3 @@ -0,0 +1,180 @@
4.4 +/*
4.5 + * To change this template, choose Tools | Templates
4.6 + * and open the template in the editor.
4.7 + */
4.8 +
4.9 +package cz.xelfi.quoridor.visidor;
4.10 +
4.11 +import cz.xelfi.quoridor.Board;
4.12 +import cz.xelfi.quoridor.Fence;
4.13 +import cz.xelfi.quoridor.Fence.Orientation;
4.14 +import cz.xelfi.quoridor.IllegalPositionException;
4.15 +import cz.xelfi.quoridor.Move;
4.16 +import java.awt.Color;
4.17 +import java.awt.Point;
4.18 +import java.awt.Rectangle;
4.19 +import javax.swing.JFrame;
4.20 +import org.netbeans.api.visual.action.ActionFactory;
4.21 +import org.netbeans.api.visual.action.MoveProvider;
4.22 +import org.netbeans.api.visual.anchor.AnchorFactory;
4.23 +import org.netbeans.api.visual.border.BorderFactory;
4.24 +import org.netbeans.api.visual.widget.ConnectionWidget;
4.25 +import org.netbeans.api.visual.widget.ImageWidget;
4.26 +import org.netbeans.api.visual.widget.LabelWidget;
4.27 +import org.netbeans.api.visual.widget.LayerWidget;
4.28 +import org.netbeans.api.visual.widget.Scene;
4.29 +import org.netbeans.api.visual.widget.Widget;
4.30 +
4.31 +/**
4.32 + *
4.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
4.34 + */
4.35 +public class Viewer implements MoveProvider {
4.36 +
4.37 + /**
4.38 + * @param args the command line arguments
4.39 + */
4.40 + public static void main(String[] args) throws IllegalPositionException {
4.41 + Board b = Board.empty();
4.42 + for (int i = 1; i <= 8; i++) {
4.43 + b = b.apply(Move.fence('A', i, Orientation.values()[i % 2]));
4.44 + }
4.45 + for (int i = 1; i <= 8; i++) {
4.46 + b = b.apply(Move.fence('H', i, Orientation.values()[(i + 1) % 2]));
4.47 + }
4.48 + //b = b.apply(Move.fence('H', 5, Orientation.HORIZONTAL));
4.49 + view(b);
4.50 + }
4.51 +
4.52 + private static void view(Board b) {
4.53 + Scene scene = new Scene();
4.54 +// Scene layerBoard = scene;
4.55 + final LayerWidget layerLines = new LayerWidget(scene);
4.56 + scene.addChild(layerLines);
4.57 + final LayerWidget layerBoard = new LayerWidget(scene);
4.58 + layerLines.addChild(layerBoard);
4.59 + final int WIDTH = 50;
4.60 + final int HEIGHT = 50;
4.61 +// conn.setSourceAnchor(ahoj);
4.62 + Widget[][] fields = new Widget[10][];
4.63 + for (int i = 0; i < fields.length; i++) {
4.64 + fields[i] = new Widget[10];
4.65 + for (int j = 0; j < fields[i].length; j++) {
4.66 + LabelWidget w = new LabelWidget(scene);
4.67 + w.setPreferredBounds(new Rectangle(i * WIDTH, j * HEIGHT, WIDTH, HEIGHT));
4.68 + layerBoard.addChild(w);
4.69 + fields[i][j] = w;
4.70 + }
4.71 + }
4.72 + for (int i = 0; i < fields.length; i++) {
4.73 + for (int j = 0; j < fields[i].length; j++) {
4.74 + if (i > 0) {
4.75 + ConnectionWidget horiz = new ConnectionWidget(scene);
4.76 + horiz.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i - 1][j]));
4.77 + horiz.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j]));
4.78 + scene.addChild(horiz);
4.79 + }
4.80 + if (j > 0) {
4.81 + ConnectionWidget vert = new ConnectionWidget(scene);
4.82 + vert.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i][j - 1]));
4.83 + vert.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j]));
4.84 + scene.addChild(vert);
4.85 + }
4.86 + }
4.87 + }
4.88 +
4.89 + ImageWidget horizontalWall = new ImageWidget(scene);
4.90 + horizontalWall.setPreferredBounds(new Rectangle(550, 300, 90, 10));
4.91 + horizontalWall.setBackground(Color.BLACK);
4.92 + horizontalWall.getActions().addAction(ActionFactory.createMoveAction(null, new Viewer(true)));
4.93 + horizontalWall.setBorder(BorderFactory.createLineBorder());
4.94 + horizontalWall.setOpaque(true);
4.95 + layerBoard.addChild(horizontalWall);
4.96 +
4.97 + ImageWidget verticalWall = new ImageWidget(scene);
4.98 + verticalWall.setPreferredBounds(new Rectangle(600, 150, 10, 90));
4.99 + verticalWall.setBackground(Color.BLACK);
4.100 + verticalWall.getActions().addAction(ActionFactory.createMoveAction(null, new Viewer(false)));
4.101 + verticalWall.setBorder(BorderFactory.createLineBorder());
4.102 + verticalWall.setOpaque(true);
4.103 + layerBoard.addChild(verticalWall);
4.104 +
4.105 + for (Fence f : b.getFences()) {
4.106 + Rectangle r = fenceRectangle(f.getColumn(), f.getRow(), f.getOrientation());
4.107 + ImageWidget fenceWall = new ImageWidget(scene);
4.108 + fenceWall.setPreferredBounds(r);
4.109 + fenceWall.setBackground(Color.BLACK);
4.110 + fenceWall.setBorder(BorderFactory.createLineBorder());
4.111 + fenceWall.setOpaque(true);
4.112 + layerBoard.addChild(fenceWall);
4.113 + }
4.114 +
4.115 + JFrame f = new JFrame();
4.116 + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
4.117 +
4.118 + f.add(scene.createView());
4.119 + f.pack();
4.120 + f.setVisible(true);
4.121 + }
4.122 +
4.123 + private static Rectangle fenceRectangle(char column, int row, Fence.Orientation o) {
4.124 + int w, h;
4.125 + switch (o) {
4.126 + case HORIZONTAL: w = 45; h = 5; break;
4.127 + case VERTICAL: w = 5; h = 45; break;
4.128 + default: throw new IllegalStateException();
4.129 + }
4.130 +
4.131 + return new Rectangle(
4.132 + (column - 'A' + 1) * 50 + 25 - w, row * 50 + 25 - h, 2 * w, 2 * h
4.133 + );
4.134 + }
4.135 +
4.136 + final boolean horizontal;
4.137 +
4.138 + Point orig;
4.139 +
4.140 + private Viewer(boolean horizontal) {
4.141 + this.horizontal = horizontal;
4.142 + }
4.143 + public void movementStarted(Widget widget) {
4.144 + System.err.println("started: " + widget.getBounds());
4.145 + }
4.146 +
4.147 + public void movementFinished(Widget widget) {
4.148 + System.err.println("finished: " + widget.getLocation());
4.149 + }
4.150 +
4.151 + public Point getOriginalLocation(Widget widget) {
4.152 + orig = new Point(widget.getBounds().x, widget.getBounds().y);
4.153 + System.err.println("orig: " + orig);
4.154 + return orig;
4.155 + }
4.156 +
4.157 + public void setNewLocation(Widget widget, Point location) {
4.158 + widget.setPreferredBounds(new Rectangle(
4.159 + round(location.x, true) + (horizontal ? 5 : 0),
4.160 + round(location.y, false) + (horizontal ? 0 : 5),
4.161 + horizontal ? 90 : 10,
4.162 + horizontal ? 10 : 90)
4.163 + );
4.164 + }
4.165 +
4.166 + int round(int p, boolean cmpHori) {
4.167 +// p = horizontal ? orig.x + p: orig.y + p;
4.168 + int onboard = p / 50;
4.169 + System.err.println(cmpHori ? "hori: " + onboard : " vert: " + onboard);
4.170 + if (onboard < 0) {
4.171 + onboard = 0;
4.172 + }
4.173 + if (onboard >= 9) {
4.174 + return p;
4.175 + }
4.176 + int real = 25 + onboard * 50;
4.177 + if (horizontal != cmpHori) {
4.178 + return real - 5;
4.179 + } else {
4.180 + return real;
4.181 + }
4.182 + }
4.183 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/visidor/src/test/java/cz/xelfi/quoridor/visidor/ViewerTest.java Mon May 25 09:07:15 2009 +0200
5.3 @@ -0,0 +1,38 @@
5.4 +package org.apidesign.quoridor.visidor;
5.5 +
5.6 +import junit.framework.Test;
5.7 +import junit.framework.TestCase;
5.8 +import junit.framework.TestSuite;
5.9 +
5.10 +/**
5.11 + * Unit test for simple App.
5.12 + */
5.13 +public class AppTest
5.14 + extends TestCase
5.15 +{
5.16 + /**
5.17 + * Create the test case
5.18 + *
5.19 + * @param testName name of the test case
5.20 + */
5.21 + public AppTest( String testName )
5.22 + {
5.23 + super( testName );
5.24 + }
5.25 +
5.26 + /**
5.27 + * @return the suite of tests being tested
5.28 + */
5.29 + public static Test suite()
5.30 + {
5.31 + return new TestSuite( AppTest.class );
5.32 + }
5.33 +
5.34 + /**
5.35 + * Rigourous Test :-)
5.36 + */
5.37 + public void testApp()
5.38 + {
5.39 + assertTrue( true );
5.40 + }
5.41 +}
6.1 --- a/visidor/src/visidor/Viewer.java Mon May 25 08:46:19 2009 +0200
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,180 +0,0 @@
6.4 -/*
6.5 - * To change this template, choose Tools | Templates
6.6 - * and open the template in the editor.
6.7 - */
6.8 -
6.9 -package visidor;
6.10 -
6.11 -import cz.xelfi.quoridor.Board;
6.12 -import cz.xelfi.quoridor.Fence;
6.13 -import cz.xelfi.quoridor.Fence.Orientation;
6.14 -import cz.xelfi.quoridor.IllegalPositionException;
6.15 -import cz.xelfi.quoridor.Move;
6.16 -import java.awt.Color;
6.17 -import java.awt.Point;
6.18 -import java.awt.Rectangle;
6.19 -import javax.swing.JFrame;
6.20 -import org.netbeans.api.visual.action.ActionFactory;
6.21 -import org.netbeans.api.visual.action.MoveProvider;
6.22 -import org.netbeans.api.visual.anchor.AnchorFactory;
6.23 -import org.netbeans.api.visual.border.BorderFactory;
6.24 -import org.netbeans.api.visual.widget.ConnectionWidget;
6.25 -import org.netbeans.api.visual.widget.ImageWidget;
6.26 -import org.netbeans.api.visual.widget.LabelWidget;
6.27 -import org.netbeans.api.visual.widget.LayerWidget;
6.28 -import org.netbeans.api.visual.widget.Scene;
6.29 -import org.netbeans.api.visual.widget.Widget;
6.30 -
6.31 -/**
6.32 - *
6.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
6.34 - */
6.35 -public class Viewer implements MoveProvider {
6.36 -
6.37 - /**
6.38 - * @param args the command line arguments
6.39 - */
6.40 - public static void main(String[] args) throws IllegalPositionException {
6.41 - Board b = Board.empty();
6.42 - for (int i = 1; i <= 8; i++) {
6.43 - b = b.apply(Move.fence('A', i, Orientation.values()[i % 2]));
6.44 - }
6.45 - for (int i = 1; i <= 8; i++) {
6.46 - b = b.apply(Move.fence('H', i, Orientation.values()[(i + 1) % 2]));
6.47 - }
6.48 - //b = b.apply(Move.fence('H', 5, Orientation.HORIZONTAL));
6.49 - view(b);
6.50 - }
6.51 -
6.52 - private static void view(Board b) {
6.53 - Scene scene = new Scene();
6.54 -// Scene layerBoard = scene;
6.55 - final LayerWidget layerLines = new LayerWidget(scene);
6.56 - scene.addChild(layerLines);
6.57 - final LayerWidget layerBoard = new LayerWidget(scene);
6.58 - layerLines.addChild(layerBoard);
6.59 - final int WIDTH = 50;
6.60 - final int HEIGHT = 50;
6.61 -// conn.setSourceAnchor(ahoj);
6.62 - Widget[][] fields = new Widget[10][];
6.63 - for (int i = 0; i < fields.length; i++) {
6.64 - fields[i] = new Widget[10];
6.65 - for (int j = 0; j < fields[i].length; j++) {
6.66 - LabelWidget w = new LabelWidget(scene);
6.67 - w.setPreferredBounds(new Rectangle(i * WIDTH, j * HEIGHT, WIDTH, HEIGHT));
6.68 - layerBoard.addChild(w);
6.69 - fields[i][j] = w;
6.70 - }
6.71 - }
6.72 - for (int i = 0; i < fields.length; i++) {
6.73 - for (int j = 0; j < fields[i].length; j++) {
6.74 - if (i > 0) {
6.75 - ConnectionWidget horiz = new ConnectionWidget(scene);
6.76 - horiz.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i - 1][j]));
6.77 - horiz.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j]));
6.78 - scene.addChild(horiz);
6.79 - }
6.80 - if (j > 0) {
6.81 - ConnectionWidget vert = new ConnectionWidget(scene);
6.82 - vert.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i][j - 1]));
6.83 - vert.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j]));
6.84 - scene.addChild(vert);
6.85 - }
6.86 - }
6.87 - }
6.88 -
6.89 - ImageWidget horizontalWall = new ImageWidget(scene);
6.90 - horizontalWall.setPreferredBounds(new Rectangle(550, 300, 90, 10));
6.91 - horizontalWall.setBackground(Color.BLACK);
6.92 - horizontalWall.getActions().addAction(ActionFactory.createMoveAction(null, new Viewer(true)));
6.93 - horizontalWall.setBorder(BorderFactory.createLineBorder());
6.94 - horizontalWall.setOpaque(true);
6.95 - layerBoard.addChild(horizontalWall);
6.96 -
6.97 - ImageWidget verticalWall = new ImageWidget(scene);
6.98 - verticalWall.setPreferredBounds(new Rectangle(600, 150, 10, 90));
6.99 - verticalWall.setBackground(Color.BLACK);
6.100 - verticalWall.getActions().addAction(ActionFactory.createMoveAction(null, new Viewer(false)));
6.101 - verticalWall.setBorder(BorderFactory.createLineBorder());
6.102 - verticalWall.setOpaque(true);
6.103 - layerBoard.addChild(verticalWall);
6.104 -
6.105 - for (Fence f : b.getFences()) {
6.106 - Rectangle r = fenceRectangle(f.getColumn(), f.getRow(), f.getOrientation());
6.107 - ImageWidget fenceWall = new ImageWidget(scene);
6.108 - fenceWall.setPreferredBounds(r);
6.109 - fenceWall.setBackground(Color.BLACK);
6.110 - fenceWall.setBorder(BorderFactory.createLineBorder());
6.111 - fenceWall.setOpaque(true);
6.112 - layerBoard.addChild(fenceWall);
6.113 - }
6.114 -
6.115 - JFrame f = new JFrame();
6.116 - f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
6.117 -
6.118 - f.add(scene.createView());
6.119 - f.pack();
6.120 - f.setVisible(true);
6.121 - }
6.122 -
6.123 - private static Rectangle fenceRectangle(char column, int row, Fence.Orientation o) {
6.124 - int w, h;
6.125 - switch (o) {
6.126 - case HORIZONTAL: w = 45; h = 5; break;
6.127 - case VERTICAL: w = 5; h = 45; break;
6.128 - default: throw new IllegalStateException();
6.129 - }
6.130 -
6.131 - return new Rectangle(
6.132 - (column - 'A' + 1) * 50 + 25 - w, row * 50 + 25 - h, 2 * w, 2 * h
6.133 - );
6.134 - }
6.135 -
6.136 - final boolean horizontal;
6.137 -
6.138 - Point orig;
6.139 -
6.140 - private Viewer(boolean horizontal) {
6.141 - this.horizontal = horizontal;
6.142 - }
6.143 - public void movementStarted(Widget widget) {
6.144 - System.err.println("started: " + widget.getBounds());
6.145 - }
6.146 -
6.147 - public void movementFinished(Widget widget) {
6.148 - System.err.println("finished: " + widget.getLocation());
6.149 - }
6.150 -
6.151 - public Point getOriginalLocation(Widget widget) {
6.152 - orig = new Point(widget.getBounds().x, widget.getBounds().y);
6.153 - System.err.println("orig: " + orig);
6.154 - return orig;
6.155 - }
6.156 -
6.157 - public void setNewLocation(Widget widget, Point location) {
6.158 - widget.setPreferredBounds(new Rectangle(
6.159 - round(location.x, true) + (horizontal ? 5 : 0),
6.160 - round(location.y, false) + (horizontal ? 0 : 5),
6.161 - horizontal ? 90 : 10,
6.162 - horizontal ? 10 : 90)
6.163 - );
6.164 - }
6.165 -
6.166 - int round(int p, boolean cmpHori) {
6.167 -// p = horizontal ? orig.x + p: orig.y + p;
6.168 - int onboard = p / 50;
6.169 - System.err.println(cmpHori ? "hori: " + onboard : " vert: " + onboard);
6.170 - if (onboard < 0) {
6.171 - onboard = 0;
6.172 - }
6.173 - if (onboard >= 9) {
6.174 - return p;
6.175 - }
6.176 - int real = 25 + onboard * 50;
6.177 - if (horizontal != cmpHori) {
6.178 - return real - 5;
6.179 - } else {
6.180 - return real;
6.181 - }
6.182 - }
6.183 -}