Skip to content

Commit

Permalink
Merge pull request #70 from codesquad-members-2023/fix/#69-bug-feat
Browse files Browse the repository at this point in the history
[BE] 버그 및 기능 수정
  • Loading branch information
yhpark95 authored Nov 6, 2023
2 parents 72d4616 + d39febb commit f8b8e9d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> players;
Expand All @@ -26,8 +28,9 @@ private GameStatus(Boolean isStarted, List<Player> players, List<Stock> stocks,
}

public void setOrder(Integer firstOrder) {
for (int i=0; i<players.size(); i++) {
players.get(i).setOrder(((firstOrder + i - 1) % players.size()) + 1);
for (int i = 0; i < players.size(); i++) {
players.get(i).setOrder(((i + players.size() - firstOrder + 1) % players.size()) + 1);
log.info("설정된 오더 (아이디 + 오더)" + players.get(i).getPlayerId() + "/" + players.get(i).getOrder());
}
}

Expand Down
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 @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f8b8e9d

Please sign in to comment.