Browse Source

init game representation

feat-serverGameRepresentation
Steffen Nitschke 4 years ago
parent
commit
b06bce9bd9
  1. 25
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Field.java
  2. 20
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Figure.java
  3. 29
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/Game.java
  4. 27
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameId.java
  5. 2
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/User.java

25
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
}
}

20
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
}
}

29
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<Field> fields;
@Embedded
private UserId winner;
}

27
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());
}
}

2
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;

Loading…
Cancel
Save