diff --git a/be/src/main/java/codesquad/gaemimarble/game/controller/GameController.java b/be/src/main/java/codesquad/gaemimarble/game/controller/GameController.java index fa92bc7..eb6a430 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/controller/GameController.java +++ b/be/src/main/java/codesquad/gaemimarble/game/controller/GameController.java @@ -28,8 +28,10 @@ import codesquad.gaemimarble.game.dto.request.GameTeleportRequest; import codesquad.gaemimarble.game.dto.response.GameAccessibleResponse; import codesquad.gaemimarble.game.dto.response.GameCellResponse; +import codesquad.gaemimarble.game.dto.response.GameDiceResult; import codesquad.gaemimarble.game.dto.response.GameEventNameResponse; import codesquad.gaemimarble.game.dto.response.GameRoomCreateResponse; +import codesquad.gaemimarble.game.dto.response.GameTeleportResponse; import codesquad.gaemimarble.game.dto.response.userStatusBoard.GameUserBoardResponse; import codesquad.gaemimarble.game.entity.Player; import codesquad.gaemimarble.game.entity.TypeConstants; @@ -152,8 +154,14 @@ private void sendFirstPlayer(GameStartRequest gameStartRequest) { } private void sendDiceResult(GameRollDiceRequest gameRollDiceRequest) { + GameDiceResult gameDiceResult = gameService.rollDice(gameRollDiceRequest.getGameId(), + gameRollDiceRequest.getPlayerId()); socketDataSender.send(gameRollDiceRequest.getGameId(), new ResponseDTO<>(TypeConstants.DICE, - gameService.rollDice(gameRollDiceRequest.getGameId(), gameRollDiceRequest.getPlayerId()))); + gameDiceResult)); + if (gameDiceResult.getTripleDouble()) { + socketDataSender.send(gameRollDiceRequest.getGameId(), new ResponseDTO<>(TypeConstants.TELEPORT, + GameTeleportResponse.builder().location(6).build())); + } sendCellArrival(gameRollDiceRequest.getGameId(), gameRollDiceRequest.getPlayerId()); } @@ -167,6 +175,8 @@ private void sendCellArrival(Long gameId, String playerId) { private void sendTeleport(GameTeleportRequest gameTeleportRequest) { gameService.teleport(gameTeleportRequest); sendCellArrival(gameTeleportRequest.getGameId(), gameTeleportRequest.getPlayerId()); + socketDataSender.send(gameTeleportRequest.getGameId(), new ResponseDTO<>(TypeConstants.TELEPORT, + GameTeleportResponse.builder().location(gameTeleportRequest.getLocation()).build())); } private void sendRandomEvents(GameEventRequest gameEventRequest) { diff --git a/be/src/main/java/codesquad/gaemimarble/game/dto/response/GameDiceResult.java b/be/src/main/java/codesquad/gaemimarble/game/dto/response/GameDiceResult.java index a8c8a94..c17f727 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/dto/response/GameDiceResult.java +++ b/be/src/main/java/codesquad/gaemimarble/game/dto/response/GameDiceResult.java @@ -7,13 +7,13 @@ @Getter @NoArgsConstructor public class GameDiceResult { - private Integer startLocation; + private Boolean tripleDouble; private Integer dice1; private Integer dice2; @Builder - public GameDiceResult(Integer startLocation, Integer dice1, Integer dice2) { - this.startLocation = startLocation; + public GameDiceResult(Boolean tripleDouble, Integer dice1, Integer dice2) { + this.tripleDouble = tripleDouble; this.dice1 = dice1; this.dice2 = dice2; } diff --git a/be/src/main/java/codesquad/gaemimarble/game/dto/response/GameTeleportResponse.java b/be/src/main/java/codesquad/gaemimarble/game/dto/response/GameTeleportResponse.java new file mode 100644 index 0000000..2943999 --- /dev/null +++ b/be/src/main/java/codesquad/gaemimarble/game/dto/response/GameTeleportResponse.java @@ -0,0 +1,14 @@ +package codesquad.gaemimarble.game.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class GameTeleportResponse { + private final Integer location; + + @Builder + private GameTeleportResponse(Integer location) { + this.location = location; + } +} diff --git a/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java b/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java index 663848b..3851260 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java +++ b/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java @@ -4,8 +4,10 @@ import lombok.Builder; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; @Getter +@Slf4j public class GameStatus { private final Boolean isStarted; private final List players; @@ -26,8 +28,9 @@ private GameStatus(Boolean isStarted, List players, List stocks, } public void setOrder(Integer firstOrder) { - for (int i=0; i initStocks() { } public void changePrice(Integer percentage) { + Integer changingPrice = this.currentPrice + ((this.startPrice * percentage) / 100); + if (changingPrice <= 0) { + currentPrice = 0; + return; + } this.currentPrice += ((this.startPrice * percentage) / 100); } diff --git a/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java index cb1f497..016239e 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java +++ b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java @@ -44,9 +44,11 @@ import codesquad.gaemimarble.game.entity.Theme; import codesquad.gaemimarble.game.repository.GameRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; @Service @RequiredArgsConstructor +@Slf4j public class GameService { private final GameRepository gameRepository; @@ -86,6 +88,7 @@ public String getFirstPlayer(Long gameId) { int randomIndex = (int)(Math.random() * players.size()) + 1; Player player = players.get(randomIndex - 1); + log.info("first order" + player.getOrder()); gameStatus.setOrder(player.getOrder()); gameStatus.initCurrentPlayerInfo(player); return player.getPlayerId(); @@ -110,21 +113,19 @@ public GameDiceResult rollDice(Long gameId, String playerId) { Player player = gameStatus.getPlayer(playerId); int startLocation = player.getLocation(); - // int dice1 = (int)(Math.random() * 6) + 1; - // int dice2 = (int)(Math.random() * 6) + 1; - int dice1 = 6; - int dice2 = 3; + int dice1 = (int)(Math.random() * 6) + 1; + int dice2 = (int)(Math.random() * 6) + 1; if (dice1 == dice2) { int countDouble = gameStatus.getCurrentPlayerInfo().increaseCountDouble(); if (countDouble == 3) { player.goToPrison(); - return new GameDiceResult(startLocation, dice1, dice2); + return new GameDiceResult(true, dice1, dice2); } } player.move(dice1 + dice2); - return new GameDiceResult(startLocation, dice1, dice2); + return new GameDiceResult(false, dice1, dice2); } public GameCellResponse arriveAtCell(Long gameId, String playerId) { @@ -303,9 +304,12 @@ public GameEndTurnResponse endTurn(GameEndTurnRequest gameEndTurnRequest) { if (currentPlayerInfo.getRolledDouble()) { currentPlayerInfo.initRolledDouble(); - return GameEndTurnResponse.builder().nextPlayerId(currentPlayerInfo.getPlayerId()).build(); + Integer location = gameStatus.getPlayer(currentPlayerInfo.getPlayerId()).getLocation(); + if (!(location == 18 || location == 6)) { + return GameEndTurnResponse.builder().nextPlayerId(currentPlayerInfo.getPlayerId()).build(); + } } - + log.info("order: " + currentPlayerInfo.getOrder() + "game player size" + gameStatus.getPlayers().size()); if (currentPlayerInfo.getOrder() != gameStatus.getPlayers().size()) { for (Player player : gameStatus.getPlayers()) { if (player.getOrder() == currentPlayerInfo.getOrder() + 1) {