-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
72 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
server/src/main/java/org/schlunzis/kurtama/server/game/Game.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.schlunzis.kurtama.server.game; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.schlunzis.kurtama.server.game.model.SquareGameState; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class Game { | ||
|
||
private final UUID id; | ||
private final SquareGameState gameState; | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
server/src/main/java/org/schlunzis/kurtama/server/game/GameManagement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.schlunzis.kurtama.server.game; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.schlunzis.kurtama.common.game.GameSettings; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.UUID; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class GameManagement { | ||
|
||
private final GameStore gameStore; | ||
|
||
public Game createGame(GameSettings gameSettings) { | ||
return gameStore.create(gameSettings); | ||
} | ||
|
||
public void removeGame(Game game) { | ||
gameStore.remove(game.getId()); | ||
} | ||
|
||
public void removeGame(UUID id) { | ||
gameStore.remove(id); | ||
} | ||
|
||
public Game getGame(UUID id) { | ||
return gameStore.get(id).orElseThrow(); | ||
} | ||
|
||
} |
12 changes: 6 additions & 6 deletions
12
server/src/main/java/org/schlunzis/kurtama/server/game/GameService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
server/src/main/java/org/schlunzis/kurtama/server/game/GameStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.schlunzis.kurtama.server.game; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.schlunzis.kurtama.common.game.GameSettings; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class GameStore { | ||
|
||
private final Map<UUID, Game> gameMap = new ConcurrentHashMap<>(); | ||
private final IGameFactory gameFactory; | ||
|
||
public Game create(GameSettings gameSettings) { | ||
UUID uuid; | ||
do { | ||
uuid = UUID.randomUUID(); | ||
} while (gameMap.containsKey(uuid)); | ||
|
||
Game game = gameFactory.create(uuid, gameSettings); | ||
gameMap.put(uuid, game); | ||
return game; | ||
} | ||
|
||
public boolean remove(UUID uuid) { | ||
return gameMap.remove(uuid) != null; | ||
} | ||
|
||
public Optional<Game> get(UUID uuid) { | ||
return Optional.ofNullable(gameMap.get(uuid)); | ||
} | ||
|
||
public Collection<Game> getAll() { | ||
return gameMap.values(); | ||
} | ||
|
||
} |
66 changes: 0 additions & 66 deletions
66
server/src/main/java/org/schlunzis/kurtama/server/game/GenericSquareTerrainFactory.java
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
server/src/main/java/org/schlunzis/kurtama/server/game/IGameFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.schlunzis.kurtama.server.game; | ||
|
||
import org.schlunzis.kurtama.common.game.GameSettings; | ||
|
||
import java.util.UUID; | ||
|
||
public interface IGameFactory { | ||
Game create(UUID uuid, GameSettings gameSettings); | ||
} |
25 changes: 25 additions & 0 deletions
25
server/src/main/java/org/schlunzis/kurtama/server/game/SquareGameFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.schlunzis.kurtama.server.game; | ||
|
||
import org.schlunzis.kurtama.common.game.GameSettings; | ||
import org.schlunzis.kurtama.server.game.model.SquareGameState; | ||
import org.schlunzis.kurtama.server.game.model.SquareTerrain; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collections; | ||
import java.util.UUID; | ||
|
||
@Component | ||
public class SquareGameFactory implements IGameFactory { | ||
|
||
@Override | ||
public Game create(UUID id, GameSettings gameSettings) { | ||
SquareGameState gameState = createGameState(gameSettings); | ||
return new Game(id, gameState); | ||
} | ||
|
||
private SquareGameState createGameState(GameSettings gameSettings) { | ||
SquareTerrainFactory terrainFactory = new SquareTerrainFactory(gameSettings); | ||
return new SquareGameState((SquareTerrain) terrainFactory.create(), Collections.emptyList()); | ||
} | ||
|
||
} |