refaktor till maven
3
.gitignore
vendored
@ -6,4 +6,5 @@ nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
store
|
||||
store
|
||||
target/
|
||||
|
12
Schack.iml
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
94
build.xml
@ -1,94 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="Schack" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Schack.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="Schack-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
<!-- Bygg alla libs i sista jar -->
|
||||
<target name="package-for-store" depends="jar">
|
||||
<property name="store.jar.name" value="Schack"/>
|
||||
<property name="store.dir" value="store"/>
|
||||
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
|
||||
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
|
||||
<delete dir="${store.dir}"/>
|
||||
<mkdir dir="${store.dir}"/>
|
||||
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
|
||||
<zipgroupfileset dir="dist" includes="*.jar"/>
|
||||
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
<zip destfile="${store.jar}">
|
||||
<zipfileset src="${store.dir}/temp_final.jar"
|
||||
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
|
||||
</zip>
|
||||
<delete file="${store.dir}/temp_final.jar"/>
|
||||
</target>
|
||||
</project>
|
3
cli_run.bat
Executable file
@ -0,0 +1,3 @@
|
||||
mvn clean package
|
||||
java -jar target/Schack-1-jar-with-dependencies.jar
|
||||
pause
|
2
cli_run.sh
Executable file
@ -0,0 +1,2 @@
|
||||
mvn clean package
|
||||
java -jar target/Schack-1-jar-with-dependencies.jar
|
@ -1,4 +0,0 @@
|
||||
libs.CopyLibs.classpath=\
|
||||
${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
|
||||
libs.CopyLibs.displayName=CopyLibs Task
|
||||
libs.CopyLibs.prop-version=3.0
|
@ -1,3 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
@ -1,5 +0,0 @@
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=8c4b7f48
|
||||
nbproject/build-impl.xml.script.CRC32=e431c94e
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
|
@ -1,115 +0,0 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=Schack
|
||||
application.vendor=love & Simon
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap=none
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent=true
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.modulepath=\
|
||||
${run.modulepath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
debug.test.modulepath=\
|
||||
${run.test.modulepath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/Schack.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
includes=**
|
||||
jar.archive.disabled=${jnlp.enabled}
|
||||
jar.compress=false
|
||||
jar.index=${jnlp.enabled}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.modulepath=
|
||||
javac.processormodulepath=
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.modulepath=\
|
||||
${javac.modulepath}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.html5=false
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
jlink.launcher=false
|
||||
jlink.launcher.name=Schack
|
||||
jnlp.codebase.type=no.codebase
|
||||
jnlp.descriptor=application
|
||||
jnlp.enabled=false
|
||||
jnlp.mixed.code=default
|
||||
jnlp.offline-allowed=false
|
||||
jnlp.signed=false
|
||||
jnlp.signing=
|
||||
jnlp.signing.alias=
|
||||
jnlp.signing.keystore=
|
||||
main.class=schack.Schack
|
||||
# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found.
|
||||
manifest.custom.application.library.allowable.codebase=
|
||||
# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts.
|
||||
manifest.custom.caller.allowable.codebase=
|
||||
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
|
||||
manifest.custom.codebase=
|
||||
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
|
||||
manifest.custom.permissions=
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.modulepath=\
|
||||
${javac.modulepath}
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
run.test.modulepath=\
|
||||
${javac.test.modulepath}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>Schack</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
<libraries xmlns="http://www.netbeans.org/ns/ant-project-libraries/1">
|
||||
<definitions>.\lib\nblibraries.properties</definitions>
|
||||
</libraries>
|
||||
</configuration>
|
||||
</project>
|
119
pom.xml
Normal file
@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.billenius</groupId>
|
||||
<artifactId>Schack</artifactId>
|
||||
<version>1</version>
|
||||
|
||||
<name>Schack</name>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Love Billenius</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Simon Hansson</name>
|
||||
</contributor>
|
||||
</contributors>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java/</directory>
|
||||
<includes>
|
||||
<include>com/billenius/img/</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<pluginManagement> <!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.billenius.schack.Schack</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>com.billenius.schack.Schack</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
@ -13,10 +13,9 @@ public class Bishop extends LongWalkers {
|
||||
@Override
|
||||
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
|
||||
return getMoves(
|
||||
new int[][]{{-1, -1}, {1, 1}, {-1, 1}, {1, -1}},
|
||||
new int[][] { { -1, -1 }, { 1, 1 }, { -1, 1 }, { 1, -1 } },
|
||||
pieces,
|
||||
allowedToRecurse
|
||||
);
|
||||
allowedToRecurse);
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@ -41,14 +41,22 @@ public class Board extends JPanel implements MouseListener {
|
||||
|
||||
private Piece[][] getPieces() throws IOException {
|
||||
Piece[][] piecesRet = {
|
||||
{new Rook(false, new Point(0, 0)), null, null, null, null, null, null, new Rook(true, new Point(0, 7))},
|
||||
{new Horse(false, new Point(1, 0)), null, null, null, null, null, null, new Horse(true, new Point(1, 7))},
|
||||
{new Bishop(false, new Point(2, 0)), null, null, null, null, null, null, new Bishop(true, new Point(2, 7))},
|
||||
{new Queen(false, new Point(3, 0)), null, null, null, null, null, null, new Queen(true, new Point(3, 7))},
|
||||
{new King(false, new Point(4, 0)), null, null, null, null, null, null, new King(true, new Point(4, 7))},
|
||||
{new Bishop(false, new Point(5, 0)), null, null, null, null, null, null, new Bishop(true, new Point(5, 7))},
|
||||
{new Horse(false, new Point(6, 0)), null, null, null, null, null, null, new Horse(true, new Point(6, 7))},
|
||||
{new Rook(false, new Point(7, 0)), null, null, null, null, null, null, new Rook(true, new Point(7, 7))}
|
||||
{ new Rook(false, new Point(0, 0)), null, null, null, null, null, null,
|
||||
new Rook(true, new Point(0, 7)) },
|
||||
{ new Horse(false, new Point(1, 0)), null, null, null, null, null, null,
|
||||
new Horse(true, new Point(1, 7)) },
|
||||
{ new Bishop(false, new Point(2, 0)), null, null, null, null, null, null,
|
||||
new Bishop(true, new Point(2, 7)) },
|
||||
{ new Queen(false, new Point(3, 0)), null, null, null, null, null, null,
|
||||
new Queen(true, new Point(3, 7)) },
|
||||
{ new King(false, new Point(4, 0)), null, null, null, null, null, null,
|
||||
new King(true, new Point(4, 7)) },
|
||||
{ new Bishop(false, new Point(5, 0)), null, null, null, null, null, null,
|
||||
new Bishop(true, new Point(5, 7)) },
|
||||
{ new Horse(false, new Point(6, 0)), null, null, null, null, null, null,
|
||||
new Horse(true, new Point(6, 7)) },
|
||||
{ new Rook(false, new Point(7, 0)), null, null, null, null, null, null,
|
||||
new Rook(true, new Point(7, 7)) }
|
||||
};
|
||||
|
||||
// Sätt ut bönder
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
@ -15,8 +15,8 @@ public class Horse extends Piece {
|
||||
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
|
||||
List<Point> movable = new ArrayList<>();
|
||||
|
||||
for (int dx : new int[]{-2, -1, 1, 2}) {
|
||||
for (int direction : new int[]{-1, 1}) {
|
||||
for (int dx : new int[] { -2, -1, 1, 2 }) {
|
||||
for (int direction : new int[] { -1, 1 }) {
|
||||
int stepLength = (3 - Math.abs(dx)),
|
||||
dy = direction * stepLength;
|
||||
Point potentialMove = new Point(this.position.x + dx, this.position.y + dy);
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
@ -26,7 +26,7 @@ public final class King extends Piece {
|
||||
|
||||
boolean[] somethingBetweenOrSchackOnTheWay = new boolean[2]; // Vänster, höger
|
||||
int leftModifier = -1, rightModifier = 1;
|
||||
for (int modifier : new int[]{leftModifier, rightModifier}) {
|
||||
for (int modifier : new int[] { leftModifier, rightModifier }) {
|
||||
for (int loopX = this.position.x + modifier; loopX > 0 && loopX < 7; loopX += modifier) {
|
||||
if (pieces[loopX][this.position.y] != null || isInSchack(pieces, new Point(loopX, this.position.y))) {
|
||||
somethingBetweenOrSchackOnTheWay[(modifier == leftModifier) ? 0 : 1] = true;
|
||||
@ -36,7 +36,7 @@ public final class King extends Piece {
|
||||
}
|
||||
leftModifier = 0;
|
||||
rightModifier = 1;
|
||||
for (int direction : new int[]{leftModifier, rightModifier}) {
|
||||
for (int direction : new int[] { leftModifier, rightModifier }) {
|
||||
if (!somethingBetweenOrSchackOnTheWay[direction]) {
|
||||
Piece possibleRook = pieces[direction == leftModifier ? 0 : 7][this.position.y];
|
||||
if (possibleRook != null && !possibleRook.isMoved()) {
|
||||
@ -87,7 +87,8 @@ public final class King extends Piece {
|
||||
if (loopY == 0 && loopX == 0) {
|
||||
continue;
|
||||
}
|
||||
addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces, allowedToRecurse);
|
||||
addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces,
|
||||
allowedToRecurse);
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
@ -14,9 +14,15 @@ public abstract class LongWalkers extends Piece {
|
||||
/**
|
||||
* Generell metod för att generera möjliga drag för LongWalkers
|
||||
*
|
||||
* @param directions vilka håll. Exempel: <pre>
|
||||
* {@code new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}}</pre> för att gå
|
||||
* som ett torn
|
||||
* @param directions vilka håll. Exempel:
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } }
|
||||
* }</pre>
|
||||
*
|
||||
* för att gå
|
||||
* som ett torn
|
||||
*
|
||||
* @param pieces
|
||||
* @param allowedToRecurse
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Point;
|
||||
@ -18,7 +18,8 @@ public class Pawn extends Piece {
|
||||
*
|
||||
* @param pieces
|
||||
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot Ifall man ska kolla ifall
|
||||
* det är något i möjliga attackrutor ifall
|
||||
* det är något i möjliga
|
||||
* attackrutor ifall
|
||||
* @return Alla lämpliga attackMoves
|
||||
*/
|
||||
@Override
|
||||
@ -26,7 +27,7 @@ public class Pawn extends Piece {
|
||||
List<Point> movable = new ArrayList<>();
|
||||
|
||||
// Kolla ifall vi kan ta någon
|
||||
for (int pawnX : new int[]{-1, 1}) {
|
||||
for (int pawnX : new int[] { -1, 1 }) {
|
||||
// Position vi kollar just nu, snett upp åt höger & vänster
|
||||
Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite() ? -1 : 1));
|
||||
if (pos.x < 0 || pos.x > 7 || pos.y < 0 || pos.y > 7) {
|
||||
@ -59,7 +60,7 @@ public class Pawn extends Piece {
|
||||
}
|
||||
|
||||
// Kolla ifall vi kan ta någon
|
||||
for (int pawnX : new int[]{-1, 1}) {
|
||||
for (int pawnX : new int[] { -1, 1 }) {
|
||||
// Position vi kollar just nu, snett upp åt höger & vänster
|
||||
final Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite() ? -1 : 1));
|
||||
movable.addAll(addAttackMovesIfCan(pos, pieces));
|
||||
@ -121,7 +122,7 @@ public class Pawn extends Piece {
|
||||
}
|
||||
|
||||
private void transform(Piece[][] pieces) throws HeadlessException {
|
||||
String[] transformations = {"Queen", "Rook", "Bishop", "Horse"};
|
||||
String[] transformations = { "Queen", "Rook", "Bishop", "Horse" };
|
||||
int choosenTransformations = JOptionPane.showOptionDialog(null,
|
||||
"What do you want to the pawn to transform into?",
|
||||
"Pawn about to transform",
|
||||
@ -129,8 +130,7 @@ public class Pawn extends Piece {
|
||||
JOptionPane.INFORMATION_MESSAGE,
|
||||
null,
|
||||
transformations,
|
||||
transformations[0]
|
||||
);
|
||||
transformations[0]);
|
||||
try {
|
||||
switch (choosenTransformations) {
|
||||
case 0:
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
@ -54,7 +54,7 @@ public abstract class Piece {
|
||||
String className = this.getClass().getSimpleName();
|
||||
String colorName = this.isWhite() ? "White" : "Black";
|
||||
String fileName = colorName + className + ".png";
|
||||
InputStream is = getClass().getResourceAsStream("/img/" + fileName);
|
||||
InputStream is = getClass().getResourceAsStream("/com/billenius/img/" + fileName);
|
||||
icon = ImageIO.read(is);
|
||||
}
|
||||
|
||||
@ -72,7 +72,8 @@ public abstract class Piece {
|
||||
*
|
||||
* @param pieces
|
||||
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot För bönder ifall den ska
|
||||
* kolla ifall det är något i möjliga attackrutor ifall
|
||||
* kolla ifall det är något i
|
||||
* möjliga attackrutor ifall
|
||||
* @return Alla lämpliga attackMoves
|
||||
*/
|
||||
public List<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
|
||||
@ -89,8 +90,7 @@ public abstract class Piece {
|
||||
icon,
|
||||
position.x * Board.SIZE_OF_TILE,
|
||||
position.y * Board.SIZE_OF_TILE,
|
||||
null
|
||||
);
|
||||
null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,11 +114,12 @@ public abstract class Piece {
|
||||
/**
|
||||
* Lägg till move ifall det går, alltså inte är schack där
|
||||
*
|
||||
* @param pos Drag att lägga till ifall det går
|
||||
* @param movable Lägger till drag i denna ArrayList
|
||||
* @param pieces Piece[][] över brädet
|
||||
* @param pos Drag att lägga till ifall det går
|
||||
* @param movable Lägger till drag i denna ArrayList
|
||||
* @param pieces Piece[][] över brädet
|
||||
* @param allowedToRecurse Behövs för att inte gå in i en evig loop där
|
||||
* <pre>{@code addMovesIfCan -> isInSchack -> validMoves -> getCastlingIfPossible(King) -> isInSchack}</pre>
|
||||
*
|
||||
* <pre>{@code addMovesIfCan -> isInSchack -> validMoves -> getCastlingIfPossible(King) -> isInSchack}</pre>
|
||||
*
|
||||
* @return true ifall man inte kan gå längre i denna riktning
|
||||
*/
|
||||
@ -155,7 +156,7 @@ public abstract class Piece {
|
||||
* Kolla ifall det är schack vid den här positionen
|
||||
*
|
||||
* @param pieces Piece[][] över hela brädet
|
||||
* @param pos Kollar ifall det är schack om denna Piece flyttar hit
|
||||
* @param pos Kollar ifall det är schack om denna Piece flyttar hit
|
||||
* @return true ifall det är schack
|
||||
*/
|
||||
protected boolean isInSchack(Piece[][] pieces, Point pos) {
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
@ -13,9 +13,8 @@ public class Queen extends LongWalkers {
|
||||
@Override
|
||||
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
|
||||
return getMoves(
|
||||
new int[][]{{1, 0}, {-1, 0}, {0, 1}, {-1, -1}, {0, -1}, {1, 1}, {-1, 1}, {1, -1}},
|
||||
new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { -1, -1 }, { 0, -1 }, { 1, 1 }, { -1, 1 }, { 1, -1 } },
|
||||
pieces,
|
||||
allowedToRecurse
|
||||
);
|
||||
allowedToRecurse);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
@ -13,10 +13,9 @@ public class Rook extends LongWalkers {
|
||||
@Override
|
||||
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
|
||||
return getMoves(
|
||||
new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}},
|
||||
new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } },
|
||||
pieces,
|
||||
allowedToRecurse
|
||||
);
|
||||
allowedToRecurse);
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.ActionEvent;
|
||||
@ -33,12 +33,12 @@ public class Schack {
|
||||
frame.setAlwaysOnTop(false);
|
||||
frame.setResizable(false);
|
||||
|
||||
// Might throw an IOException if the icon of the Pieces isn't embedded correctly
|
||||
// Might throw an IOException if the icon of the Pieces isn't embedded correctly
|
||||
final Board board = new Board();
|
||||
frame.setContentPane(board);
|
||||
frame.getContentPane().addMouseListener(board);
|
||||
|
||||
// Create menu
|
||||
// Create menu
|
||||
final JMenuBar menuBar = new JMenuBar();
|
||||
final JMenu gameMenu = new JMenu("Game");
|
||||
final JMenu connectMenu = new JMenu("Connect");
|
||||
@ -81,9 +81,8 @@ public class Schack {
|
||||
});
|
||||
connectToOpponent.addActionListener((ActionEvent ae) -> {
|
||||
String opponentIP = JOptionPane.showInputDialog(null, "What's your opponents IP?");
|
||||
System.out.println("opponents ip: "+opponentIP);
|
||||
|
||||
|
||||
System.out.println("opponents ip: " + opponentIP);
|
||||
|
||||
});
|
||||
|
||||
// Add the menu stuff
|
@ -1,4 +1,4 @@
|
||||
package schack;
|
||||
package com.billenius.schack;
|
||||
|
||||
/**
|
||||
*
|