Browse Source

add fields to game

feat-serverGameRepresentation
Steffen Nitschke 4 years ago
parent
commit
168d65862a
  1. 21
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameService.java
  2. 1
      fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameServiceTest.java

21
fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameService.java

@ -3,6 +3,9 @@ package de.fd.fh.server.game;
import de.fd.fh.server.user.UserId;
import lombok.RequiredArgsConstructor;
import java.util.HashSet;
import java.util.Set;
@RequiredArgsConstructor
public class GameService
{
@ -15,7 +18,23 @@ public class GameService
public GameId createGame(final UserId blackUser, final UserId whiteUser)
{
final Game game = new Game(null, null, null, null, null, null);
final Set<Field> fields = initFields(blackUser, whiteUser);
final Game game = new Game(null, whiteUser, blackUser, whiteUser, fields, null);
return (GameId) repository.save(game).getId();
}
private Set<Field> initFields(UserId blackUser, UserId whiteUser)
{
final Set<Field> fields = new HashSet<>();
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
fields.add(new Field(x, y, null , null));
}
}
return fields;
}
}

1
fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameServiceTest.java

@ -49,7 +49,6 @@ class GameServiceTest
final Game savedGame = captor.getValue();
assertNotNull(savedGame.getId());
assertEquals("12345", savedGame.getBlackPlayer().getIdentifier());
assertEquals("98765", savedGame.getWhitePlayer().getIdentifier());
assertEquals("98765", savedGame.getCurrentPlayer().getIdentifier());

Loading…
Cancel
Save