diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..a5815d5 --- /dev/null +++ b/build.gradle @@ -0,0 +1,14 @@ +plugins { + id 'java' +} + +group 'rahnzo.kata.solid' +version '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/src/main/java/game/domain/core/DynamoDB.java b/src/main/java/game/domain/core/DynamoDB.java new file mode 100644 index 0000000..aa4b743 --- /dev/null +++ b/src/main/java/game/domain/core/DynamoDB.java @@ -0,0 +1,21 @@ +package game.domain.core; + +import game.domain.player.PlayerRecord; +import game.domain.player.PlayerInfo; + +import java.util.Set; + +public class DynamoDB { + public Set getUserInfo(long userId) { + // Get a db connection and query + return Set.of(new PlayerInfo("current-level", "level_1")); + } + + public void saveOrUpdate(PlayerRecord playerRecord) { + // Save or update player to db + } + + public void delete(long userId) { + // Delete player from db + } +} diff --git a/src/main/java/game/domain/core/GameCore.java b/src/main/java/game/domain/core/GameCore.java new file mode 100644 index 0000000..cdceb3a --- /dev/null +++ b/src/main/java/game/domain/core/GameCore.java @@ -0,0 +1,19 @@ +package game.domain.core; + +import game.domain.input.UserAction; + +public class GameCore { + + public void initializeAllGameObjects() { + // Load all objects + // Init game parameters with complex and large operations + } + + public void processInput(UserAction userAction) { + // Apply logic on event, calling hero actions + } + + public void handleHardwareEvents(Object hardwareEvent) { + // Apply certain actions based on hardware events + } +} diff --git a/src/main/java/game/domain/core/GameEventObserver.java b/src/main/java/game/domain/core/GameEventObserver.java new file mode 100644 index 0000000..4c8b545 --- /dev/null +++ b/src/main/java/game/domain/core/GameEventObserver.java @@ -0,0 +1,32 @@ +package game.domain.core; + +import game.domain.hero.HeroInteract; + +public class GameEventObserver { + + private final World world; + private final HeroInteract heroInteract; + + // This works by injection + public GameEventObserver(World world, HeroInteract heroInteract) { + this.world = world; + this.heroInteract = heroInteract; + } + + public void observeHeroPunch(Object obj) { + // Do some task with punch event + world.processEvent(obj); + heroInteract.processEvent(obj); + } + + public void observeHeroMagicCasting(Object obj) { + // Do some task with magic casting + world.processEvent(obj); + heroInteract.processEvent(obj); + } + + public void observeHeroJump(Object obj) { + // Do some task with jump event + world.processEvent(obj); + } +} diff --git a/src/main/java/game/domain/core/World.java b/src/main/java/game/domain/core/World.java new file mode 100644 index 0000000..27f2efa --- /dev/null +++ b/src/main/java/game/domain/core/World.java @@ -0,0 +1,16 @@ +package game.domain.core; + +import game.domain.music.SpotifyPlugin; + +public class World { + + private final SpotifyPlugin spotifyPlugin = new SpotifyPlugin(); + + public void runWorld() { + spotifyPlugin.playMusic(); + } + + public void processEvent(Object obj) { + // Process a world event + } +} diff --git a/src/main/java/game/domain/hero/Hero.java b/src/main/java/game/domain/hero/Hero.java new file mode 100644 index 0000000..4845cf5 --- /dev/null +++ b/src/main/java/game/domain/hero/Hero.java @@ -0,0 +1,6 @@ +package game.domain.hero; + +public interface Hero { + void punch(); + void jump(); +} diff --git a/src/main/java/game/domain/hero/HeroInteract.java b/src/main/java/game/domain/hero/HeroInteract.java new file mode 100644 index 0000000..ad5a107 --- /dev/null +++ b/src/main/java/game/domain/hero/HeroInteract.java @@ -0,0 +1,16 @@ +package game.domain.hero; + +import java.util.Set; + +public class HeroInteract { + + private final Set heroes; + + public HeroInteract(Set heroes) { + this.heroes = heroes; + } + + public void processEvent(Object obj) { + // Process a event between heroes + } +} diff --git a/src/main/java/game/domain/hero/MagicianHero.java b/src/main/java/game/domain/hero/MagicianHero.java new file mode 100644 index 0000000..ef781b8 --- /dev/null +++ b/src/main/java/game/domain/hero/MagicianHero.java @@ -0,0 +1,14 @@ +package game.domain.hero; + +public class MagicianHero extends MeleeHero { + + public void castMagic() { + gameEventObserver.observeHeroMagicCasting(this); + // Do some casting action + } + + @Override + public void punch() { + // This hero is a magician. Does not punch. + } +} diff --git a/src/main/java/game/domain/hero/MeleeHero.java b/src/main/java/game/domain/hero/MeleeHero.java new file mode 100644 index 0000000..ab8bea1 --- /dev/null +++ b/src/main/java/game/domain/hero/MeleeHero.java @@ -0,0 +1,22 @@ +package game.domain.hero; + +import game.domain.core.GameEventObserver; + +public class MeleeHero implements Hero { + private int punchPower; + protected GameEventObserver gameEventObserver; + + @Override + public void punch() { + gameEventObserver.observeHeroPunch(this); + // process hero actions for hero + } + + @Override + public void jump() { + gameEventObserver.observeHeroJump(this); + // process jump action for hero + } + + //TODO: Next week this class will change in order to support a new turbo punch feature +} diff --git a/src/main/java/game/domain/input/ButtonAction.java b/src/main/java/game/domain/input/ButtonAction.java new file mode 100644 index 0000000..7e4324f --- /dev/null +++ b/src/main/java/game/domain/input/ButtonAction.java @@ -0,0 +1,6 @@ +package game.domain.input; + +public enum ButtonAction { + JUMP, + PUNCH +} diff --git a/src/main/java/game/domain/input/GamepadInput.java b/src/main/java/game/domain/input/GamepadInput.java new file mode 100644 index 0000000..37eab77 --- /dev/null +++ b/src/main/java/game/domain/input/GamepadInput.java @@ -0,0 +1,32 @@ +package game.domain.input; + +import game.domain.core.GameCore; + +public class GamepadInput implements PlayerInput { + + public final GameCore gameCore; + + public GamepadInput(GameCore gameCore) { + this.gameCore = gameCore; + } + + @Override + public void captureKeyPressed(KeyAction keyAction) { + // Log warning, this is not supported + } + + @Override + public void captureBottomPressed(ButtonAction keyAction) { + gameCore.processInput(convertTo(keyAction)); + } + + @Override + public void captureStickPressed(ButtonAction keyAction) { + gameCore.processInput(convertTo(keyAction)); + } + + private UserAction convertTo(ButtonAction keyAction) { + // Map to user action + return UserAction.GENERIC; + } +} diff --git a/src/main/java/game/domain/input/KeyAction.java b/src/main/java/game/domain/input/KeyAction.java new file mode 100644 index 0000000..6f00c3e --- /dev/null +++ b/src/main/java/game/domain/input/KeyAction.java @@ -0,0 +1,10 @@ +package game.domain.input; + +public enum KeyAction { + UP, + DOWN, + LEFT, + RIGHT, + Z, + X +} diff --git a/src/main/java/game/domain/input/KeyboardInput.java b/src/main/java/game/domain/input/KeyboardInput.java new file mode 100644 index 0000000..7bb87eb --- /dev/null +++ b/src/main/java/game/domain/input/KeyboardInput.java @@ -0,0 +1,32 @@ +package game.domain.input; + +import game.domain.core.GameCore; + +public class KeyboardInput implements PlayerInput { + + public final GameCore gameCore; + + public KeyboardInput(GameCore gameCore) { + this.gameCore = gameCore; + } + + @Override + public void captureKeyPressed(KeyAction keyAction) { + gameCore.processInput(convertTo(keyAction)); + } + + @Override + public void captureBottomPressed(ButtonAction keyAction) { + // Log warning, this is not supported + } + + @Override + public void captureStickPressed(ButtonAction keyAction) { + // Log warning, this is not supported + } + + private UserAction convertTo(KeyAction keyAction) { + // Map to user action + return UserAction.GENERIC; + } +} diff --git a/src/main/java/game/domain/input/PlayerInput.java b/src/main/java/game/domain/input/PlayerInput.java new file mode 100644 index 0000000..3299931 --- /dev/null +++ b/src/main/java/game/domain/input/PlayerInput.java @@ -0,0 +1,7 @@ +package game.domain.input; + +public interface PlayerInput { + void captureKeyPressed(KeyAction keyAction); + void captureBottomPressed(ButtonAction keyAction); + void captureStickPressed(ButtonAction keyAction); +} diff --git a/src/main/java/game/domain/input/StickAction.java b/src/main/java/game/domain/input/StickAction.java new file mode 100644 index 0000000..e86c310 --- /dev/null +++ b/src/main/java/game/domain/input/StickAction.java @@ -0,0 +1,8 @@ +package game.domain.input; + +public enum StickAction { + UP, + DOWN, + LEFT, + RIGHT, +} diff --git a/src/main/java/game/domain/input/UserAction.java b/src/main/java/game/domain/input/UserAction.java new file mode 100644 index 0000000..656995f --- /dev/null +++ b/src/main/java/game/domain/input/UserAction.java @@ -0,0 +1,11 @@ +package game.domain.input; + +public enum UserAction { + DIRECTION_UP, + DIRECTION_DOWN, + DIRECTION_LEFT, + DIRECTION_RIGHT, + PUNCH_PRESSED, + JUMP_PRESSED, + GENERIC +} diff --git a/src/main/java/game/domain/music/SpotifyPlugin.java b/src/main/java/game/domain/music/SpotifyPlugin.java new file mode 100644 index 0000000..b286f17 --- /dev/null +++ b/src/main/java/game/domain/music/SpotifyPlugin.java @@ -0,0 +1,7 @@ +package game.domain.music; + +public class SpotifyPlugin { + public void playMusic() { + // Do some management of the plugin and play music + } +} diff --git a/src/main/java/game/domain/player/Player.java b/src/main/java/game/domain/player/Player.java new file mode 100644 index 0000000..4532fbe --- /dev/null +++ b/src/main/java/game/domain/player/Player.java @@ -0,0 +1,25 @@ +package game.domain.player; + +import game.domain.core.DynamoDB; + +import java.util.Map; +import java.util.Set; + +public class Player { + + private static final DynamoDB DYNAMO_DB = new DynamoDB(); + + public void createPlayer(String name, Map attributes) { + // Do some parsing work + DYNAMO_DB.saveOrUpdate(new PlayerRecord()); + } + + public Process getProcess(long userId) { + return calculateProcess(DYNAMO_DB.getUserInfo(userId)); + } + + private Process calculateProcess(Set playerInfo) { + // Do some expensive computations in order to calculate process + return new Process("level_1", 10, 30, 3); + } +} \ No newline at end of file diff --git a/src/main/java/game/domain/player/PlayerInfo.java b/src/main/java/game/domain/player/PlayerInfo.java new file mode 100644 index 0000000..b702071 --- /dev/null +++ b/src/main/java/game/domain/player/PlayerInfo.java @@ -0,0 +1,19 @@ +package game.domain.player; + +public class PlayerInfo { + public String key; + public String value; + + public PlayerInfo(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } +} diff --git a/src/main/java/game/domain/player/PlayerRecord.java b/src/main/java/game/domain/player/PlayerRecord.java new file mode 100644 index 0000000..78de3c7 --- /dev/null +++ b/src/main/java/game/domain/player/PlayerRecord.java @@ -0,0 +1,4 @@ +package game.domain.player; + +public class PlayerRecord { +} diff --git a/src/main/java/game/domain/player/Process.java b/src/main/java/game/domain/player/Process.java new file mode 100644 index 0000000..4911f86 --- /dev/null +++ b/src/main/java/game/domain/player/Process.java @@ -0,0 +1,49 @@ +package game.domain.player; + +public class Process { + private String stage; + private int level; + private int currentPunchPower; + private int powerLevelMultiplier; + + // A lot of process indicators + + public Process(String stage, int level, int currentPunchPower, int powerLevelMultiplier) { + this.stage = stage; + this.level = level; + this.currentPunchPower = currentPunchPower; + this.powerLevelMultiplier = powerLevelMultiplier; + } + + public String getStage() { + return stage; + } + + public void setStage(String stage) { + this.stage = stage; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getCurrentPunchPower() { + return currentPunchPower; + } + + public void setCurrentPunchPower(int currentPunchPower) { + this.currentPunchPower = currentPunchPower; + } + + public int getPowerLevelMultiplier() { + return powerLevelMultiplier; + } + + public void setPowerLevelMultiplier(int powerLevelMultiplier) { + this.powerLevelMultiplier = powerLevelMultiplier; + } +}