summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Cherniy <qugalet@m0e.space>2024-06-08 22:58:45 +0300
committerAndriy Cherniy <qugalet@m0e.space>2024-06-08 22:58:45 +0300
commit249c10030fe27ef6a3a0afcacf53d4024143a054 (patch)
treef0ef624783997f9b46be6057f12d05f5e0537e3b
downloadoop-kursach-249c10030fe27ef6a3a0afcacf53d4024143a054.tar.gz
oop-kursach-249c10030fe27ef6a3a0afcacf53d4024143a054.zip
initial commit
-rw-r--r--.gitignore38
-rw-r--r--.idea/.gitignore8
-rw-r--r--.idea/encodings.xml7
-rw-r--r--.idea/misc.xml14
-rw-r--r--.mvn/wrapper/maven-wrapper.jarbin0 -> 58727 bytes
-rw-r--r--.mvn/wrapper/maven-wrapper.properties2
-rw-r--r--flake.lock27
-rw-r--r--flake.nix54
-rwxr-xr-xmvnw316
-rw-r--r--mvnw.cmd188
-rw-r--r--pom.xml77
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/Main.java133
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/dialogs/ChangeDialog.java96
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/dialogs/InsertDialog.java127
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Ability.java5
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Coordinates.java33
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Fortress.java129
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/ThroneRoom.java52
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Workstation.java57
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Dwarf.java92
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Immigrant.java333
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Nobel.java19
-rw-r--r--src/main/java/space/m0e/quga/oop/lab56maven/threads/ImmigrantThread.java57
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.pngbin0 -> 506975 bytes
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.png-autosave.krabin0 -> 1600989 bytes
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/change_dialog.fxml44
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/insert_dialog.fxml52
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/fortress.jpegbin0 -> 339659 bytes
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/throne_room.jpgbin0 -> 510577 bytes
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/workstation.pngbin0 -> 6545 bytes
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/dwarf.pngbin0 -> 1645 bytes
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/immigrant.pngbin0 -> 1610 bytes
-rw-r--r--src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/nobel.pngbin0 -> 1644 bytes
33 files changed, 1960 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store \ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Encoding">
+ <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+ <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
+ </component>
+</project> \ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..89c3cbb
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ExternalStorageConfigurationManager" enabled="true" />
+ <component name="MavenProjectsManager">
+ <option name="originalFiles">
+ <list>
+ <option value="$PROJECT_DIR$/pom.xml" />
+ </list>
+ </option>
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21 (2)" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/out" />
+ </component>
+</project> \ No newline at end of file
diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar
new file mode 100644
index 0000000..c1dd12f
--- /dev/null
+++ b/.mvn/wrapper/maven-wrapper.jar
Binary files differ
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 0000000..40ca015
--- /dev/null
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,2 @@
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
+wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar \ No newline at end of file
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..8650720
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1716948383,
+ "narHash": "sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "ad57eef4ef0659193044870c731987a6df5cf56b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..856d9ec
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,54 @@
+{
+ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; };
+
+ outputs = { self, nixpkgs }:
+ let
+ system = "x86_64-linux";
+ pkgs = import nixpkgs {
+ inherit system;
+ config = { allowUnfree = true; };
+ };
+ fhs = pkgs.buildFHSUserEnv {
+ name = "fhs-shell";
+ # targetPkgs = pkgs: [
+ # ];
+
+ targetPkgs = pkgs:
+ (with pkgs; [
+ gtk3
+ pkg-config
+ javaPackages.openjfx21
+ libpng
+ zlib
+ lcms2
+ cpio
+ file
+ which
+ zip
+ perl
+ zlib
+ cups
+ freetype
+ harfbuzz
+ alsa-lib
+ libjpeg
+ giflib
+ (jdk21.override { enableJavaFX = true; })
+
+ jetbrains.idea-ultimate
+ ]) ++ (with pkgs.xorg; [
+ libXi
+ libXinerama
+ libXcursor
+ libXrandr
+ libX11
+ libICE
+ libXrender
+ libXext
+ libXtst
+ libXt
+ libXtst
+ ]);
+ };
+ in { devShells.${system}.default = fhs.env; };
+}
diff --git a/mvnw b/mvnw
new file mode 100755
index 0000000..8a8fb22
--- /dev/null
+++ b/mvnw
@@ -0,0 +1,316 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+# JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+# M2_HOME - location of maven2's installed home dir
+# MAVEN_OPTS - parameters passed to the Java VM when running Maven
+# e.g. to debug Maven itself, use
+# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+ if [ -f /usr/local/etc/mavenrc ] ; then
+ . /usr/local/etc/mavenrc
+ fi
+
+ if [ -f /etc/mavenrc ] ; then
+ . /etc/mavenrc
+ fi
+
+ if [ -f "$HOME/.mavenrc" ] ; then
+ . "$HOME/.mavenrc"
+ fi
+
+fi
+
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ MINGW*) mingw=true;;
+ Darwin*) darwin=true
+ # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+ # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+ if [ -z "$JAVA_HOME" ]; then
+ if [ -x "/usr/libexec/java_home" ]; then
+ export JAVA_HOME="`/usr/libexec/java_home`"
+ else
+ export JAVA_HOME="/Library/Java/Home"
+ fi
+ fi
+ ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+ if [ -r /etc/gentoo-release ] ; then
+ JAVA_HOME=`java-config --jre-home`
+ fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+ ## resolve links - $0 may be a link to maven's home
+ PRG="$0"
+
+ # need this for relative symlinks
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`dirname "$PRG"`/$link"
+ fi
+ done
+
+ saveddir=`pwd`
+
+ M2_HOME=`dirname "$PRG"`/..
+
+ # make it fully qualified
+ M2_HOME=`cd "$M2_HOME" && pwd`
+
+ cd "$saveddir"
+ # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --unix "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME="`(cd "$M2_HOME"; pwd)`"
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+ javaExecutable="`which javac`"
+ if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+ # readlink(1) is not available as standard on Solaris 10.
+ readLink=`which readlink`
+ if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+ if $darwin ; then
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+ else
+ javaExecutable="`readlink -f \"$javaExecutable\"`"
+ fi
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ JAVA_HOME="$javaHome"
+ export JAVA_HOME
+ fi
+ fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+ if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ else
+ JAVACMD="`\\unset -f command; \\command -v java`"
+ fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+ echo "Error: JAVA_HOME is not defined correctly." >&2
+ echo " We cannot execute $JAVACMD" >&2
+ exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+ echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+ if [ -z "$1" ]
+ then
+ echo "Path not specified to find_maven_basedir"
+ return 1
+ fi
+
+ basedir="$1"
+ wdir="$1"
+ while [ "$wdir" != '/' ] ; do
+ if [ -d "$wdir"/.mvn ] ; then
+ basedir=$wdir
+ break
+ fi
+ # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+ if [ -d "${wdir}" ]; then
+ wdir=`cd "$wdir/.."; pwd`
+ fi
+ # end of workaround
+ done
+ echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+ if [ -f "$1" ]; then
+ echo "$(tr -s '\n' ' ' < "$1")"
+ fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+ exit 1;
+fi
+
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found .mvn/wrapper/maven-wrapper.jar"
+ fi
+else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+ fi
+ if [ -n "$MVNW_REPOURL" ]; then
+ jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+ else
+ jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+ fi
+ while IFS="=" read key value; do
+ case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+ esac
+ done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Downloading from: $jarUrl"
+ fi
+ wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+ if $cygwin; then
+ wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
+ fi
+
+ if command -v wget > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found wget ... using wget"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
+ else
+ wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
+ fi
+ elif command -v curl > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found curl ... using curl"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ curl -o "$wrapperJarPath" "$jarUrl" -f
+ else
+ curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
+ fi
+
+ else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Falling back to using Java to download"
+ fi
+ javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+ # For Cygwin, switch paths to Windows format before running javac
+ if $cygwin; then
+ javaClass=`cygpath --path --windows "$javaClass"`
+ fi
+ if [ -e "$javaClass" ]; then
+ if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Compiling MavenWrapperDownloader.java ..."
+ fi
+ # Compiling the Java class
+ ("$JAVA_HOME/bin/javac" "$javaClass")
+ fi
+ if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ # Running the downloader
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Running MavenWrapperDownloader.java ..."
+ fi
+ ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+ fi
+ fi
+ fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+if [ "$MVNW_VERBOSE" = true ]; then
+ echo $MAVEN_PROJECTBASEDIR
+fi
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --path --windows "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+ [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+ MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+ $MAVEN_OPTS \
+ $MAVEN_DEBUG_OPTS \
+ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+ "-Dmaven.home=${M2_HOME}" \
+ "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
diff --git a/mvnw.cmd b/mvnw.cmd
new file mode 100644
index 0000000..1d8ab01
--- /dev/null
+++ b/mvnw.cmd
@@ -0,0 +1,188 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM https://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM set title of command window
+title %0
+@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
+if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+
+FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
+ IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Found %WRAPPER_JAR%
+ )
+) else (
+ if not "%MVNW_REPOURL%" == "" (
+ SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
+ )
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Couldn't find %WRAPPER_JAR%, downloading it ...
+ echo Downloading from: %DOWNLOAD_URL%
+ )
+
+ powershell -Command "&{"^
+ "$webclient = new-object System.Net.WebClient;"^
+ "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
+ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
+ "}"^
+ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
+ "}"
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Finished downloading %WRAPPER_JAR%
+ )
+)
+@REM End of extension
+
+@REM Provide a "standardized" way to retrieve the CLI args that will
+@REM work with both Windows and non-Windows executions.
+set MAVEN_CMD_LINE_ARGS=%*
+
+%MAVEN_JAVA_EXE% ^
+ %JVM_CONFIG_MAVEN_PROPS% ^
+ %MAVEN_OPTS% ^
+ %MAVEN_DEBUG_OPTS% ^
+ -classpath %WRAPPER_JAR% ^
+ "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
+ %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
+if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%"=="on" pause
+
+if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
+
+cmd /C exit /B %ERROR_CODE%
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..b32b409
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,77 @@
+<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>space.m0e.quga.oop</groupId>
+ <artifactId>lab-5-6-maven</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>lab-5-6-maven</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <junit.version>5.10.0</junit.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openjfx</groupId>
+ <artifactId>javafx-controls</artifactId>
+ <version>21</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openjfx</groupId>
+ <artifactId>javafx-fxml</artifactId>
+ <version>21</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.11.0</version>
+ <configuration>
+ <source>21</source>
+ <target>21</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.openjfx</groupId>
+ <artifactId>javafx-maven-plugin</artifactId>
+ <version>0.0.8</version>
+ <executions>
+ <execution>
+ <!-- Default configuration for running with: mvn clean javafx:run -->
+ <id>default-cli</id>
+ <configuration>
+ <mainClass>space.m0e.quga.oop.lab56maven/space.m0e.quga.oop.lab56maven.Main
+ </mainClass>
+ <launcher>app</launcher>
+ <jlinkZipName>app</jlinkZipName>
+ <jlinkImageName>app</jlinkImageName>
+ <noManPages>true</noManPages>
+ <stripDebug>true</stripDebug>
+ <noHeaderFiles>true</noHeaderFiles>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project> \ No newline at end of file
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/Main.java b/src/main/java/space/m0e/quga/oop/lab56maven/Main.java
new file mode 100644
index 0000000..b337de8
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/Main.java
@@ -0,0 +1,133 @@
+package space.m0e.quga.oop.lab56maven;
+
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.scene.Group;
+import javafx.scene.Scene;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Label;
+import javafx.scene.input.KeyCode;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
+import javafx.stage.Stage;
+import space.m0e.quga.oop.lab56maven.dialogs.InsertDialog;
+import space.m0e.quga.oop.lab56maven.entities.common.Ability;
+import space.m0e.quga.oop.lab56maven.entities.macro.Fortress;
+import space.m0e.quga.oop.lab56maven.entities.macro.ThroneRoom;
+import space.m0e.quga.oop.lab56maven.entities.macro.Workstation;
+import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class Main extends Application {
+ public static Group root = new Group();
+ public static ArrayList<Immigrant> immigrants = new ArrayList<>();
+ public static ArrayList<Fortress> fortresses = new ArrayList<>();
+ public static Label status = new Label();
+
+ @Override
+ public void start(Stage stage) throws IOException, InterruptedException {
+ Rectangle rect = new Rectangle(3000, 2000, Color.WHITE);
+
+ root.getChildren().add(rect);
+ Fortress fortress = new Fortress("Eartha", 200, 200, new ArrayList<>(List.of(new Workstation("Torgrus"))), new ArrayList<>(List.of(new ThroneRoom("Halzorga"))));
+ fortresses.add(fortress);
+
+ immigrants.add(new Immigrant("1", "0", 50, 0,0, Ability.MASONIST));
+ immigrants.getFirst().setX(100);
+ immigrants.getFirst().setY(100);
+
+// BorderPane borderPane = new BorderPane();
+// borderPane.setCenter(root);
+// borderPane.setTop(status);
+
+// root.setStyle("-fx-background-color:rgb(186,153,122,0.7);");
+ root.getChildren().add(status);
+ Scene scene = new Scene(root, 1500, 700);
+
+ scene.setOnKeyPressed(event -> {
+ switch (event.getCode()) {
+ case LEFT -> moveImmigrants(-10, 0);
+ case RIGHT -> moveImmigrants(10, 0);
+ case UP -> moveImmigrants(0, -10);
+ case DOWN -> moveImmigrants(0, 10);
+ case INSERT -> {
+ try {
+ InsertDialog.display();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ case DELETE -> {
+ Iterator<Immigrant> iterator = immigrants.iterator();
+ while (iterator.hasNext()) {
+ Immigrant immigrant = iterator.next();
+ if (immigrant.isActive()) {
+ iterator.remove();
+ root.getChildren().remove(immigrant.getGroup());
+ }
+ }
+ processImmigrants();
+ }
+
+ case ESCAPE -> {
+ immigrants.forEach(immigrant -> {
+ immigrant.setActive(false);
+ });
+ }
+
+ case TAB -> {
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ alert.setTitle("Object list");
+ alert.setHeaderText("Object list");
+ alert.setContentText(immigrants.stream().map(Immigrant::toString).collect(Collectors.joining("\n")));
+ alert.showAndWait();
+ }
+ }
+ });
+ stage.setTitle("Hello!");
+ stage.setScene(scene);
+ ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+ scheduler.scheduleWithFixedDelay(() -> immigrants.forEach(immigrant -> {
+ immigrant.getThread().start();
+ }), 1, 1, TimeUnit.SECONDS);
+
+
+ stage.show();
+
+ }
+
+ private void moveImmigrants(double dx, double dy) {
+ immigrants.forEach(immigrant -> {
+ if (immigrant.isActive()) {
+ Platform.runLater(() -> {
+ immigrant.setX(immigrant.getX() + dx);
+ immigrant.setY(immigrant.getY() + dy);
+ });
+ }
+ });
+ }
+
+ public static void processImmigrants() {
+ status.setText("Active:");
+ immigrants.forEach(immigrant -> {
+ if (immigrant.isActive()) {
+ status.setText(status.getText() + " " + immigrant.getFullName());
+ }
+ });
+ }
+
+ public static void main(String[] args) {
+ launch();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/dialogs/ChangeDialog.java b/src/main/java/space/m0e/quga/oop/lab56maven/dialogs/ChangeDialog.java
new file mode 100644
index 0000000..1f005ab
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/dialogs/ChangeDialog.java
@@ -0,0 +1,96 @@
+package space.m0e.quga.oop.lab56maven.dialogs;
+
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.fxml.Initializable;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.scene.control.*;
+import javafx.stage.Modality;
+import javafx.stage.Stage;
+import space.m0e.quga.oop.lab56maven.entities.common.Ability;
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.ResourceBundle;
+
+public class ChangeDialog implements Initializable {
+ public static Stage window = null;
+ public static Scene scene;
+ public TextField firstName;
+ public TextField lastName;
+ public TextField age;
+ public TextField x;
+ public TextField y;
+ public ChoiceBox ability;
+ public Button submitButton;
+
+ public static Immigrant obj;
+
+ public static void display(Immigrant obj1) throws IOException {
+ obj = obj1;
+ Parent root = FXMLLoader.load(Objects.requireNonNull(ChangeDialog.class.getResource("change_dialog.fxml")));
+
+ window = new Stage();
+ window.initModality(Modality.APPLICATION_MODAL);
+ window.setTitle("Insert New Dialog");
+
+ scene = new Scene(root, 440, 350);
+ window.setScene(scene);
+ window.showAndWait();
+ }
+
+ @Override
+ public void initialize(URL location, ResourceBundle resources) {
+ Arrays.stream(Ability.values())
+ .forEach(a -> this.ability.getItems().add(a));
+ firstName.setText(obj.getFirstName());
+ lastName.setText(obj.getLastName());
+ age.setText(String.valueOf(obj.getAge()));
+ x.setText(String.valueOf(obj.getX()));
+ y.setText(String.valueOf(obj.getY()));
+ ability.setValue(obj.getAbility().toString());
+ }
+
+ public void sendError(String title, String description) {
+ Alert alert = new Alert(Alert.AlertType.ERROR);
+ alert.setTitle("Error");
+ alert.setHeaderText(title);
+ alert.setContentText(description);
+ alert.showAndWait();
+ }
+
+ @FXML
+ public void submitButtonHandler() {
+ if (age.getText().isEmpty() ||
+ x.getText().isEmpty() ||
+ y.getText().isEmpty() ||
+ firstName.getText().isEmpty() ||
+ lastName.getText().isEmpty() ||
+ ability.getValue() == null
+ ) {
+ sendError("You must enter all the fields", null);
+ return;
+ }
+ int inputAge = Integer.parseInt(age.getText());
+ double inputX = Double.parseDouble(x.getText());
+ double inputY = Double.parseDouble(y.getText());
+ Ability inputAbility = Ability.valueOf(ability.getValue().toString());
+ if (inputAge < 0) {
+ sendError("You must enter a valid age", null);
+ return;
+ }
+
+ obj.setX(inputX);
+ obj.setY(inputY);
+ obj.setAge(inputAge);
+ obj.setAbility(inputAbility);
+ obj.setFirstName(firstName.getText());
+ obj.setLastName(lastName.getText());
+
+ window.close();
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/dialogs/InsertDialog.java b/src/main/java/space/m0e/quga/oop/lab56maven/dialogs/InsertDialog.java
new file mode 100644
index 0000000..c0c72f3
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/dialogs/InsertDialog.java
@@ -0,0 +1,127 @@
+package space.m0e.quga.oop.lab56maven.dialogs;
+
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.fxml.Initializable;
+import javafx.geometry.Point2D;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.scene.control.*;
+import javafx.scene.control.Button;
+import javafx.scene.control.TextField;
+import javafx.stage.Modality;
+import javafx.stage.Stage;
+import space.m0e.quga.oop.lab56maven.Main;
+import space.m0e.quga.oop.lab56maven.entities.common.Ability;
+import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+import space.m0e.quga.oop.lab56maven.entities.micro.Nobel;
+
+import java.awt.*;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.ResourceBundle;
+
+public class InsertDialog implements Initializable {
+ public static Stage window = null;
+ public static Scene scene;
+ public TextField firstName;
+ public TextField lastName;
+ public TextField age;
+ public TextField x;
+ public TextField y;
+ public ChoiceBox ability;
+ public CheckBox generateItems;
+ public Button submitButton;
+ public ChoiceBox classSelection;
+
+ public static void display() throws IOException {
+ Parent root = FXMLLoader.load(Objects.requireNonNull(InsertDialog.class.getResource("insert_dialog.fxml")));
+
+ window = new Stage();
+ window.initModality(Modality.APPLICATION_MODAL);
+ window.setTitle("Insert New Dialog");
+
+ scene = new Scene(root, 440, 350);
+ window.setScene(scene);
+ window.showAndWait();
+ }
+
+ @Override
+ public void initialize(URL location, ResourceBundle resources) {
+ Point p = MouseInfo.getPointerInfo().getLocation();
+ Point2D local = Main.root.screenToLocal(p.x, p.y);
+ x.setText(String.valueOf(local.getX()));
+ y.setText(String.valueOf(local.getY()));
+ Arrays.stream(Ability.values())
+ .forEach(a -> this.ability.getItems().add(a));
+ generateItems.setSelected(true);
+ classSelection.getItems().addAll("Immigrant", "Dwarf", "Nobel");
+ classSelection.setValue("Immigrant");
+ }
+
+ public void sendError(String title, String description) {
+ Alert alert = new Alert(Alert.AlertType.ERROR);
+ alert.setTitle("Error");
+ alert.setHeaderText(title);
+ alert.setContentText(description);
+ alert.showAndWait();
+ }
+
+ @FXML
+ public void submitButtonHandler() {
+ if (age.getText().isEmpty() ||
+ x.getText().isEmpty() ||
+ y.getText().isEmpty() ||
+ firstName.getText().isEmpty() ||
+ lastName.getText().isEmpty() ||
+ ability.getValue() == null ||
+ classSelection.getValue() == null
+ ) {
+ sendError("You must enter all the fields", null);
+ return;
+ }
+ int inputAge = Integer.parseInt(age.getText());
+ double inputX = Double.parseDouble(x.getText());
+ double inputY = Double.parseDouble(y.getText());
+ Ability inputAbility = Ability.valueOf(ability.getValue().toString());
+ if (inputAge < 0) {
+ sendError("You must enter a valid age", null);
+ return;
+ }
+
+ switch (classSelection.getValue().toString()) {
+ case "Immigrant" -> {
+ Immigrant immigrant = new Immigrant(firstName.getText(), lastName.getText(), inputAge, inputX, inputY, inputAbility);
+ if (!generateItems.isSelected()) {
+ immigrant.setItems(new ArrayList<>());
+ }
+ immigrant.getThread().start();
+
+ Main.immigrants.add(immigrant);
+ }
+ case "Dwarf" -> {
+ Dwarf dwarf = new Dwarf(firstName.getText(), lastName.getText(), inputAge, inputX, inputY, inputAbility);
+ if (!generateItems.isSelected()) {
+ dwarf.setItems(new ArrayList<>());
+ }
+
+ Main.immigrants.add(dwarf);
+ }
+
+ case "Nobel" -> {
+ Nobel nobel = new Nobel(firstName.getText(), lastName.getText(), inputAge, inputX, inputY, inputAbility);
+ if (!generateItems.isSelected()) {
+ nobel.setItems(new ArrayList<>());
+ }
+
+ Main.immigrants.add(nobel);
+ }
+ }
+
+ window.close();
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Ability.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Ability.java
new file mode 100644
index 0000000..9fc2e68
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Ability.java
@@ -0,0 +1,5 @@
+package space.m0e.quga.oop.lab56maven.entities.common;
+
+public enum Ability {
+ WOODCUTTER, MASONIST
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Coordinates.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Coordinates.java
new file mode 100644
index 0000000..a68f178
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/common/Coordinates.java
@@ -0,0 +1,33 @@
+package space.m0e.quga.oop.lab56maven.entities.common;
+
+
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+
+public class Coordinates {
+ private double x;
+ private double y;
+ public Coordinates(double x, double y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public double getX() {
+ return x;
+ }
+
+ public void setX(double x) {
+ this.x = x;
+ }
+
+ public double getY() {
+ return y;
+ }
+
+ public void setY(double y) {
+ this.y = y;
+ }
+
+ public boolean isThere(Immigrant immigrant) {
+ return (int) immigrant.getX() == (int) this.x && (int) immigrant.getY() == (int) this.y;
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Fortress.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Fortress.java
new file mode 100644
index 0000000..36911f7
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Fortress.java
@@ -0,0 +1,129 @@
+package space.m0e.quga.oop.lab56maven.entities.macro;
+
+import javafx.scene.control.Label;
+import javafx.scene.image.Image;
+import javafx.scene.layout.*;
+import javafx.scene.paint.Color;
+import space.m0e.quga.oop.lab56maven.Main;
+import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+
+import java.util.ArrayList;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+public class Fortress {
+ private Image spriteImage = new Image(Objects.requireNonNull(Fortress.class.getResourceAsStream("fortress.jpeg")));;
+ private GridPane insideGroup = new GridPane(10, 10);
+ private Label nameLabel = new Label();
+ private Label countLabel = new Label();
+
+ ArrayList<Workstation> workstations = new ArrayList<>();
+ ArrayList<ThroneRoom> throneRooms = new ArrayList<>();
+
+ ArrayList<Dwarf> dwarves = new ArrayList<>();
+
+ private String name;
+ private double x;
+ private double y;
+ private VBox vBox = new VBox();
+
+ private GridPane dwarvesContainer = new GridPane(10, 10);
+
+ public Fortress(String name, double x, double y, ArrayList<Workstation> workstations, ArrayList<ThroneRoom> throneRooms) {
+ this.x = x;
+ this.y = y;
+
+ nameLabel.setText(name);
+ countLabel.setText("0");
+
+ nameLabel.setStyle("-fx-text-fill: red; -fx-font-size: 16px;");
+
+ RowConstraints insideRow = new RowConstraints();
+ insideRow.setPrefHeight(200);
+ ColumnConstraints insideColumn = new ColumnConstraints();
+ insideColumn.setPrefWidth(200);
+ for (int i = 0; i < 3; i++) {
+ insideGroup.getRowConstraints().add(insideRow);
+ insideGroup.getColumnConstraints().add(insideColumn);
+ }
+
+ insideGroup.setBackground(new Background(new BackgroundImage(spriteImage, BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT)));
+ this.workstations = workstations;
+ this.throneRooms = throneRooms;
+ int col = 0;
+ int row = 0;
+ for (Workstation w : this.workstations) {
+ if (col > 3) {
+ col = 0;
+ row++;
+ }
+ insideGroup.add(w.getGroup(), col, row);
+ col++;
+ }
+
+ for (ThroneRoom t : this.throneRooms) {
+ if (col > 3) {
+ col = 0;
+ row++;
+ }
+ insideGroup.add(t.getGroup(), col, row);
+ col++;
+ }
+
+ insideGroup.add(dwarvesContainer, 2, 2);
+
+ this.dwarvesContainer.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(3))));
+// dwarvesContainer.setMinSize(100 * 3, 100 * 3);
+
+ vBox.setLayoutX(x);
+ vBox.setLayoutY(y);
+ vBox.getChildren().addAll(nameLabel, insideGroup, countLabel);
+
+ this.vBox.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(3))));
+ Main.root.getChildren().add(vBox);
+ };
+
+ public void add(Dwarf dwarf) {
+ dwarves.add(dwarf);
+ dwarvesContainer.add(dwarf.getGroup(), dwarves.size() % 3, dwarves.size() / 3);
+ }
+
+ public void process() {
+ ArrayList<Immigrant> migration = (ArrayList<Immigrant>) Main.immigrants.stream().filter(immigrant -> immigrant.getClass().equals(Immigrant.class) && immigrant.getCoordinatesToFortress(this).isThere(immigrant)).collect(Collectors.toList());
+ migration.forEach(immigrant -> {
+ Dwarf dwarf = new Dwarf(immigrant, this);
+ Main.immigrants.add(dwarf);
+ this.dwarves.add(dwarf);
+ Main.root.getChildren().remove(immigrant.getGroup());
+ });
+ Main.immigrants.removeAll(migration);
+
+ countLabel.setText(String.valueOf(dwarves.size()));
+
+ workstations.forEach(Workstation::process);
+ throneRooms.forEach(ThroneRoom::process);
+ }
+
+ public double getX() {
+ return x;
+ }
+
+ public double getY() {
+ return y;
+ }
+
+ public ArrayList<Workstation> getWorkstations() {
+ return workstations;
+ }
+
+ public VBox getGroup() {
+ return vBox;
+ }
+
+ public ArrayList<Dwarf> getDwarves() {
+ return dwarves;
+ }
+
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/ThroneRoom.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/ThroneRoom.java
new file mode 100644
index 0000000..7a51cb5
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/ThroneRoom.java
@@ -0,0 +1,52 @@
+package space.m0e.quga.oop.lab56maven.entities.macro;
+
+import javafx.scene.control.Label;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.VBox;
+import space.m0e.quga.oop.lab56maven.Main;
+import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+import space.m0e.quga.oop.lab56maven.entities.micro.Nobel;
+
+import java.util.ArrayList;
+import java.util.Objects;
+import java.util.Optional;
+
+public class ThroneRoom {
+ private Image spriteImage = new Image(Objects.requireNonNull(ThroneRoom.class.getResourceAsStream("throne_room.jpg")));;
+ private ImageView sprite = new ImageView(spriteImage);
+ private Label nameLabel = new Label();
+ private Label countLabel = new Label();
+
+ private ArrayList<Nobel> nobels = new ArrayList<>();
+ String name;
+
+ private VBox vBox = new VBox();
+
+ public ThroneRoom(String name) {
+ this.name = name;
+
+ sprite.setFitHeight(150);
+ sprite.setFitWidth(150);
+ nameLabel.setText(name);
+
+ nameLabel.setStyle("-fx-text-fill: white; -fx-font-size: 16px; -fx-background-color: grey");
+ countLabel.setStyle("-fx-text-fill: white; -fx-font-size: 16px; -fx-background-color: grey");
+
+ vBox.getChildren().addAll(nameLabel, sprite, countLabel);
+ Main.root.getChildren().add(vBox);
+ };
+
+ public void process() {
+ countLabel.setText(String.valueOf(nobels.size()));
+ }
+
+ public ArrayList<Nobel> getNobels() {
+ return nobels;
+ }
+
+ public VBox getGroup() {
+ return vBox;
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Workstation.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Workstation.java
new file mode 100644
index 0000000..fe80a2b
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/macro/Workstation.java
@@ -0,0 +1,57 @@
+package space.m0e.quga.oop.lab56maven.entities.macro;
+
+import javafx.scene.control.Label;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.VBox;
+import javafx.scene.text.Font;
+import space.m0e.quga.oop.lab56maven.Main;
+import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+
+import java.util.ArrayList;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class Workstation {
+ private Image spriteImage = new Image(Objects.requireNonNull(Workstation.class.getResourceAsStream("workstation.png")));;
+ private ImageView sprite = new ImageView(spriteImage);
+ private Label nameLabel = new Label();
+ private Label countLabel = new Label();
+
+ private ArrayList<Dwarf> dwarves = new ArrayList<>();
+ private String name;
+
+ private VBox vBox = new VBox();
+
+ public Workstation(String name) {
+ this.name = name;
+
+ sprite.setFitHeight(150);
+ sprite.setFitWidth(150);
+ nameLabel.setText(name);
+
+ nameLabel.setStyle("-fx-text-fill: white; -fx-font-size: 16px; -fx-background-color: grey");
+ countLabel.setStyle("-fx-text-fill: white; -fx-font-size: 16px; -fx-background-color: grey");
+
+ vBox.getChildren().addAll(nameLabel, sprite, countLabel);
+ Main.root.getChildren().add(vBox);
+ };
+
+ public void process() {
+ Optional<Immigrant> entered = Main.immigrants.stream().filter(immigrant -> immigrant instanceof Dwarf && vBox.getBoundsInParent().contains(immigrant.getGroup().getBoundsInParent())).findFirst();
+ entered.ifPresent(immigrant -> {
+ dwarves.add((Dwarf) immigrant);
+ });
+ countLabel.setText(String.valueOf(dwarves.size()));
+ }
+
+ public ArrayList<Dwarf> getDwarves() {
+ return dwarves;
+ }
+
+ public VBox getGroup() {
+ return vBox;
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Dwarf.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Dwarf.java
new file mode 100644
index 0000000..d00f24f
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Dwarf.java
@@ -0,0 +1,92 @@
+package space.m0e.quga.oop.lab56maven.entities.micro;
+
+import javafx.scene.image.Image;
+import space.m0e.quga.oop.lab56maven.Main;
+import space.m0e.quga.oop.lab56maven.entities.common.Ability;
+import space.m0e.quga.oop.lab56maven.entities.common.Coordinates;
+import space.m0e.quga.oop.lab56maven.entities.macro.Fortress;
+import space.m0e.quga.oop.lab56maven.entities.macro.Workstation;
+
+import java.util.ArrayList;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Random;
+import java.util.stream.Collectors;
+
+public class Dwarf extends Immigrant {
+ private Fortress fortress = null;
+ private Workstation workstation = null;
+ public Image spriteImage = new Image(Objects.requireNonNull(Immigrant.class.getResourceAsStream("dwarf.png")));;
+ public Dwarf(String firstName, String lastName, int age, double x, double y, Ability ability) {
+ super(firstName, lastName, age, x, y, ability);
+ getSprite().setImage(spriteImage);
+ }
+
+ public Dwarf() {
+ this("Edzul", "Èrithbesmar", 35, 0, 0, Ability.values()[new Random().nextInt(Ability.values().length)]);
+ }
+
+ public Dwarf(Immigrant immigrant, Fortress fortress) {
+ this(immigrant.getFirstName(), immigrant.getLastName(), immigrant.getAge(), immigrant.getX(), immigrant.getY(), immigrant.getAbility());
+ this.setItems((ArrayList<String>) immigrant.getItems().clone());
+ this.setHp(this.getHp());
+ this.setMaxHp(this.getMaxHp());
+ this.fortress = fortress;
+ }
+
+ public Workstation findNearestWorkstation() {
+ ArrayList<Workstation> searchWorkstations = (ArrayList<Workstation>) fortress.getWorkstations().stream().filter(w -> w.getDwarves().isEmpty()).collect(Collectors.toList());
+ searchWorkstations.sort((o1, o2) -> (int) ((Math.abs(o1.getGroup().getLayoutX() - this.getX()) + Math.abs(o1.getGroup().getLayoutY() - this.getY())) - ((Math.abs(o2.getGroup().getLayoutX() - this.getX()) + Math.abs(o2.getGroup().getLayoutY() - this.getY())))));
+ if (searchWorkstations.isEmpty()) {
+ return null;
+ } else {
+ return searchWorkstations.get(0);
+ }
+ }
+
+ public Coordinates getCoordinatesToWorkstation(Workstation workstation) {
+ double workstationX = workstation.getGroup().getLayoutX() + workstation.getGroup().getBoundsInParent().getWidth() - this.getGroup().getBoundsInParent().getWidth();
+ double workstationY = workstation.getGroup().getLayoutX() + workstation.getGroup().getBoundsInParent().getHeight() - this.getGroup().getBoundsInParent().getHeight();
+ return new Coordinates(workstationX, workstationY);
+ }
+
+ @Override
+ public void moveAI() {
+ if (fortress == null) {
+ fortress = findNearestFortress();
+ fortress.getDwarves().add(this);
+ }
+ if (!fortress.getGroup().getBoundsInParent().contains(this.getGroup().getBoundsInParent())) {
+ super.moveAI();
+ } else {
+ if (workstation == null) {
+ workstation = findNearestWorkstation();
+ if (workstation == null) {
+ super.moveAI();
+ } else {
+ Coordinates workstationToMove = this.getCoordinatesToWorkstation(workstation);
+ if (!workstationToMove.isThere(this)) {
+ double workstationX = workstationToMove.getX();
+ double workstationY = workstationToMove.getY();
+
+ if (workstationX > this.getX()) {
+ this.setX(this.getX() + 1);
+ }
+
+ if (workstationX < this.getX()) {
+ this.setX(this.getX() - 1);
+ }
+
+ if (workstationY > this.getY()) {
+ this.setY(this.getY() + 1);
+ }
+
+ if (workstationY < this.getY()) {
+ this.setY(this.getY() - 1);
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Immigrant.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Immigrant.java
new file mode 100644
index 0000000..f91d0c2
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Immigrant.java
@@ -0,0 +1,333 @@
+package space.m0e.quga.oop.lab56maven.entities.micro;
+
+import javafx.geometry.Pos;
+import javafx.scene.control.Label;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.*;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
+import space.m0e.quga.oop.lab56maven.dialogs.ChangeDialog;
+import space.m0e.quga.oop.lab56maven.Main;
+import space.m0e.quga.oop.lab56maven.entities.common.Ability;
+import space.m0e.quga.oop.lab56maven.entities.common.Coordinates;
+import space.m0e.quga.oop.lab56maven.entities.macro.Fortress;
+import space.m0e.quga.oop.lab56maven.threads.ImmigrantThread;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.ForkJoinTask;
+import java.util.stream.Collectors;
+
+public class Immigrant implements Comparable<Immigrant>, Cloneable {
+ private String firstName;
+ private String lastName;
+ private int age;
+ private double x;
+ private double y;
+ private Ability ability;
+
+ private ArrayList<String> items = new ArrayList<>();
+ private static final String[] availableItems = new String[]{"axe", "pickaxe", "shovel", "piece of coal", "wood log"};
+
+ private double hp;
+ private double maxHp;
+ private static final double hpCap;
+
+ private boolean isActive = false;
+
+ private final VBox vBox = new VBox();
+ private final Label label;
+
+ private final ImageView sprite;
+ private final Rectangle hpBar;
+ private static final Image spriteImage = new Image(Objects.requireNonNull(Immigrant.class.getResourceAsStream("immigrant.png")));
+
+ private ImmigrantThread thread = new ImmigrantThread(this);
+
+ public Immigrant(String firstName, String lastName, int age, double x, double y, Ability ability) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.age = age;
+ this.x = x;
+ this.y = y;
+ this.ability = ability;
+
+ this.label = new Label(firstName + " " + lastName);
+ this.sprite = new ImageView(spriteImage);
+ this.hpBar = new Rectangle(50, 10);
+ this.hpBar.widthProperty().multiply(this.hp/this.maxHp);
+ this.hpBar.setFill(Color.LIME);
+ this.vBox.setSpacing(5);
+ this.vBox.setLayoutX(this.x);
+ this.vBox.setLayoutY(this.y);
+ this.vBox.getChildren().addAll(label, sprite, hpBar);
+ this.vBox.setAlignment(Pos.CENTER);
+ this.vBox.setOnMouseClicked(event -> {
+ switch (event.getButton()) {
+ case PRIMARY -> {
+ this.setActive(!this.isActive);
+ }
+ case SECONDARY -> {
+ try {
+ ChangeDialog.display(this);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+ this.thread = new ImmigrantThread(this);
+ Main.root.getChildren().add(this.getGroup());
+ }
+
+ public Immigrant() {
+ this("Edzul", "Èrithbesmar", 35, 0, 0, Ability.values()[new Random().nextInt(Ability.values().length)]);
+ }
+
+ public boolean isActive() {
+ return isActive;
+ }
+
+ public VBox getGroup() {
+ return vBox;
+ }
+
+ public ImageView getSprite() {
+ return sprite;
+ }
+
+ public Ability getAbility() {
+ return ability;
+ }
+
+ public void setAbility(Ability ability) {
+ this.ability = ability;
+ }
+
+ public ArrayList<String> getItems() {
+ return items;
+ }
+
+ public void setItems(ArrayList<String> items) {
+ this.items = items;
+ }
+
+ static {
+ hpCap = 100 + new Random().nextInt(50);
+ }
+
+ {
+ maxHp = 50 + new Random().nextInt(100);
+ hp = maxHp;
+ int itemCount = new Random().nextInt(1, availableItems.length);
+ ArrayList<String> itemPick = new ArrayList<String>(List.of(availableItems));
+ Collections.shuffle(itemPick);
+ items = (ArrayList<String>) itemPick.stream().limit(itemCount).collect(Collectors.toList());
+ }
+
+ public String getFullName() {
+ return this.firstName + " " + this.lastName;
+ }
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public String getLastName() {
+ return this.lastName;
+ }
+
+ public int getAge() {
+ return this.age;
+ }
+
+ public double getX() {
+ return this.x;
+ }
+
+ public double getY() {
+ return this.y;
+ }
+
+ public double getHp() {
+ return this.hp;
+ }
+
+ public double getMaxHp() {
+ return this.maxHp;
+ }
+
+ public double getHpCap() {
+ return Immigrant.hpCap;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ this.label.setText(firstName + " " + this.lastName);
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ this.label.setText(firstName + " " + this.lastName);
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public void setX(double x) {
+ this.x = x;
+ this.vBox.setLayoutX(this.x);
+ }
+
+ public void setY(double y) {
+ this.y = y;
+ this.vBox.setLayoutY(this.y);
+ }
+
+ public void setHp(double hp) {
+ this.hp = hp;
+ this.hpBar.widthProperty().multiply(this.hp / this.maxHp);
+ }
+
+ public void setMaxHp(double maxHp) {
+ this.maxHp = maxHp;
+ if (this.maxHp > Immigrant.hpCap) {
+ this.maxHp = Immigrant.hpCap;
+ }
+ this.hpBar.widthProperty().multiply(this.hp / this.maxHp);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s{Name=%s, Age=%d, Ability=%s, HP: %f/%f, Items: [%s]}", this.getClass().getSimpleName(), this.getFullName(), this.age, this.ability, this.hp, this.maxHp, String.join(", ", this.items));
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Immigrant immigrant = (Immigrant) o;
+
+ return Objects.equals(this.firstName, immigrant.firstName) && Objects.equals(this.lastName, immigrant.lastName);
+ }
+
+
+ public void setActive(boolean active) {
+ this.isActive = active;
+ if (this.isActive) {
+ this.vBox.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(3))));
+ } else {
+ this.vBox.setBorder(null);
+ }
+ Main.processImmigrants();
+ }
+
+
+ public void print() {
+ System.out.println(this);
+ }
+
+ public void grow() {
+ this.age++;
+ if (age > 24) {
+ this.maxHp--;
+ if (this.hp > this.maxHp) {
+ this.hp = this.maxHp;
+ }
+ } else {
+ this.maxHp++;
+ this.hp++;
+ }
+ }
+
+ public void hurt(double deltaHp) {
+ this.hp -= deltaHp;
+ if (this.hp < 0) {
+ this.hp = 0;
+ }
+ }
+
+ public void heal(double deltaHp) {
+ this.hp += deltaHp;
+ if (this.hp > this.maxHp) {
+ this.hp = this.maxHp;
+ }
+ }
+
+ public void attack(Immigrant immigrant) {
+ double deltaHp = new Random().nextDouble(maxHp);
+ immigrant.hurt(deltaHp);
+
+ System.out.printf("""
+ %s attacked %s (%f HP)
+ %s HP: %f/%f
+ """,
+ this.getFullName(), immigrant.getFullName(), deltaHp,
+ immigrant.getFullName(), immigrant.getHp(), immigrant.getMaxHp());
+ }
+
+ public Coordinates getCoordinatesToFortress(Fortress fortress) {
+ int dwarvesCount = fortress.getDwarves().size();
+
+ double fortressX = fortress.getX() + fortress.getGroup().getBoundsInParent().getWidth() / 2 - this.getGroup().getWidth() / 2;
+ double fortressY = fortress.getY() + fortress.getGroup().getBoundsInParent().getHeight() / 2 - this.getGroup().getHeight() / 2;
+ return new Coordinates(fortressX, fortressY);
+ }
+
+ public Fortress findNearestFortress() {
+ ArrayList<Fortress> searchFortresses = (ArrayList<Fortress>) Main.fortresses.clone();
+ searchFortresses.sort((o1, o2) -> {
+ return (int) ((Math.abs(o1.getX() - this.x) + Math.abs(o1.getY() - this.y)) - (Math.abs(o2.getX() - this.x) + Math.abs(o2.getY() - this.y)));
+ });
+ return searchFortresses.stream().filter(f -> f.getDwarves().size() < 9).findFirst().orElse(null);
+ }
+
+ public void moveAI() {
+ Fortress searchFortress = findNearestFortress();
+ Coordinates fortressToMove = this.getCoordinatesToFortress(searchFortress);
+ }
+
+ public void move(Coordinates coordinates) {
+ if (!coordinates.isThere(this)) {
+ double pointX = coordinates.getX();
+ double pointY = coordinates.getY();
+
+ if (pointX > this.getX()) {
+ this.setX(this.getX() + 1);
+ }
+
+ if (pointX < this.getX()) {
+ this.setX(this.getX() - 1);
+ }
+
+ if (pointY > this.getY()) {
+ this.setY(this.getY() + 1);
+ }
+
+ if (pointY < this.getY()) {
+ this.setY(this.getY() - 1);
+ }
+ }
+ }
+
+ @Override
+ public int compareTo(Immigrant o) {
+ return (int) (this.hp - o.hp);
+ }
+
+ @Override
+ public Immigrant clone() throws CloneNotSupportedException {
+ Immigrant immigrant = (Immigrant) super.clone();
+ immigrant.setItems((ArrayList<String>) this.items.clone());
+ return immigrant;
+ }
+
+ public ImmigrantThread getThread() {
+ return thread;
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Nobel.java b/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Nobel.java
new file mode 100644
index 0000000..ed9ba7a
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/entities/micro/Nobel.java
@@ -0,0 +1,19 @@
+package space.m0e.quga.oop.lab56maven.entities.micro;
+
+import javafx.scene.image.Image;
+import space.m0e.quga.oop.lab56maven.entities.common.Ability;
+
+import java.util.Objects;
+import java.util.Random;
+
+public class Nobel extends Immigrant {
+ public Image spriteImage = new Image(Objects.requireNonNull(Nobel.class.getResourceAsStream("nobel.png")));;
+ public Nobel(String firstName, String lastName, int age, double x, double y, Ability ability) {
+ super(firstName, lastName, age, x, y, ability);
+ getSprite().setImage(spriteImage);
+ }
+
+ public Nobel() {
+ this("Edzul", "Èrithbesmar", 35, 0, 0, Ability.values()[new Random().nextInt(Ability.values().length)]);
+ }
+}
diff --git a/src/main/java/space/m0e/quga/oop/lab56maven/threads/ImmigrantThread.java b/src/main/java/space/m0e/quga/oop/lab56maven/threads/ImmigrantThread.java
new file mode 100644
index 0000000..105f997
--- /dev/null
+++ b/src/main/java/space/m0e/quga/oop/lab56maven/threads/ImmigrantThread.java
@@ -0,0 +1,57 @@
+package space.m0e.quga.oop.lab56maven.threads;
+
+import javafx.application.Platform;
+import space.m0e.quga.oop.lab56maven.Main;
+import space.m0e.quga.oop.lab56maven.entities.common.Coordinates;
+import space.m0e.quga.oop.lab56maven.entities.macro.Fortress;
+import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
+import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
+
+import java.util.concurrent.TimeUnit;
+
+public class ImmigrantThread extends Thread {
+ public Immigrant getImmigrant() {
+ return immigrant;
+ }
+
+ public void setImmigrant(Immigrant immigrant) {
+ this.immigrant = immigrant;
+ }
+
+ private Immigrant immigrant;
+
+ public ImmigrantThread(Immigrant immigrant) {
+ super();
+ this.setName(String.format("ImmigrantThread_%s", immigrant.getFullName()));
+ this.immigrant = immigrant;
+ }
+
+ @Override
+ public void run() {
+ while (!isInterrupted()) {
+ if (immigrant != null && !immigrant.isActive()) {
+ try {
+ TimeUnit.MILLISECONDS.sleep(10);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ Fortress fortress = immigrant.findNearestFortress();
+ if (fortress != null) {
+ Coordinates moveTo = immigrant.getCoordinatesToFortress(fortress);
+ immigrant.move(moveTo);
+ if (moveTo.isThere(immigrant)) {
+ Platform.runLater(() -> {
+ Dwarf dwarf = new Dwarf(immigrant, fortress);
+ Main.immigrants.add(dwarf);
+ fortress.add(dwarf);
+ Main.root.getChildren().remove(immigrant.getGroup());
+ });
+ this.interrupt();
+ }
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.png b/src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.png
new file mode 100644
index 0000000..202216b
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.png
Binary files differ
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.png-autosave.kra b/src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.png-autosave.kra
new file mode 100644
index 0000000..02e5558
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/The Last of the Old style - Imgur.png-autosave.kra
Binary files differ
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/change_dialog.fxml b/src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/change_dialog.fxml
new file mode 100644
index 0000000..340e386
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/change_dialog.fxml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import java.lang.*?>
+<?import java.util.*?>
+<?import javafx.scene.*?>
+<?import javafx.scene.control.*?>
+<?import javafx.scene.layout.*?>
+
+<VBox xmlns="http://javafx.com/javafx"
+ xmlns:fx="http://javafx.com/fxml"
+ fx:controller="space.m0e.quga.oop.lab56maven.dialogs.ChangeDialog"
+ alignment="CENTER"
+ spacing="10"
+ prefHeight="400.0" prefWidth="600.0">
+ <HBox alignment="CENTER">
+ <Label text="First name: "/>
+ <TextField fx:id="firstName"/>
+ </HBox>
+
+ <HBox alignment="CENTER">
+ <Label text="Last name: "/>
+ <TextField fx:id="lastName"/>
+ </HBox>
+
+ <HBox alignment="CENTER">
+ <Label text="Age: "/>
+ <TextField fx:id="age"/>
+ </HBox>
+
+ <HBox alignment="CENTER" spacing="10">
+ <Label text="x:"/>
+ <TextField maxWidth="50" fx:id="x"/>
+
+ <Label text="y:"/>
+ <TextField maxWidth="50" fx:id="y"/>
+ </HBox>
+
+ <HBox alignment="CENTER">
+ <Label text="Ability: "/>
+ <ChoiceBox fx:id="ability"/>
+ </HBox>
+
+ <Button fx:id="submitButton" onMouseClicked="#submitButtonHandler" text="OK" alignment="BOTTOM_CENTER"/>
+</VBox>
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/insert_dialog.fxml b/src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/insert_dialog.fxml
new file mode 100644
index 0000000..538a6f9
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/dialogs/insert_dialog.fxml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import java.lang.*?>
+<?import java.util.*?>
+<?import javafx.scene.*?>
+<?import javafx.scene.control.*?>
+<?import javafx.scene.layout.*?>
+
+<VBox xmlns="http://javafx.com/javafx"
+ xmlns:fx="http://javafx.com/fxml"
+ fx:controller="space.m0e.quga.oop.lab56maven.dialogs.InsertDialog"
+ alignment="CENTER"
+ spacing="10"
+ prefHeight="400.0" prefWidth="600.0">
+ <HBox alignment="CENTER">
+ <Label text="Class: "/>
+ <ChoiceBox fx:id="classSelection" />
+ </HBox>
+ <HBox alignment="CENTER">
+ <Label text="First name: "/>
+ <TextField fx:id="firstName"/>
+ </HBox>
+
+ <HBox alignment="CENTER">
+ <Label text="Last name: "/>
+ <TextField fx:id="lastName"/>
+ </HBox>
+
+ <HBox alignment="CENTER">
+ <Label text="Age: "/>
+ <TextField fx:id="age"/>
+ </HBox>
+
+ <HBox alignment="CENTER" spacing="10">
+ <Label text="x:"/>
+ <TextField maxWidth="50" fx:id="x"/>
+
+ <Label text="y:"/>
+ <TextField maxWidth="50" fx:id="y"/>
+ </HBox>
+
+ <HBox alignment="CENTER">
+ <Label text="Ability: "/>
+ <ChoiceBox fx:id="ability"/>
+ </HBox>
+
+ <HBox alignment="CENTER">
+ <Label text="Generate items? "/>
+ <CheckBox fx:id="generateItems"/>
+ </HBox>
+ <Button fx:id="submitButton" onMouseClicked="#submitButtonHandler" text="OK" alignment="BOTTOM_CENTER"/>
+</VBox>
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/fortress.jpeg b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/fortress.jpeg
new file mode 100644
index 0000000..b323db6
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/fortress.jpeg
Binary files differ
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/throne_room.jpg b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/throne_room.jpg
new file mode 100644
index 0000000..483b7b7
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/throne_room.jpg
Binary files differ
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/workstation.png b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/workstation.png
new file mode 100644
index 0000000..8ca4a3c
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/macro/workstation.png
Binary files differ
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/dwarf.png b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/dwarf.png
new file mode 100644
index 0000000..567f194
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/dwarf.png
Binary files differ
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/immigrant.png b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/immigrant.png
new file mode 100644
index 0000000..fe90f69
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/immigrant.png
Binary files differ
diff --git a/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/nobel.png b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/nobel.png
new file mode 100644
index 0000000..60ea8a5
--- /dev/null
+++ b/src/main/resources/space/m0e/quga/oop/lab56maven/entities/micro/nobel.png
Binary files differ