refaktor till maven

This commit is contained in:
Love 2022-12-04 16:11:40 +01:00
parent d209eb4b3c
commit e06ff9478b
No known key found for this signature in database
GPG Key ID: A3C10DC241C8FA9F
36 changed files with 194 additions and 2104 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ dist/
nbdist/ nbdist/
.nb-gradle/ .nb-gradle/
store store
target/

View File

@ -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>

View File

@ -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
View File

@ -0,0 +1,3 @@
mvn clean package
java -jar target/Schack-1-jar-with-dependencies.jar
pause

2
cli_run.sh Executable file
View File

@ -0,0 +1,2 @@
mvn clean package
java -jar target/Schack-1-jar-with-dependencies.jar

View File

@ -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

View File

@ -1,3 +0,0 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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

View File

@ -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
View 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>

View File

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Point; import java.awt.Point;
import java.io.IOException; import java.io.IOException;
@ -13,10 +13,9 @@ public class Bishop extends LongWalkers {
@Override @Override
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) { public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
return getMoves( return getMoves(
new int[][]{{-1, -1}, {1, 1}, {-1, 1}, {1, -1}}, new int[][] { { -1, -1 }, { 1, 1 }, { -1, 1 }, { 1, -1 } },
pieces, pieces,
allowedToRecurse allowedToRecurse);
);
} }
} }

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@ -41,14 +41,22 @@ public class Board extends JPanel implements MouseListener {
private Piece[][] getPieces() throws IOException { private Piece[][] getPieces() throws IOException {
Piece[][] piecesRet = { Piece[][] piecesRet = {
{new Rook(false, new Point(0, 0)), null, null, null, null, null, null, new Rook(true, new Point(0, 7))}, { new Rook(false, new Point(0, 0)), null, null, null, null, null, null,
{new Horse(false, new Point(1, 0)), null, null, null, null, null, null, new Horse(true, new Point(1, 7))}, new Rook(true, new Point(0, 7)) },
{new Bishop(false, new Point(2, 0)), null, null, null, null, null, null, new Bishop(true, new Point(2, 7))}, { new Horse(false, new Point(1, 0)), null, null, null, null, null, null,
{new Queen(false, new Point(3, 0)), null, null, null, null, null, null, new Queen(true, new Point(3, 7))}, new Horse(true, new Point(1, 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(2, 0)), null, null, null, null, null, null,
{new Bishop(false, new Point(5, 0)), null, null, null, null, null, null, new Bishop(true, new Point(5, 7))}, new Bishop(true, new Point(2, 7)) },
{new Horse(false, new Point(6, 0)), null, null, null, null, null, null, new Horse(true, new Point(6, 7))}, { new Queen(false, new Point(3, 0)), null, null, null, null, null, null,
{new Rook(false, new Point(7, 0)), null, null, null, null, null, null, new Rook(true, new Point(7, 7))} 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 // Sätt ut bönder

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Point; import java.awt.Point;
import java.io.IOException; import java.io.IOException;
@ -15,8 +15,8 @@ public class Horse extends Piece {
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) { public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
List<Point> movable = new ArrayList<>(); List<Point> movable = new ArrayList<>();
for (int dx : new int[]{-2, -1, 1, 2}) { for (int dx : new int[] { -2, -1, 1, 2 }) {
for (int direction : new int[]{-1, 1}) { for (int direction : new int[] { -1, 1 }) {
int stepLength = (3 - Math.abs(dx)), int stepLength = (3 - Math.abs(dx)),
dy = direction * stepLength; dy = direction * stepLength;
Point potentialMove = new Point(this.position.x + dx, this.position.y + dy); Point potentialMove = new Point(this.position.x + dx, this.position.y + dy);

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Point; import java.awt.Point;
import java.io.IOException; import java.io.IOException;
@ -26,7 +26,7 @@ public final class King extends Piece {
boolean[] somethingBetweenOrSchackOnTheWay = new boolean[2]; // Vänster, höger boolean[] somethingBetweenOrSchackOnTheWay = new boolean[2]; // Vänster, höger
int leftModifier = -1, rightModifier = 1; 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) { 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))) { if (pieces[loopX][this.position.y] != null || isInSchack(pieces, new Point(loopX, this.position.y))) {
somethingBetweenOrSchackOnTheWay[(modifier == leftModifier) ? 0 : 1] = true; somethingBetweenOrSchackOnTheWay[(modifier == leftModifier) ? 0 : 1] = true;
@ -36,7 +36,7 @@ public final class King extends Piece {
} }
leftModifier = 0; leftModifier = 0;
rightModifier = 1; rightModifier = 1;
for (int direction : new int[]{leftModifier, rightModifier}) { for (int direction : new int[] { leftModifier, rightModifier }) {
if (!somethingBetweenOrSchackOnTheWay[direction]) { if (!somethingBetweenOrSchackOnTheWay[direction]) {
Piece possibleRook = pieces[direction == leftModifier ? 0 : 7][this.position.y]; Piece possibleRook = pieces[direction == leftModifier ? 0 : 7][this.position.y];
if (possibleRook != null && !possibleRook.isMoved()) { if (possibleRook != null && !possibleRook.isMoved()) {
@ -87,7 +87,8 @@ public final class King extends Piece {
if (loopY == 0 && loopX == 0) { if (loopY == 0 && loopX == 0) {
continue; 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);
} }
} }

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Point; import java.awt.Point;
import java.io.IOException; 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 * Generell metod för att generera möjliga drag för LongWalkers
* *
* @param directions vilka håll. Exempel: <pre> * @param directions vilka håll. Exempel:
* {@code new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}}</pre> för att *
* som ett torn * <pre>
* {@code
* new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } }
* }</pre>
*
* för att
* som ett torn
* *
* @param pieces * @param pieces
* @param allowedToRecurse * @param allowedToRecurse

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import java.awt.Point; import java.awt.Point;
@ -18,7 +18,8 @@ public class Pawn extends Piece {
* *
* @param pieces * @param pieces
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot Ifall man ska kolla ifall * @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 * @return Alla lämpliga attackMoves
*/ */
@Override @Override
@ -26,7 +27,7 @@ public class Pawn extends Piece {
List<Point> movable = new ArrayList<>(); List<Point> movable = new ArrayList<>();
// Kolla ifall vi kan ta någon // 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 // 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)); 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) { 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 // 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 // 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)); final Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite() ? -1 : 1));
movable.addAll(addAttackMovesIfCan(pos, pieces)); movable.addAll(addAttackMovesIfCan(pos, pieces));
@ -121,7 +122,7 @@ public class Pawn extends Piece {
} }
private void transform(Piece[][] pieces) throws HeadlessException { private void transform(Piece[][] pieces) throws HeadlessException {
String[] transformations = {"Queen", "Rook", "Bishop", "Horse"}; String[] transformations = { "Queen", "Rook", "Bishop", "Horse" };
int choosenTransformations = JOptionPane.showOptionDialog(null, int choosenTransformations = JOptionPane.showOptionDialog(null,
"What do you want to the pawn to transform into?", "What do you want to the pawn to transform into?",
"Pawn about to transform", "Pawn about to transform",
@ -129,8 +130,7 @@ public class Pawn extends Piece {
JOptionPane.INFORMATION_MESSAGE, JOptionPane.INFORMATION_MESSAGE,
null, null,
transformations, transformations,
transformations[0] transformations[0]);
);
try { try {
switch (choosenTransformations) { switch (choosenTransformations) {
case 0: case 0:

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
@ -54,7 +54,7 @@ public abstract class Piece {
String className = this.getClass().getSimpleName(); String className = this.getClass().getSimpleName();
String colorName = this.isWhite() ? "White" : "Black"; String colorName = this.isWhite() ? "White" : "Black";
String fileName = colorName + className + ".png"; String fileName = colorName + className + ".png";
InputStream is = getClass().getResourceAsStream("/img/" + fileName); InputStream is = getClass().getResourceAsStream("/com/billenius/img/" + fileName);
icon = ImageIO.read(is); icon = ImageIO.read(is);
} }
@ -72,7 +72,8 @@ public abstract class Piece {
* *
* @param pieces * @param pieces
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot För bönder ifall den ska * @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 * @return Alla lämpliga attackMoves
*/ */
public List<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) { public List<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
@ -89,8 +90,7 @@ public abstract class Piece {
icon, icon,
position.x * Board.SIZE_OF_TILE, position.x * Board.SIZE_OF_TILE,
position.y * 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 * 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 pos Drag att lägga till ifall det går
* @param movable Lägger till drag i denna ArrayList * @param movable Lägger till drag i denna ArrayList
* @param pieces Piece[][] över brädet * @param pieces Piece[][] över brädet
* @param allowedToRecurse Behövs för att inte in i en evig loop där * @param allowedToRecurse Behövs för att inte 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 längre i denna riktning * @return true ifall man inte kan längre i denna riktning
*/ */
@ -155,7 +156,7 @@ public abstract class Piece {
* Kolla ifall det är schack vid den här positionen * Kolla ifall det är schack vid den här positionen
* *
* @param pieces Piece[][] över hela brädet * @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 * @return true ifall det är schack
*/ */
protected boolean isInSchack(Piece[][] pieces, Point pos) { protected boolean isInSchack(Piece[][] pieces, Point pos) {

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Point; import java.awt.Point;
import java.io.IOException; import java.io.IOException;
@ -13,9 +13,8 @@ public class Queen extends LongWalkers {
@Override @Override
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) { public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
return getMoves( 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, pieces,
allowedToRecurse allowedToRecurse);
);
} }
} }

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.Point; import java.awt.Point;
import java.io.IOException; import java.io.IOException;
@ -13,10 +13,9 @@ public class Rook extends LongWalkers {
@Override @Override
public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) { public List<Point> validMoves(Piece[][] pieces, boolean allowedToRecurse) {
return getMoves( return getMoves(
new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}, new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } },
pieces, pieces,
allowedToRecurse allowedToRecurse);
);
} }
} }

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -33,7 +33,7 @@ public class Schack {
frame.setAlwaysOnTop(false); frame.setAlwaysOnTop(false);
frame.setResizable(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(); final Board board = new Board();
frame.setContentPane(board); frame.setContentPane(board);
frame.getContentPane().addMouseListener(board); frame.getContentPane().addMouseListener(board);
@ -81,8 +81,7 @@ public class Schack {
}); });
connectToOpponent.addActionListener((ActionEvent ae) -> { connectToOpponent.addActionListener((ActionEvent ae) -> {
String opponentIP = JOptionPane.showInputDialog(null, "What's your opponents IP?"); String opponentIP = JOptionPane.showInputDialog(null, "What's your opponents IP?");
System.out.println("opponents ip: "+opponentIP); System.out.println("opponents ip: " + opponentIP);
}); });

View File

@ -1,4 +1,4 @@
package schack; package com.billenius.schack;
/** /**
* *