-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2단계 - 사다리 게임 실행] 테오(최우성) 미션 제출합니다. #194
Merged
Merged
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
23bd55e
feat: 리스트 미션 및 테스트코드 구현
woosung1223 b2ee1c0
docs: 기능 목록 추가
woosung1223 d202412
feat: 사다리 게임 실행 결과 입력 기능 생성
woosung1223 1ad9b1d
feat: 결과를 보고 싶은 사람을 입력하는 기능 생성
woosung1223 f99315f
feat: 사다리의 한 곳이 어디로 이어지는지 반환하는 기능 생성
woosung1223 c39ea9f
chore: 메서드명을 이해하기 쉽도록 변경
woosung1223 dd4edb2
feat: 플레이어 별 사다리 게임 결과를 생성하는 기능 구현
woosung1223 6947697
feat: 게임 결과를 반환하는 기능 생성
woosung1223 0c6d138
feat: 사다리 게임 흐름 제어 기능 생성
woosung1223 03463f7
fix: testInstance를 클래스 단위로 변경
woosung1223 ecdf925
refactor: 예외 발생 테스트의 경우 assertThatThrownBy 사용
woosung1223 e76f02f
refactor: exception 패키지를 도메인 패키지 하위로 이동
woosung1223 a3cea2e
refactor: View단에서 예외 메세지를 생성하도록 변경
woosung1223 0b18961
chore: 메소드 및 프로퍼티 네이밍을 이해하기 쉽도록 변경
woosung1223 6999cc1
docs: 기능 목록 및 고민사항 작성
woosung1223 c9b7894
chore: 클래스명 변경에 따른 메소드 및 프로퍼티명 변경
woosung1223 effa549
chore: 메소드 네이밍이 단일 책임을 가지도록 수정
woosung1223 fcac921
refactor: 예외 발생 시 사용자에게 보여질 행위를 담당하는 객체 생성
woosung1223 b7f40b9
refactor: 모든 예외를 RuntimeException으로 Catch하도록 변경
woosung1223 e7e85b5
refactor: 의존관계를 명확히 하기 위해 View 비static화
woosung1223 6ce9d4d
fix: Runtime 예외도 catch 하도록 수정
woosung1223 ba83dc4
refactor: 원시값이 의미를 가지도록 상수화
woosung1223 579279d
refactor: 메소드 분리 및 PREFIX 삽입 자동화
woosung1223 0ca2daa
docs: 고민사항 추가 기재
woosung1223 55774b5
refactor: 메소드 네이밍 수정
woosung1223 9ff6259
refactor: 변수명을 이해하기 쉽도록 변경
woosung1223 8acc87f
refactor: 플레이어 객체와 플레이어 이름 객체 통합
woosung1223 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ladder.domain.exception; | ||
|
||
public class CustomException extends RuntimeException { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/ladder/domain/exception/LadderLengthException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ladder.domain.exception; | ||
|
||
public class LadderLengthException extends CustomException { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/ladder/domain/exception/NoSuchPlayerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ladder.domain.exception; | ||
|
||
public class NoSuchPlayerException extends CustomException { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/ladder/domain/exception/NotIntegerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ladder.domain.exception; | ||
|
||
public class NotIntegerException extends CustomException { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/ladder/domain/exception/PlayerNameLengthException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ladder.domain.exception; | ||
|
||
public class PlayerNameLengthException extends CustomException { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/ladder/domain/exception/PlayerNumberException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ladder.domain.exception; | ||
|
||
public class PlayerNumberException extends CustomException { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ladder.domain.game; | ||
|
||
import ladder.domain.ladder.Ladder; | ||
import ladder.domain.player.Player; | ||
import ladder.domain.player.Players; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class LadderGame { | ||
|
||
private final Players players; | ||
private final Ladder ladder; | ||
private final List<String> destinations; | ||
|
||
public LadderGame(Players players, Ladder ladder, List<String> destinations) { | ||
this.players = players; | ||
this.ladder = ladder; | ||
this.destinations = List.copyOf(destinations); | ||
} | ||
|
||
public void letPlayersToGoDown() { | ||
List<String> gameRecord = new ArrayList<>(); | ||
int location = 0; | ||
|
||
for (int i = 0; i < players.size(); i++) { | ||
int finalDestination = ladder.getDestinationOf(location++); | ||
String gameResultForOneLocation = destinations.get(finalDestination); | ||
gameRecord.add(gameResultForOneLocation); | ||
} | ||
players.recordGameResult(gameRecord); | ||
} | ||
|
||
public Map<Player, String> getAllLadderGameResult() { | ||
return players.getAllGameRecords(); | ||
} | ||
|
||
public Map.Entry<Player, String> getOneLadderGameResult(String playerName) { | ||
return players.getGameRecordFor(playerName); | ||
} | ||
|
||
public Players getPlayers() { | ||
return players; | ||
} | ||
|
||
public Ladder getLadder() { | ||
return ladder; | ||
} | ||
|
||
public List<String> getDestinations() { | ||
return List.copyOf(destinations); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,64 @@ | ||
package ladder.domain.ladder; | ||
|
||
import ladder.domain.rule.BlockGenerator; | ||
import ladder.domain.rule.StoolGenerator; | ||
|
||
import java.util.List; | ||
import java.util.Stack; | ||
|
||
public class Line { | ||
|
||
private final BlockGenerator blockGenerator; | ||
private final List<Block> blocks; | ||
private final StoolGenerator stoolGenerator; | ||
private final List<Stool> stools; | ||
|
||
public Line(final int playerNumber, final BlockGenerator blockGenerator) { | ||
this.blockGenerator = blockGenerator; | ||
this.blocks = makeBlocks(playerNumber - 1); | ||
public Line(final int playerNumber, final StoolGenerator stoolGenerator) { | ||
this.stoolGenerator = stoolGenerator; | ||
this.stools = makeBlocks(playerNumber - 1); | ||
} | ||
|
||
private List<Block> makeBlocks(final int blockCount) { | ||
Stack<Block> temporaryBlocks = new Stack<>(); | ||
temporaryBlocks.push(blockGenerator.generate()); | ||
while (temporaryBlocks.size() != blockCount) { | ||
Block block = generateBlock(temporaryBlocks.peek()); | ||
temporaryBlocks.push(block); | ||
private List<Stool> makeBlocks(final int blockCount) { | ||
Stack<Stool> temporaryStools = new Stack<>(); | ||
temporaryStools.push(stoolGenerator.generate()); | ||
while (temporaryStools.size() != blockCount) { | ||
Stool stool = generateBlock(temporaryStools.peek()); | ||
temporaryStools.push(stool); | ||
} | ||
return List.copyOf(temporaryBlocks); | ||
return List.copyOf(temporaryStools); | ||
} | ||
|
||
private Block generateBlock(final Block previousBlock) { | ||
if (previousBlock.isExistBlock()) { | ||
return Block.EMPTY; | ||
private Stool generateBlock(final Stool previousStool) { | ||
if (previousStool.isExistBlock()) { | ||
return Stool.EMPTY; | ||
} | ||
return blockGenerator.generate(); | ||
return stoolGenerator.generate(); | ||
} | ||
|
||
public List<Block> getBlocks() { | ||
return List.copyOf(blocks); | ||
public int goDownAndGetLocation(final int currentLocation) { | ||
int newLocation = currentLocation; | ||
if (hasWayToGo(currentLocation)) { | ||
newLocation = getUpdatedLocation(currentLocation); | ||
} | ||
return newLocation; | ||
} | ||
|
||
private boolean hasWayToGo(final int location) { | ||
return isStoolExistAt(location - 1) || isStoolExistAt(location); | ||
} | ||
|
||
private boolean isStoolExistAt(final int location) { | ||
if (location < 0 || location >= stools.size()) { | ||
return false; | ||
} | ||
return stools.get(location) == Stool.EXIST; | ||
} | ||
|
||
private int getUpdatedLocation(final int location) { | ||
if (isStoolExistAt(location)) { | ||
return location + 1; | ||
} | ||
return location - 1; | ||
} | ||
|
||
public List<Stool> getStools() { | ||
return List.copyOf(stools); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...main/java/ladder/domain/ladder/Block.java → ...main/java/ladder/domain/ladder/Stool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package ladder.domain.ladder; | ||
|
||
public enum Block { | ||
public enum Stool { | ||
|
||
EMPTY, | ||
EXIST; | ||
|
||
public boolean isExistBlock() { | ||
return this == Block.EXIST; | ||
return this == Stool.EXIST; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수 이름에서 2개의 역할을 하도록 네이밍이 되어있는데, 하나의 역할을 하도록 만드는 것이 좋지 않을까요~?