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/Stock.java b/be/src/main/java/codesquad/gaemimarble/game/entity/Stock.java index eb65e56..d54cf8d 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/entity/Stock.java +++ b/be/src/main/java/codesquad/gaemimarble/game/entity/Stock.java @@ -41,6 +41,11 @@ public static List 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..53485cc 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java +++ b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java @@ -110,21 +110,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,7 +301,10 @@ 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(); + } } if (currentPlayerInfo.getOrder() != gameStatus.getPlayers().size()) {