|
@ -3,6 +3,9 @@ package de.fd.fh.server.game; |
|
|
import de.fd.fh.server.user.UserId; |
|
|
import de.fd.fh.server.user.UserId; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
|
public class GameService |
|
|
public class GameService |
|
|
{ |
|
|
{ |
|
@ -15,7 +18,23 @@ public class GameService |
|
|
|
|
|
|
|
|
public GameId createGame(final UserId blackUser, final UserId whiteUser) |
|
|
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(); |
|
|
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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |