From 32bc1b99866518bda03409dd8c81a2756656f44f Mon Sep 17 00:00:00 2001 From: Squibid Date: Mon, 3 Jun 2024 20:33:38 -0400 Subject: update game engine and example game --- src/main/java/los/numeros/ExampleGame/Main.java | 20 +++++++++++ .../numeros/ExampleGame/modules/ExampleModule.java | 17 +++++++++ src/main/java/los/numeros/GameEngine/Engine.java | 24 +++++++++++++ src/main/java/los/numeros/GameEngine/Module.java | 13 +++++++ src/main/java/los/numeros/example/Main.java | 20 ----------- .../los/numeros/example/modules/ExampleModule.java | 17 --------- src/main/java/los/numeros/gameEngine/Engine.java | 41 ---------------------- src/main/java/los/numeros/gameEngine/Module.java | 13 ------- 8 files changed, 74 insertions(+), 91 deletions(-) create mode 100644 src/main/java/los/numeros/ExampleGame/Main.java create mode 100644 src/main/java/los/numeros/ExampleGame/modules/ExampleModule.java create mode 100644 src/main/java/los/numeros/GameEngine/Engine.java create mode 100644 src/main/java/los/numeros/GameEngine/Module.java delete mode 100644 src/main/java/los/numeros/example/Main.java delete mode 100644 src/main/java/los/numeros/example/modules/ExampleModule.java delete mode 100644 src/main/java/los/numeros/gameEngine/Engine.java delete mode 100644 src/main/java/los/numeros/gameEngine/Module.java (limited to 'src/main/java/los/numeros') diff --git a/src/main/java/los/numeros/ExampleGame/Main.java b/src/main/java/los/numeros/ExampleGame/Main.java new file mode 100644 index 0000000..eb515c6 --- /dev/null +++ b/src/main/java/los/numeros/ExampleGame/Main.java @@ -0,0 +1,20 @@ +package los.numeros.ExampleGame; + +import java.util.function.BooleanSupplier; + +import los.numeros.ExampleGame.modules.*; +import los.numeros.GameEngine.Engine; +import los.numeros.GameEngine.Module; + +public class Main implements Engine { + BooleanSupplier running = () -> true; + Module modules[]; + + public Main() { + /* put the modules in an array */ + modules[modules.length] = new ExampleModule(); + + /* start the game */ + Engine.StartEngine(running, modules); + } +} diff --git a/src/main/java/los/numeros/ExampleGame/modules/ExampleModule.java b/src/main/java/los/numeros/ExampleGame/modules/ExampleModule.java new file mode 100644 index 0000000..9ab3179 --- /dev/null +++ b/src/main/java/los/numeros/ExampleGame/modules/ExampleModule.java @@ -0,0 +1,17 @@ +package los.numeros.ExampleGame.modules; + +import los.numeros.GameEngine.Module; + +public class ExampleModule implements Module { + @Override + public int init() + { + return 0; + } + + @Override + public int end() + { + return 0; + } +} diff --git a/src/main/java/los/numeros/GameEngine/Engine.java b/src/main/java/los/numeros/GameEngine/Engine.java new file mode 100644 index 0000000..2cc509a --- /dev/null +++ b/src/main/java/los/numeros/GameEngine/Engine.java @@ -0,0 +1,24 @@ +package los.numeros.GameEngine; + +import java.util.function.BooleanSupplier; + +public interface Engine { + public static int + StartEngine(BooleanSupplier running, Module modules[]) + { + /* run module inits */ + for (Module module : modules) { + module.init(); + } + + /* wait for the game to end */ + while (running.getAsBoolean()); + + /* run module ends */ + for (Module module : modules) { + module.end(); + } + + return 0; + } +} diff --git a/src/main/java/los/numeros/GameEngine/Module.java b/src/main/java/los/numeros/GameEngine/Module.java new file mode 100644 index 0000000..53b8e5e --- /dev/null +++ b/src/main/java/los/numeros/GameEngine/Module.java @@ -0,0 +1,13 @@ +package los.numeros.GameEngine; + +public interface Module { + /** + * code to run when the game is started + */ + public int init(); + + /** + * code to run when the game has ended + */ + public int end(); +} diff --git a/src/main/java/los/numeros/example/Main.java b/src/main/java/los/numeros/example/Main.java deleted file mode 100644 index 02fe35e..0000000 --- a/src/main/java/los/numeros/example/Main.java +++ /dev/null @@ -1,20 +0,0 @@ -package los.numeros.example; - -import java.util.function.BooleanSupplier; - -import los.numeros.example.modules.*; -import los.numeros.gameEngine.Engine; -import los.numeros.gameEngine.Module; - -public class Main implements Engine { - BooleanSupplier running = () -> true; - Module modules[]; - - public Main() { - /* put the modules in an array */ - modules[modules.length] = new ExampleModule(); - - /* start the game */ - Engine.StartEngine(running, modules); - } -} diff --git a/src/main/java/los/numeros/example/modules/ExampleModule.java b/src/main/java/los/numeros/example/modules/ExampleModule.java deleted file mode 100644 index 0e2d103..0000000 --- a/src/main/java/los/numeros/example/modules/ExampleModule.java +++ /dev/null @@ -1,17 +0,0 @@ -package los.numeros.example.modules; - -import los.numeros.gameEngine.Module; - -public class ExampleModule implements Module { - @Override - public int init() - { - return 0; - } - - @Override - public int end() - { - return 0; - } -} diff --git a/src/main/java/los/numeros/gameEngine/Engine.java b/src/main/java/los/numeros/gameEngine/Engine.java deleted file mode 100644 index ba09cf0..0000000 --- a/src/main/java/los/numeros/gameEngine/Engine.java +++ /dev/null @@ -1,41 +0,0 @@ -package los.numeros.gameEngine; - -import java.util.function.BooleanSupplier; - -public interface Engine { - public static int StartEngine(BooleanSupplier running, Module modules[]) - { - /* start game init tasks */ - GameStart(); - - /* run module inits */ - for (Module module : modules) { - module.init(); - } - - /* wait for the game to end */ - while (running.getAsBoolean()); - - /* run game end tasks */ - GameEnd(); - - /* run module ends */ - for (Module module : modules) { - module.end(); - } - - return 0; - } - - public static int - GameStart() - { - return 0; - } - - public static int - GameEnd() - { - return 0; - } -} diff --git a/src/main/java/los/numeros/gameEngine/Module.java b/src/main/java/los/numeros/gameEngine/Module.java deleted file mode 100644 index 0406615..0000000 --- a/src/main/java/los/numeros/gameEngine/Module.java +++ /dev/null @@ -1,13 +0,0 @@ -package los.numeros.gameEngine; - -public interface Module { - /** - * code to run when the game is started - */ - public int init(); - - /** - * code to run when the game has ended - */ - public int end(); -} -- cgit v1.2.1