-
Notifications
You must be signed in to change notification settings - Fork 250
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
[1단계 - 사다리 생성] 허브(방대의) 미션 제출합니다. #97
Merged
Merged
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
244004a
docs: 요구사항 정리
greeng00se 187cab7
feat: 참가자 생성 기능 구현
greeng00se 3eb9db8
remove: 사용하지 않는 SuppressWarning 제거
greeng00se 2564118
feat: LineStatus 생성 구현
greeng00se bb8e17c
feat: Line 생성 구현
greeng00se 97fb1f8
feat: Ladder 생성 구현
greeng00se 8c620ed
feat: 입력 기능 구현
greeng00se aee791d
feat: 출력 기능 구현
greeng00se 7d48c69
refactor: 메소드 분리 및 호출 순서 변경
greeng00se 7c53ea0
feat: LadderGame 생성 구현
greeng00se 1b77fbc
docs: 요구사항 정리
greeng00se aac2877
feat: 랜덤 Boolean 값을 반환하는 기능 추가
greeng00se f97ccc8
refactor: 사람이름을 List<String>으로 받도록 타입 변경
greeng00se 343ab37
feat: 컨트롤러 구현
greeng00se d848e51
feat: 게임 실행 기능 구현
greeng00se c39048b
feat: Player에 대한 일급 컬렉션 구현
greeng00se 194c4d1
refactor: Players 적용
greeng00se e949722
refactor: LineStatus 상태 확인 메소드 추가
greeng00se f856fcb
test: Test용 BooleanGenerator 구현
greeng00se 570baeb
refactor: 가로라인 생성에 대한 책임 분리
greeng00se 45f4c01
remove: 사용하지 않는 equals & hashcode 제거
greeng00se dad109f
style: 공백 정리
greeng00se 9c202f0
refactor: final 선언 빠진부분 추가
greeng00se 13d946b
feat: 참가인원 반환 기능 추가
greeng00se b0ba707
feat: 에러 메시지 출력 기능 추가
greeng00se e5acabe
feat: 재입력 기능 추가
greeng00se 3ac7d2e
docs: 요구사항 정리
greeng00se e36141e
test: final 빠진 부분 추가
greeng00se 9c6732b
refactor: 상수 재사용 가능하도록 변경
greeng00se 0a8418c
refactor: 이해하기 어려운 조건 메서드로 분리
greeng00se 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
Empty file.
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,33 @@ | ||
package ladder; | ||
|
||
import java.util.Scanner; | ||
import ladder.controller.LadderGameController; | ||
import ladder.domain.RandomBooleanGenerator; | ||
import ladder.view.InputView; | ||
import ladder.view.OutputView; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
try (Scanner scanner = new Scanner(System.in)) { | ||
final LadderGameController ladderGameController = new LadderGameController( | ||
booleanGenerator(), | ||
inputView(scanner), | ||
outputView() | ||
); | ||
ladderGameController.run(); | ||
} | ||
} | ||
|
||
private static RandomBooleanGenerator booleanGenerator() { | ||
return new RandomBooleanGenerator(); | ||
} | ||
|
||
private static OutputView outputView() { | ||
return new OutputView(); | ||
} | ||
|
||
private static InputView inputView(final Scanner scanner) { | ||
return new InputView(scanner); | ||
} | ||
} |
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,60 @@ | ||
package ladder.controller; | ||
|
||
import java.util.List; | ||
import ladder.domain.BooleanGenerator; | ||
import ladder.domain.LadderGame; | ||
import ladder.domain.Line; | ||
import ladder.domain.Players; | ||
import ladder.view.InputView; | ||
import ladder.view.OutputView; | ||
|
||
public class LadderGameController { | ||
|
||
private final BooleanGenerator booleanGenerator; | ||
private final InputView inputView; | ||
private final OutputView outputView; | ||
|
||
public LadderGameController( | ||
final BooleanGenerator booleanGenerator, | ||
final InputView inputView, | ||
final OutputView outputView | ||
) { | ||
this.booleanGenerator = booleanGenerator; | ||
this.inputView = inputView; | ||
this.outputView = outputView; | ||
} | ||
|
||
public void run() { | ||
final LadderGame ladderGame = initialize(); | ||
final List<String> players = ladderGame.getPlayers(); | ||
final List<Line> ladder = ladderGame.getLadder(); | ||
|
||
outputView.printResult(players, ladder); | ||
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. View를 깔끔하게 잘 분리해주셨네요 👍🏻 |
||
} | ||
|
||
private LadderGame initialize() { | ||
final Players players = readPlayers(); | ||
final int height = readHeight(); | ||
|
||
return new LadderGame(booleanGenerator, players, height); | ||
} | ||
|
||
private Players readPlayers() { | ||
try { | ||
final List<String> names = inputView.readPlayerNames(); | ||
return new Players(names); | ||
} catch (IllegalArgumentException e) { | ||
outputView.printError(e.getMessage()); | ||
return readPlayers(); | ||
} | ||
} | ||
|
||
private int readHeight() { | ||
try { | ||
return inputView.readLadderHeight(); | ||
} catch (IllegalArgumentException e) { | ||
outputView.printError(e.getMessage()); | ||
return readHeight(); | ||
} | ||
} | ||
} |
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,5 @@ | ||
package ladder.domain; | ||
|
||
public interface BooleanGenerator { | ||
boolean generate(); | ||
} | ||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인터페이스 추출 👍🏻 |
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,26 @@ | ||
package ladder.domain; | ||
|
||
import static java.util.stream.Collectors.toUnmodifiableList; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
class Ladder { | ||
|
||
private final List<Line> lines; | ||
|
||
public Ladder(final BooleanGenerator booleanGenerator, final int height, final int width) { | ||
this.lines = generateLines(booleanGenerator, height, width); | ||
} | ||
|
||
private List<Line> generateLines(final BooleanGenerator booleanGenerator, final int height, final int width) { | ||
return Stream.generate(() -> new Line(booleanGenerator, width)) | ||
.limit(height) | ||
.collect(toUnmodifiableList()); | ||
} | ||
|
||
public List<Line> getLines() { | ||
return Collections.unmodifiableList(lines); | ||
} | ||
} |
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,24 @@ | ||
package ladder.domain; | ||
|
||
import java.util.List; | ||
|
||
public class LadderGame { | ||
|
||
private static final int SUBTRACT_VALUE_OF_LADDER_WIDTH = 1; | ||
|
||
private final Players players; | ||
private final Ladder ladder; | ||
|
||
public LadderGame(final BooleanGenerator booleanGenerator, final Players players, final int height) { | ||
this.players = players; | ||
this.ladder = new Ladder(booleanGenerator, height, players.count() - SUBTRACT_VALUE_OF_LADDER_WIDTH); | ||
} | ||
|
||
public List<String> getPlayers() { | ||
return players.getNames(); | ||
} | ||
|
||
public List<Line> getLadder() { | ||
return ladder.getLines(); | ||
} | ||
} |
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,36 @@ | ||
package ladder.domain; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Deque; | ||
import java.util.List; | ||
|
||
public class Line { | ||
|
||
private final List<LineStatus> statuses; | ||
|
||
public Line(final BooleanGenerator booleanGenerator, final int width) { | ||
this.statuses = generateLine(booleanGenerator, width); | ||
} | ||
|
||
private List<LineStatus> generateLine(final BooleanGenerator booleanGenerator, final int width) { | ||
final Deque<LineStatus> statuses = new ArrayDeque<>(); | ||
for (int i = 0; i < width; i++) { | ||
statuses.add(generateLineStatus(booleanGenerator, statuses)); | ||
} | ||
return new ArrayList<>(statuses); | ||
} | ||
|
||
private LineStatus generateLineStatus(final BooleanGenerator booleanGenerator, final Deque<LineStatus> statuses) { | ||
final boolean status = booleanGenerator.generate(); | ||
if (statuses.isEmpty() || statuses.getLast().isDisconnected()) { | ||
return LineStatus.from(status); | ||
} | ||
return LineStatus.DISCONNECTED; | ||
} | ||
|
||
public List<LineStatus> getLine() { | ||
return Collections.unmodifiableList(statuses); | ||
} | ||
} |
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,21 @@ | ||
package ladder.domain; | ||
|
||
public enum LineStatus { | ||
CONNECTED, | ||
DISCONNECTED; | ||
|
||
public static LineStatus from(final boolean status) { | ||
if (status) { | ||
return CONNECTED; | ||
} | ||
return DISCONNECTED; | ||
} | ||
|
||
public boolean isConnected() { | ||
return this == CONNECTED; | ||
} | ||
|
||
public boolean isDisconnected() { | ||
return this == DISCONNECTED; | ||
} | ||
} |
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,27 @@ | ||
package ladder.domain; | ||
|
||
public class Player { | ||
private static final String INVALID_NAME_LENGTH_MESSAGE = "이름은 1자 이상, 5자 이하여야 한다."; | ||
private static final int NAME_LENGTH_UPPER_BOUND = 5; | ||
|
||
private final String name; | ||
|
||
public Player(final String name) { | ||
validate(name); | ||
this.name = name; | ||
} | ||
|
||
private void validate(final String name) { | ||
if (isInvalidNameLength(name)) { | ||
throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); | ||
} | ||
} | ||
|
||
private boolean isInvalidNameLength(final String name) { | ||
return name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
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,53 @@ | ||
package ladder.domain; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class Players { | ||
private static final int PLAYERS_SIZE_LOWER_BOUND = 2; | ||
private static final String INVALID_PLAYERS_SIZE_MESSAGE = "참가자는 최소 두명이어야 합니다."; | ||
private static final String DUPLICATE_NAMES_MESSAGE = "참가자의 이름은 중복되지 않아야 합니다."; | ||
|
||
private final List<Player> players; | ||
|
||
public Players(final List<String> names) { | ||
validate(names); | ||
this.players = generatePlayers(names); | ||
} | ||
|
||
private void validate(final List<String> names) { | ||
validatePlayersSize(names); | ||
validateDuplicateNames(names); | ||
} | ||
|
||
private void validatePlayersSize(final List<String> names) { | ||
if (names.size() < PLAYERS_SIZE_LOWER_BOUND) { | ||
throw new IllegalArgumentException(INVALID_PLAYERS_SIZE_MESSAGE); | ||
} | ||
} | ||
|
||
private void validateDuplicateNames(final List<String> names) { | ||
final Set<String> nonDuplicateNames = new HashSet<>(names); | ||
if (nonDuplicateNames.size() != names.size()) { | ||
throw new IllegalArgumentException(DUPLICATE_NAMES_MESSAGE); | ||
} | ||
} | ||
|
||
private List<Player> generatePlayers(final List<String> names) { | ||
return names.stream() | ||
.map(Player::new) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
public List<String> getNames() { | ||
return players.stream() | ||
.map(Player::getName) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
public int count() { | ||
return players.size(); | ||
} | ||
} |
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,13 @@ | ||
package ladder.domain; | ||
|
||
import java.util.Random; | ||
|
||
public class RandomBooleanGenerator implements BooleanGenerator { | ||
|
||
private final Random random = new Random(); | ||
|
||
@Override | ||
public boolean generate() { | ||
return random.nextBoolean(); | ||
} | ||
} |
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.
기능목록을 상세하게 잘 작성해주셨네요 👍🏻