Skip to content

Commit

Permalink
Merge branch 'fix/#69-bug-feat' of https://github.com/codesquad-membe…
Browse files Browse the repository at this point in the history
…rs-2023/gaemi-marble-team-04 into be

# Conflicts:
#	be/src/main/java/codesquad/gaemimarble/game/service/GameService.java
  • Loading branch information
HyowonSin committed Nov 2, 2023
2 parents 72d4616 + f7becd4 commit 4a99694
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 5 additions & 0 deletions be/src/main/java/codesquad/gaemimarble/game/entity/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static List<Stock> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 4a99694

Please sign in to comment.