From b06bce9bd9aa24b07bd74cf9a1eb2a8b16d99873 Mon Sep 17 00:00:00 2001 From: Steffen Nitschke Date: Mon, 1 Feb 2021 14:35:47 +0100 Subject: [PATCH] init game representation --- .../main/java/de/fd/fh/server/game/Field.java | 25 ++++++++++++++++ .../java/de/fd/fh/server/game/Figure.java | 20 +++++++++++++ .../main/java/de/fd/fh/server/game/Game.java | 29 +++++++++++++++++++ .../java/de/fd/fh/server/game/GameId.java | 27 +++++++++++++++++ .../main/java/de/fd/fh/server/user/User.java | 2 ++ 5 files changed, 103 insertions(+) create mode 100644 fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Field.java create mode 100644 fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Figure.java create mode 100644 fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Game.java create mode 100644 fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameId.java diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Field.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Field.java new file mode 100644 index 0000000..ee8ec3c --- /dev/null +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Field.java @@ -0,0 +1,25 @@ +package de.fd.fh.server.game; + +import dev.morphia.annotations.Embedded; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class Field +{ + private int x; + + private int y; + + private Color color; + @Embedded + private Figure figure; + + private enum Color + { + WHITE, BLACK + } +} diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Figure.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Figure.java new file mode 100644 index 0000000..5b36193 --- /dev/null +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Figure.java @@ -0,0 +1,20 @@ +package de.fd.fh.server.game; + +import de.fd.fh.server.user.UserId; +import dev.morphia.annotations.Embedded; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public class Figure +{ + private final Type type; + @Embedded + private final UserId player; + + private enum Type + { + KING, QUEEN, BISHOP, KNIGHT, ROOK, PAWN + } +} diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Game.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Game.java new file mode 100644 index 0000000..e2f7ba3 --- /dev/null +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Game.java @@ -0,0 +1,29 @@ +package de.fd.fh.server.game; + +import de.fd.fh.server.user.UserId; +import dev.morphia.annotations.Embedded; +import dev.morphia.annotations.Id; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Set; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class Game +{ + @Id + private GameId id; + @Embedded + private UserId whitePlayer; + @Embedded + private UserId blackPlayer; + @Embedded + private UserId currentPlayer; + @Embedded + private Set fields; + @Embedded + private UserId winner; +} diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameId.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameId.java new file mode 100644 index 0000000..87b4b3a --- /dev/null +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameId.java @@ -0,0 +1,27 @@ +package de.fd.fh.server.game; + +import dev.morphia.annotations.Embedded; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import org.bson.types.ObjectId; + +@Getter +@Embedded +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@EqualsAndHashCode(of = {"identifier"}) +public class GameId +{ + private String identifier; + + public static GameId of(final String identifier) + { + return new GameId(identifier); + } + + public static GameId random() + { + return new GameId(new ObjectId().toHexString()); + } +} diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/user/User.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/user/User.java index ef18257..e250496 100644 --- a/fh.fd.ci.server/src/main/java/de/fd/fh/server/user/User.java +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/user/User.java @@ -1,11 +1,13 @@ package de.fd.fh.server.user; +import dev.morphia.annotations.Id; import lombok.*; @AllArgsConstructor @Getter public class User { + @Id private final UserId id; private String name;