From 8ca12377b0726ddf06a1ab88ec18578a190d1314 Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 11 Nov 2023 16:46:59 +0100
Subject: [PATCH 1/8] Delete oolab/gradlew
---
oolab/gradlew | 234 --------------------------------------------------
1 file changed, 234 deletions(-)
delete mode 100644 oolab/gradlew
diff --git a/oolab/gradlew b/oolab/gradlew
deleted file mode 100644
index 1b6c787..0000000
--- a/oolab/gradlew
+++ /dev/null
@@ -1,234 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright © 2015-2021 the original authors.
-#
-# Licensed 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.
-#
-
-##############################################################################
-#
-# Gradle start up script for POSIX generated by Gradle.
-#
-# Important for running:
-#
-# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
-# noncompliant, but you have some other compliant shell such as ksh or
-# bash, then to run this script, type that shell name before the whole
-# command line, like:
-#
-# ksh Gradle
-#
-# Busybox and similar reduced shells will NOT work, because this script
-# requires all of these POSIX shell features:
-# * functions;
-# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
-# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
-# * compound commands having a testable exit status, especially «case»;
-# * various built-in commands including «command», «set», and «ulimit».
-#
-# Important for patching:
-#
-# (2) This script targets any POSIX shell, so it avoids extensions provided
-# by Bash, Ksh, etc; in particular arrays are avoided.
-#
-# The "traditional" practice of packing multiple parameters into a
-# space-separated string is a well documented source of bugs and security
-# problems, so this is (mostly) avoided, by progressively accumulating
-# options in "$@", and eventually passing that to Java.
-#
-# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
-# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
-# see the in-line comments for details.
-#
-# There are tweaks for specific operating systems such as AIX, CygWin,
-# Darwin, MinGW, and NonStop.
-#
-# (3) This script is generated from the Groovy template
-# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
-# within the Gradle project.
-#
-# You can find Gradle at https://github.com/gradle/gradle/.
-#
-##############################################################################
-
-# Attempt to set APP_HOME
-
-# Resolve links: $0 may be a link
-app_path=$0
-
-# Need this for daisy-chained symlinks.
-while
- APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
- [ -h "$app_path" ]
-do
- ls=$( ls -ld "$app_path" )
- link=${ls#*' -> '}
- case $link in #(
- /*) app_path=$link ;; #(
- *) app_path=$APP_HOME$link ;;
- esac
-done
-
-APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
-
-APP_NAME="Gradle"
-APP_BASE_NAME=${0##*/}
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
-
-# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD=maximum
-
-warn () {
- echo "$*"
-} >&2
-
-die () {
- echo
- echo "$*"
- echo
- exit 1
-} >&2
-
-# OS specific support (must be 'true' or 'false').
-cygwin=false
-msys=false
-darwin=false
-nonstop=false
-case "$( uname )" in #(
- CYGWIN* ) cygwin=true ;; #(
- Darwin* ) darwin=true ;; #(
- MSYS* | MINGW* ) msys=true ;; #(
- NONSTOP* ) nonstop=true ;;
-esac
-
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
-
-
-# Determine the Java command to use to start the JVM.
-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
- if [ ! -x "$JAVACMD" ] ; then
- die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
- fi
-else
- JAVACMD=java
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-fi
-
-# Increase the maximum file descriptors if we can.
-if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
- case $MAX_FD in #(
- max*)
- MAX_FD=$( ulimit -H -n ) ||
- warn "Could not query maximum file descriptor limit"
- esac
- case $MAX_FD in #(
- '' | soft) :;; #(
- *)
- ulimit -n "$MAX_FD" ||
- warn "Could not set maximum file descriptor limit to $MAX_FD"
- esac
-fi
-
-# Collect all arguments for the java command, stacking in reverse order:
-# * args from the command line
-# * the main class name
-# * -classpath
-# * -D...appname settings
-# * --module-path (only if needed)
-# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
-
-# For Cygwin or MSYS, switch paths to Windows format before running java
-if "$cygwin" || "$msys" ; then
- APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
- CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
-
- JAVACMD=$( cygpath --unix "$JAVACMD" )
-
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
- for arg do
- if
- case $arg in #(
- -*) false ;; # don't mess with options #(
- /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
- [ -e "$t" ] ;; #(
- *) false ;;
- esac
- then
- arg=$( cygpath --path --ignore --mixed "$arg" )
- fi
- # Roll the args list around exactly as many times as the number of
- # args, so each arg winds up back in the position where it started, but
- # possibly modified.
- #
- # NB: a `for` loop captures its iteration list before it begins, so
- # changing the positional parameters here affects neither the number of
- # iterations, nor the values presented in `arg`.
- shift # remove old arg
- set -- "$@" "$arg" # push replacement arg
- done
-fi
-
-# Collect all arguments for the java command;
-# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
-# shell script including quotes and variable substitutions, so put them in
-# double quotes to make sure that they get re-expanded; and
-# * put everything else in single quotes, so that it's not re-expanded.
-
-set -- \
- "-Dorg.gradle.appname=$APP_BASE_NAME" \
- -classpath "$CLASSPATH" \
- org.gradle.wrapper.GradleWrapperMain \
- "$@"
-
-# Use "xargs" to parse quoted args.
-#
-# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
-#
-# In Bash we could simply go:
-#
-# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
-# set -- "${ARGS[@]}" "$@"
-#
-# but POSIX shell has neither arrays nor command substitution, so instead we
-# post-process each arg (as a line of input to sed) to backslash-escape any
-# character that might be a shell metacharacter, then use eval to reverse
-# that process (while maintaining the separation between arguments), and wrap
-# the whole thing up as a single "set" statement.
-#
-# This will of course break if any of these variables contains a newline or
-# an unmatched quote.
-#
-
-eval "set -- $(
- printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
- xargs -n1 |
- sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
- tr '\n' ' '
- )" '"$@"'
-
-exec "$JAVACMD" "$@"
From 919cc79402d5c70a5c3f07a23e05e8d966da82a1 Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 11 Nov 2023 16:47:10 +0100
Subject: [PATCH 2/8] Delete oolab/.gitignore
---
oolab/.gitignore | 42 ------------------------------------------
1 file changed, 42 deletions(-)
delete mode 100644 oolab/.gitignore
diff --git a/oolab/.gitignore b/oolab/.gitignore
deleted file mode 100644
index b63da45..0000000
--- a/oolab/.gitignore
+++ /dev/null
@@ -1,42 +0,0 @@
-.gradle
-build/
-!gradle/wrapper/gradle-wrapper.jar
-!**/src/main/**/build/
-!**/src/test/**/build/
-
-### IntelliJ IDEA ###
-.idea/modules.xml
-.idea/jarRepositories.xml
-.idea/compiler.xml
-.idea/libraries/
-*.iws
-*.iml
-*.ipr
-out/
-!**/src/main/**/out/
-!**/src/test/**/out/
-
-### Eclipse ###
-.apt_generated
-.classpath
-.factorypath
-.project
-.settings
-.springBeans
-.sts4-cache
-bin/
-!**/src/main/**/bin/
-!**/src/test/**/bin/
-
-### NetBeans ###
-/nbproject/private/
-/nbbuild/
-/dist/
-/nbdist/
-/.nb-gradle/
-
-### VS Code ###
-.vscode/
-
-### Mac OS ###
-.DS_Store
\ No newline at end of file
From f753fac5f2f4bd4e1d907bbbaf3d7feec7a6826f Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 11 Nov 2023 16:47:17 +0100
Subject: [PATCH 3/8] Delete oolab/gradlew.bat
---
oolab/gradlew.bat | 89 -----------------------------------------------
1 file changed, 89 deletions(-)
delete mode 100644 oolab/gradlew.bat
diff --git a/oolab/gradlew.bat b/oolab/gradlew.bat
deleted file mode 100644
index 107acd3..0000000
--- a/oolab/gradlew.bat
+++ /dev/null
@@ -1,89 +0,0 @@
-@rem
-@rem Copyright 2015 the original author or authors.
-@rem
-@rem Licensed under the Apache License, Version 2.0 (the "License");
-@rem you may not use this file except in compliance with the License.
-@rem 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, software
-@rem distributed under the License is distributed on an "AS IS" BASIS,
-@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-@rem See the License for the specific language governing permissions and
-@rem limitations under the License.
-@rem
-
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Resolve any "." and ".." in APP_HOME to make it shorter.
-for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto execute
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto execute
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
From e1a7bdc7c2691d82ccf642adc20fe79b108475f3 Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 11 Nov 2023 16:47:24 +0100
Subject: [PATCH 4/8] Delete oolab/.idea directory
---
oolab/.idea/.gitignore | 8 --------
oolab/.idea/gradle.xml | 17 -----------------
oolab/.idea/misc.xml | 10 ----------
oolab/.idea/vcs.xml | 6 ------
4 files changed, 41 deletions(-)
delete mode 100644 oolab/.idea/.gitignore
delete mode 100644 oolab/.idea/gradle.xml
delete mode 100644 oolab/.idea/misc.xml
delete mode 100644 oolab/.idea/vcs.xml
diff --git a/oolab/.idea/.gitignore b/oolab/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/oolab/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/oolab/.idea/gradle.xml b/oolab/.idea/gradle.xml
deleted file mode 100644
index 2a65317..0000000
--- a/oolab/.idea/gradle.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/oolab/.idea/misc.xml b/oolab/.idea/misc.xml
deleted file mode 100644
index 10f381e..0000000
--- a/oolab/.idea/misc.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/oolab/.idea/vcs.xml b/oolab/.idea/vcs.xml
deleted file mode 100644
index 6c0b863..0000000
--- a/oolab/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
From 4c8d0f0f1549edd35cb18813ef0e9a210cef0909 Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 11 Nov 2023 16:49:30 +0100
Subject: [PATCH 5/8] Update .gitignore
---
.gitignore | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index d16bbbe..6c0b6f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,4 +74,52 @@ fabric.properties
.idea/httpRequests
# Android studio 3.1+ serialized cache file
-.idea/caches/build_file_checksums.ser
\ No newline at end of file
+.idea/caches/build_file_checksums.ser
+
+.gradle
+build/
+!gradle/wrapper/gradle-wrapper.jar
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
+
+oolab/.idea/
+oolab/gradlew.bat
+oolab/gradlew
+oolab/.gitignore
From 851c0aaac218cda2550f4ada575c71afdf51ee25 Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 11 Nov 2023 16:49:51 +0100
Subject: [PATCH 6/8] Update README.md
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 586c886..263f8df 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,6 @@
Kamil Rudny
Piątek 11:20
Gerard
-https://gitexercises.fracz.com/committer/4a757cf05e8a3f76ed8599ee38a79085391ed03d?email=karudny@student.agh.edu.pl
\ No newline at end of file
+https://gitexercises.fracz.com/committer/4a757cf05e8a3f76ed8599ee38a79085391ed03d?email=karudny@student.agh.edu.pl
+
+Za zadania z gita z srebrnej skrzynki chce marchewkę lab, a z brązowej weterynarza.
From 89c66040e0591f09435c6a527af85676f7a387d3 Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 16 Dec 2023 19:51:49 +0100
Subject: [PATCH 7/8] JavaFX setup
---
oolab/build.gradle | 44 ++++++++-------
.../main/java/agh/ics/oop/SimulationApp.java | 10 ++++
oolab/src/main/java/agh/ics/oop/World.java | 53 +++++++++++--------
.../agh/ics/oop/model/SimulationEngine.java | 2 -
4 files changed, 68 insertions(+), 41 deletions(-)
create mode 100644 oolab/src/main/java/agh/ics/oop/SimulationApp.java
diff --git a/oolab/build.gradle b/oolab/build.gradle
index 2618d76..e944566 100644
--- a/oolab/build.gradle
+++ b/oolab/build.gradle
@@ -1,31 +1,39 @@
plugins {
- id 'application'
- id 'java'
+ id("application")
+ id("java")
+ id("org.openjfx.javafxplugin") version "0.0.13"
}
-group = 'org.example'
-version = '1.0-SNAPSHOT'
+application {
+ getMainClass().set("agh.ics.oop.WorldGUI")
+}
-repositories {
- mavenCentral()
+java {
+ toolchain {
+ languageVersion.set(JavaLanguageVersion.of(17))
+ }
}
-dependencies {
- testImplementation platform('org.junit:junit-bom:5.9.1')
- testImplementation 'org.junit.jupiter:junit-jupiter'
- testImplementation 'junit:junit:4.13.1'
+group = "org.example"
+version = "1.0-SNAPSHOT"
+
+repositories {
+ mavenCentral()
}
-test {
- useJUnitPlatform()
+javafx {
+ version = "17"
+ modules("javafx.controls", "javafx.fxml")
}
-application {
- getMainClass().set('agh.ics.oop.World')
+dependencies {
+ implementation("junit:junit:4.13.1")
+ implementation("junit:junit:4.13.1")
+ implementation("junit:junit:4.13.1")
+ testImplementation(platform("org.junit:junit-bom:5.9.1"))
+ testImplementation("org.junit.jupiter:junit-jupiter")
}
-java {
- toolchain {
- languageVersion.set(JavaLanguageVersion.of(17))
- }
+tasks.test {
+ useJUnitPlatform()
}
\ No newline at end of file
diff --git a/oolab/src/main/java/agh/ics/oop/SimulationApp.java b/oolab/src/main/java/agh/ics/oop/SimulationApp.java
new file mode 100644
index 0000000..a23e6e9
--- /dev/null
+++ b/oolab/src/main/java/agh/ics/oop/SimulationApp.java
@@ -0,0 +1,10 @@
+package agh.ics.oop;
+
+import javafx.application.Application;
+import javafx.stage.Stage;
+
+public class SimulationApp extends Application {
+ public void start(Stage primaryStage){
+ primaryStage.show();
+ }
+}
diff --git a/oolab/src/main/java/agh/ics/oop/World.java b/oolab/src/main/java/agh/ics/oop/World.java
index 841f5a6..d51ed15 100644
--- a/oolab/src/main/java/agh/ics/oop/World.java
+++ b/oolab/src/main/java/agh/ics/oop/World.java
@@ -1,6 +1,7 @@
package agh.ics.oop;
import agh.ics.oop.model.*;
+import javafx.application.Application;
import org.w3c.dom.css.Rect;
import java.util.ArrayList;
@@ -30,31 +31,41 @@ public static void run(List directions) {
}
public static void main(String[] args) {
- List directions = new ArrayList<>();
-
- String[] args1 = {"f", "f","f","f","f","f","f","f","f"};
-
- try {
- List listOfSimulations = new ArrayList<>();
- ConsoleMapDisplay listener = new ConsoleMapDisplay();
- for(int i = 0; i < 20; i++) {
- directions = OptionsParser.Parser(args1);
- List positions = List.of(new Vector2d(2,2), new Vector2d(3,4), new Vector2d(0,0));
- GrassField map = new GrassField(10);
- map.addListener(listener);
- listOfSimulations.add(new Simulation(positions, directions, map));
- }
+ Application.launch(SimulationApp.class, args);
- SimulationEngine simulationEngine = new SimulationEngine(listOfSimulations);
- simulationEngine.runAsyncInThreadPool();
- simulationEngine.awaitSimulationsEnds();
- System.out.println("koniec programu");
- } catch (IllegalArgumentException | InterruptedException e){
- e.printStackTrace();
- }
+
+
+
+
+// List directions = new ArrayList<>();
+//
+// String[] args1 = {"f", "f","f","f","f","f","f","f","f"};
+// try {
+// List listOfSimulations = new ArrayList<>();
+// ConsoleMapDisplay listener = new ConsoleMapDisplay();
+// for(int i = 0; i < 20; i++) {
+// directions = OptionsParser.Parser(args1);
+// List positions = List.of(new Vector2d(2,2), new Vector2d(3,4), new Vector2d(0,0));
+// GrassField map = new GrassField(10);
+// map.addListener(listener);
+// listOfSimulations.add(new Simulation(positions, directions, map));
+// }
+//
+//
+// SimulationEngine simulationEngine = new SimulationEngine(listOfSimulations);
+// simulationEngine.runAsyncInThreadPool();
+// simulationEngine.awaitSimulationsEnds();
+//
+// System.out.println("koniec programu");
+//
+// } catch (IllegalArgumentException | InterruptedException e){
+// e.printStackTrace();
+// }
+
+
}
diff --git a/oolab/src/main/java/agh/ics/oop/model/SimulationEngine.java b/oolab/src/main/java/agh/ics/oop/model/SimulationEngine.java
index 8d35daf..c4f755b 100644
--- a/oolab/src/main/java/agh/ics/oop/model/SimulationEngine.java
+++ b/oolab/src/main/java/agh/ics/oop/model/SimulationEngine.java
@@ -29,7 +29,6 @@ public void runAsync() {
thread.start();
}
}
-
public void awaitSimulationsEnds() throws InterruptedException
{
for(Thread thread : simulationThreads) {
@@ -43,7 +42,6 @@ public void awaitSimulationsEnds() throws InterruptedException
}
}
}
-
public void runAsyncInThreadPool(){
simulatorExecutor = newFixedThreadPool(4);
simulationList.forEach(simulatorExecutor :: submit);
From c8e731f62dbaa4283803fb8860633e3803fc5e63 Mon Sep 17 00:00:00 2001
From: Kamil Rudny <134285490+krudny@users.noreply.github.com>
Date: Sat, 16 Dec 2023 21:19:42 +0100
Subject: [PATCH 8/8] finished
---
.../src/main/java/agh/ics/oop/Simulation.java | 21 +--
.../main/java/agh/ics/oop/SimulationApp.java | 32 +++-
oolab/src/main/java/agh/ics/oop/World.java | 35 -----
.../main/java/agh/ics/oop/model/WorldMap.java | 2 +
.../oop/presenter/SimulationPresenter.java | 137 ++++++++++++++++++
oolab/src/main/resources/simulation.fxml | 26 ++++
6 files changed, 206 insertions(+), 47 deletions(-)
create mode 100644 oolab/src/main/java/agh/ics/oop/presenter/SimulationPresenter.java
create mode 100644 oolab/src/main/resources/simulation.fxml
diff --git a/oolab/src/main/java/agh/ics/oop/Simulation.java b/oolab/src/main/java/agh/ics/oop/Simulation.java
index 0794c18..1939b7d 100644
--- a/oolab/src/main/java/agh/ics/oop/Simulation.java
+++ b/oolab/src/main/java/agh/ics/oop/Simulation.java
@@ -5,7 +5,7 @@
import java.util.ArrayList;
import java.util.List;
-public class Simulation implements Runnable{
+public class Simulation extends Thread implements Runnable{
private final List Animals = new ArrayList<>();
private List Moves = new ArrayList<>();
private final WorldMap Map;
@@ -28,15 +28,16 @@ public Simulation(List positions, List moves, WorldMap
public synchronized void run() {
int animal_count = Animals.size();
- int cnt = 0;
- for(MoveDirection currentMove : Moves) {
- Animal current_animal = Animals.get(0);
- Animals.remove(0);
- System.out.println("Zwierze " + ((cnt % animal_count) + 1) + " " + current_animal.toString());
- Map.move(current_animal, currentMove);
-
- cnt += 1;
- Animals.add(current_animal);
+ try {
+ for(MoveDirection currentMove : Moves) {
+ Thread.sleep(500);
+ Animal current_animal = Animals.get(0);
+ Animals.remove(0);
+ Map.move(current_animal, currentMove);
+ Animals.add(current_animal);
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}
diff --git a/oolab/src/main/java/agh/ics/oop/SimulationApp.java b/oolab/src/main/java/agh/ics/oop/SimulationApp.java
index a23e6e9..9abd9bc 100644
--- a/oolab/src/main/java/agh/ics/oop/SimulationApp.java
+++ b/oolab/src/main/java/agh/ics/oop/SimulationApp.java
@@ -1,10 +1,38 @@
package agh.ics.oop;
+import agh.ics.oop.model.ConsoleMapDisplay;
+import agh.ics.oop.model.GrassField;
+import agh.ics.oop.presenter.SimulationPresenter;
import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Scene;
+import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
+import java.io.IOException;
+
public class SimulationApp extends Application {
- public void start(Stage primaryStage){
+
+ @Override
+ public void start(Stage primaryStage) throws IOException {
+ FXMLLoader loader = new FXMLLoader();
+ loader.setLocation(getClass().getClassLoader().getResource("simulation.fxml"));
+ BorderPane viewRoot = loader.load();
+ SimulationPresenter presenter = loader.getController();
+ GrassField grassField = new GrassField(10);
+ presenter.setWorldMap(grassField);
+ grassField.addListener(presenter);
+
+ configureStage(primaryStage, viewRoot);
primaryStage.show();
}
-}
+
+ private void configureStage(Stage primaryStage, BorderPane viewRoot) {
+ var scene = new Scene(viewRoot);
+ primaryStage.setScene(scene);
+ primaryStage.setTitle("Simulation app");
+ primaryStage.minWidthProperty().bind(viewRoot.minWidthProperty());
+ primaryStage.minHeightProperty().bind(viewRoot.minHeightProperty());
+ }
+}
\ No newline at end of file
diff --git a/oolab/src/main/java/agh/ics/oop/World.java b/oolab/src/main/java/agh/ics/oop/World.java
index d51ed15..ae8bb12 100644
--- a/oolab/src/main/java/agh/ics/oop/World.java
+++ b/oolab/src/main/java/agh/ics/oop/World.java
@@ -33,40 +33,5 @@ public static void run(List directions) {
public static void main(String[] args) {
Application.launch(SimulationApp.class, args);
-
-
-
-
-
-
-
-// List directions = new ArrayList<>();
-//
-// String[] args1 = {"f", "f","f","f","f","f","f","f","f"};
-// try {
-// List listOfSimulations = new ArrayList<>();
-// ConsoleMapDisplay listener = new ConsoleMapDisplay();
-// for(int i = 0; i < 20; i++) {
-// directions = OptionsParser.Parser(args1);
-// List positions = List.of(new Vector2d(2,2), new Vector2d(3,4), new Vector2d(0,0));
-// GrassField map = new GrassField(10);
-// map.addListener(listener);
-// listOfSimulations.add(new Simulation(positions, directions, map));
-// }
-//
-//
-// SimulationEngine simulationEngine = new SimulationEngine(listOfSimulations);
-// simulationEngine.runAsyncInThreadPool();
-// simulationEngine.awaitSimulationsEnds();
-//
-// System.out.println("koniec programu");
-//
-// } catch (IllegalArgumentException | InterruptedException e){
-// e.printStackTrace();
-// }
-
-
-
-
}
}
diff --git a/oolab/src/main/java/agh/ics/oop/model/WorldMap.java b/oolab/src/main/java/agh/ics/oop/model/WorldMap.java
index 5371a75..b31ef44 100644
--- a/oolab/src/main/java/agh/ics/oop/model/WorldMap.java
+++ b/oolab/src/main/java/agh/ics/oop/model/WorldMap.java
@@ -44,4 +44,6 @@ public interface WorldMap extends MoveValidator {
WorldElement objectAt(Vector2d position);
String getId();
+
+ public Boundary getCurrentBounds();
}
\ No newline at end of file
diff --git a/oolab/src/main/java/agh/ics/oop/presenter/SimulationPresenter.java b/oolab/src/main/java/agh/ics/oop/presenter/SimulationPresenter.java
new file mode 100644
index 0000000..671b6eb
--- /dev/null
+++ b/oolab/src/main/java/agh/ics/oop/presenter/SimulationPresenter.java
@@ -0,0 +1,137 @@
+package agh.ics.oop.presenter;
+
+import agh.ics.oop.OptionsParser;
+import agh.ics.oop.Simulation;
+import agh.ics.oop.model.SimulationEngine;
+import agh.ics.oop.model.*;
+import javafx.application.Platform;
+import javafx.fxml.FXML;
+import javafx.geometry.Pos;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.GridPane;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SimulationPresenter implements MapChangeListener {
+ private WorldMap worldMap;
+ public void setWorldMap(WorldMap worldMap) {
+ this.worldMap = worldMap;
+ }
+
+ @FXML
+ private Label infoLabel;
+ @FXML
+ private TextField movesListTextField;
+ @FXML
+ private Label moveInfoLabel;
+ @FXML
+ private Button startButton;
+
+ private void clearGrid() {
+ mapGrid.getChildren().retainAll(mapGrid.getChildren().get(0));
+ mapGrid.getColumnConstraints().clear();
+ mapGrid.getRowConstraints().clear();
+ }
+
+ private void drawAxes(Boundary boundary) {
+ drawXAxis(boundary);
+ drawYAxis(boundary);
+ Label label = new Label("x/y");
+ label.setMinWidth(50);
+ label.setMinHeight(50);
+ label.setAlignment(Pos.CENTER);
+ mapGrid.add(label, 0, 0);
+
+
+ }
+
+ private void drawXAxis(Boundary boundary) {
+ for (int j = boundary.MAP_LEFT_BOTTOM().getX(); j <= boundary.MAP_RIGHT_TOP().getX(); j++) {
+ Label label = new Label(Integer.toString(j));
+ label.setMinWidth(50);
+ label.setMinHeight(50);
+ label.setAlignment(Pos.CENTER);
+ mapGrid.add(label, j + 1 - boundary.MAP_LEFT_BOTTOM().getX(), 0); // Dodajemy etykiety osi X na górze siatki
+ }
+ }
+
+ private void drawYAxis(Boundary boundary) {
+ for (int i = boundary.MAP_LEFT_BOTTOM().getY(); i <= boundary.MAP_RIGHT_TOP().getY(); i++) {
+ Label label = new Label(Integer.toString(i));
+ label.setMinWidth(50);
+ label.setMinHeight(50);
+ label.setAlignment(Pos.CENTER);
+ mapGrid.add(label, 0, boundary.MAP_RIGHT_TOP().getY() - i + 1); // Dodajemy etykiety osi Y po lewej stronie siatki
+ }
+ }
+
+ @FXML
+ public void drawMap() {
+ clearGrid();
+ Boundary boundary = worldMap.getCurrentBounds();
+ drawAxes(boundary);
+ drawGrid(boundary);
+ infoLabel.setText("");
+ }
+
+ private void drawGrid(Boundary boundary) {
+ for (int i = boundary.MAP_LEFT_BOTTOM().getY(); i <= boundary.MAP_RIGHT_TOP().getY(); i++) {
+ for (int j = boundary.MAP_LEFT_BOTTOM().getX(); j <= boundary.MAP_RIGHT_TOP().getX(); j++) {
+ Vector2d position = new Vector2d(j, i);
+ drawGridCell(position, j - boundary.MAP_LEFT_BOTTOM().getX() + 1, boundary.MAP_RIGHT_TOP().getY() - i + 1);
+ }
+ }
+ }
+
+ private void drawGridCell(Vector2d position, int column, int row) {
+ WorldElement element = worldMap.objectAt(position);
+ Label label = createLabelForElement(element);
+ mapGrid.add(label, column, row);
+ }
+
+ private Label createLabelForElement(WorldElement element) {
+ Label label;
+ if (element != null) {
+ label = new Label(element.toString());
+ } else {
+ label = new Label(" ");
+ }
+ label.setMinWidth(50);
+ label.setMinHeight(50);
+ label.setAlignment(Pos.CENTER);
+ return label;
+ }
+
+
+ @Override
+ public void mapChanged(WorldMap worldMap, String message) {
+ Platform.runLater(() -> {
+ this.drawMap();
+ moveInfoLabel.setText(message);
+ });
+ }
+ @FXML
+ public void onSimulationStartClicked() {
+ String movesString = movesListTextField.getText();
+ try {
+ List movesList = OptionsParser.Parser(movesString.split(""));
+ List listOfSimulations = new ArrayList<>();
+ listOfSimulations.add(new Simulation(List.of(new Vector2d(3,2), new Vector2d(5,5)), movesList, worldMap));
+
+ SimulationEngine simulationEngine = new SimulationEngine(listOfSimulations);
+ simulationEngine.runAsync();
+
+
+
+ Platform.runLater(() -> startButton.setDisable(true));
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ @FXML
+ private GridPane mapGrid;
+}
\ No newline at end of file
diff --git a/oolab/src/main/resources/simulation.fxml b/oolab/src/main/resources/simulation.fxml
new file mode 100644
index 0000000..22a00bb
--- /dev/null
+++ b/oolab/src/main/resources/simulation.fxml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file