From 76b426bdb9cc629412ddaa44c5e4095732398a5a Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:44:03 +0900 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=EC=88=9C=EA=B0=84=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=20=EC=9D=91=EB=8B=B5=20=EC=B6=94=EA=B0=80=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/controller/GameController.java | 3 +++ .../game/dto/response/GameTeleportResponse.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 be/src/main/java/codesquad/gaemimarble/game/dto/response/GameTeleportResponse.java 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..53e5e2f 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/controller/GameController.java +++ b/be/src/main/java/codesquad/gaemimarble/game/controller/GameController.java @@ -30,6 +30,7 @@ import codesquad.gaemimarble.game.dto.response.GameCellResponse; 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; @@ -167,6 +168,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/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; + } +} From cbf23a81dc6c418bc104e1b53bbc0b04f37be2c1 Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:56:08 +0900 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20=EC=A3=BC=EC=82=AC=EC=9C=84=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=206=EC=9D=84=20=EA=B3=A0=EC=A0=95=20X=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codesquad/gaemimarble/game/service/GameService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 e0b4ca9..25ff45c 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java +++ b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java @@ -110,10 +110,8 @@ 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 = 4; - int dice2 = 2; + int dice1 = (int)(Math.random() * 6) + 1; + int dice2 = (int)(Math.random() * 6) + 1; if (dice1 == dice2) { int countDouble = gameStatus.getCurrentPlayerInfo().increaseCountDouble(); From 7514f0b233d7dd6fa26e138928bbe45f17fec8e3 Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:06:43 +0900 Subject: [PATCH 03/10] =?UTF-8?q?fix:=20=EC=A3=BC=EC=8B=9D=EA=B0=80?= =?UTF-8?q?=EA=B2=A9=200=EC=9C=BC=EB=A1=9C=20=EB=A6=AC=EB=AF=B8=ED=8A=B8,?= =?UTF-8?q?=20=EA=B0=90=EC=98=A5=20=EC=88=9C=EA=B0=84=EC=9D=B4=EB=8F=99=20?= =?UTF-8?q?=EB=8F=84=EC=B0=A9=EC=8B=9C=20=EB=8B=A4=EC=9D=8C=20=ED=94=8C?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=96=B4=20=EC=B0=A8=EB=A1=80=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EB=90=98=EA=B2=8C=20=EC=88=98=EC=A0=95=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/codesquad/gaemimarble/game/entity/Stock.java | 5 +++++ .../java/codesquad/gaemimarble/game/service/GameService.java | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 25ff45c..2763e93 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java +++ b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java @@ -301,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()) { From f7becd4ee545691c92231e25bac95c81a307474a Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:29:22 +0900 Subject: [PATCH 04/10] =?UTF-8?q?fix:=20=EC=84=B8=EB=B2=88=20=EB=8D=94?= =?UTF-8?q?=EB=B8=94=20=EC=8B=9C=20=EA=B0=90=EC=98=A5=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=9C=EA=B0=84=EC=9D=B4=EB=8F=99=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gaemimarble/game/controller/GameController.java | 9 ++++++++- .../gaemimarble/game/dto/response/GameDiceResult.java | 6 +++--- .../codesquad/gaemimarble/game/service/GameService.java | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) 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 53e5e2f..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,6 +28,7 @@ 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; @@ -153,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()); } 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/service/GameService.java b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java index 2763e93..53485cc 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java +++ b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java @@ -118,11 +118,11 @@ public GameDiceResult rollDice(Long gameId, String playerId) { 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) { From 055e6f68361c99c419e8a9c4eb6b2ecbe0fd1c33 Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:40:06 +0900 Subject: [PATCH 05/10] =?UTF-8?q?fix:=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=9D=84=20=EC=9C=84=ED=95=B4=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/codesquad/gaemimarble/game/entity/GameStatus.java | 5 ++++- .../java/codesquad/gaemimarble/game/service/GameService.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) 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..78d9e97 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 Date: Fri, 3 Nov 2023 12:00:28 +0900 Subject: [PATCH 06/10] =?UTF-8?q?fix:=20=ED=94=8C=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=20=EC=88=9C=EC=84=9C=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/codesquad/gaemimarble/game/entity/GameStatus.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 78d9e97..1e4907b 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java +++ b/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java @@ -29,7 +29,11 @@ private GameStatus(Boolean isStarted, List players, List stocks, public void setOrder(Integer firstOrder) { for (int i = 0; i < players.size(); i++) { - players.get(i).setOrder(((firstOrder + i - 1) % players.size()) + 1); + if (firstOrder + i != players.size()) { + players.get(i).setOrder(((firstOrder + i) % players.size())); + } else { + players.get(i).setOrder(players.size()); + } log.info("설정된 오더 (아이디 + 오더)" + players.get(i).getPlayerId() + "/" + players.get(i).getOrder()); } } From f21320a16a28c52aa435b92f864d65afdaade610 Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:06:47 +0900 Subject: [PATCH 07/10] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=20=EA=B8=B0?= =?UTF-8?q?=EC=9E=85=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/codesquad/gaemimarble/game/service/GameService.java | 1 + 1 file changed, 1 insertion(+) 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 c74c5cb..016239e 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java +++ b/be/src/main/java/codesquad/gaemimarble/game/service/GameService.java @@ -88,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(); From ea2f2eec3499ec375ce5144a1d9691b06b6e7b30 Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:29:55 +0900 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20=ED=94=8C=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=20=EC=88=9C=EC=84=9C=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=202=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/codesquad/gaemimarble/game/entity/GameStatus.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 1e4907b..b87d0d2 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java +++ b/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java @@ -28,14 +28,15 @@ private GameStatus(Boolean isStarted, List players, List stocks, } public void setOrder(Integer firstOrder) { + firstOrder--; for (int i = 0; i < players.size(); i++) { - if (firstOrder + i != players.size()) { - players.get(i).setOrder(((firstOrder + i) % players.size())); - } else { + players.get(0).setOrder((firstOrder + players.size() + 1 + i) % players.size()); + if (players.get(i).getOrder() == 0) { players.get(i).setOrder(players.size()); } log.info("설정된 오더 (아이디 + 오더)" + players.get(i).getPlayerId() + "/" + players.get(i).getOrder()); } + } public void initCurrentPlayerInfo(Player player) { From 04307ea6cd2ea86c85a145a2ed8f803896d1dc27 Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:39:21 +0900 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20=ED=94=8C=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=20=EC=88=9C=EC=84=9C=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=203=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gaemimarble/game/entity/GameStatus.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 b87d0d2..3b88596 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java +++ b/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java @@ -28,16 +28,16 @@ private GameStatus(Boolean isStarted, List players, List stocks, } public void setOrder(Integer firstOrder) { - firstOrder--; for (int i = 0; i < players.size(); i++) { - players.get(0).setOrder((firstOrder + players.size() + 1 + i) % players.size()); - if (players.get(i).getOrder() == 0) { - players.get(i).setOrder(players.size()); - } + players.get(i).setOrder(((i + players.size() - firstOrder + 1) % players.size()) + 1); log.info("설정된 오더 (아이디 + 오더)" + players.get(i).getPlayerId() + "/" + players.get(i).getOrder()); } - } + // players.get(firstOrder-1).setOrder(1); + // for (int i = firstOrder; i < players.size() + firstOrder; i++) { + // players.get(i).setOrder(players.get(i-1).getOrder() + 1); + // log.info("설정된 오더 (아이디 + 오더)" + players.get(i).getPlayerId() + "/" + players.get(i).getOrder()); + // } public void initCurrentPlayerInfo(Player player) { this.currentPlayerInfo = CurrentPlayerInfo.builder() From d39febb79cb172109fd096851a76e3ff4a18ddd4 Mon Sep 17 00:00:00 2001 From: yhpark95 <98851575+yhpark95@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:04:11 +0900 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C=20#69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/codesquad/gaemimarble/game/entity/GameStatus.java | 5 ----- 1 file changed, 5 deletions(-) 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 3b88596..3851260 100644 --- a/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java +++ b/be/src/main/java/codesquad/gaemimarble/game/entity/GameStatus.java @@ -33,11 +33,6 @@ public void setOrder(Integer firstOrder) { log.info("설정된 오더 (아이디 + 오더)" + players.get(i).getPlayerId() + "/" + players.get(i).getOrder()); } } - // players.get(firstOrder-1).setOrder(1); - // for (int i = firstOrder; i < players.size() + firstOrder; i++) { - // players.get(i).setOrder(players.get(i-1).getOrder() + 1); - // log.info("설정된 오더 (아이디 + 오더)" + players.get(i).getPlayerId() + "/" + players.get(i).getOrder()); - // } public void initCurrentPlayerInfo(Player player) { this.currentPlayerInfo = CurrentPlayerInfo.builder()