-
Notifications
You must be signed in to change notification settings - Fork 26
2주차 미션 / 서버 3조 김나은 #39
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
base: main
Are you sure you want to change the base?
Changes from all commits
adb3d07
7c31908
1b840fa
cb14c2d
88164f6
1d6b238
86babdb
ec3da7b
90f773f
ef778ef
11141e4
6c46052
659c17a
3c89116
545f620
16d0986
8634a54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ladder; | ||
|
|
||
| public enum Direction { | ||
| LEFT(-1), RIGHT(1), NONE(0); | ||
|
|
||
| private final int value; | ||
|
|
||
| Direction(int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public int getValue() { | ||
| return value; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package ladder; | ||
|
|
||
| public enum ExceptionMessage { | ||
|
|
||
| INVALID_LADDER_POSITION("사다리 위치는 1이상 자연수입니다."), | ||
| INVALID_LADDER_NUMBER("사다리의 행과 열은 2 이상이어야 합니다."), | ||
| INVALID_POSITION("유효하지 않은 위치입니다."), | ||
| INVALID_DRAW_POSITION("사다리를 그릴 수 없는 위치입니다."), | ||
| INVALID_NATURAL_NUMBER("자연수가 아닙니다."); | ||
|
|
||
| private final String message; | ||
|
|
||
| ExceptionMessage(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package ladder; | ||
|
|
||
| public class GreaterThanOne { | ||
|
|
||
| private final int number; | ||
|
|
||
| private GreaterThanOne(int number) { | ||
| this.number = number; | ||
| } | ||
|
|
||
| public static GreaterThanOne from(int number) { | ||
| if (!isGreaterThanOne(number)) { | ||
| throw new IllegalArgumentException(ExceptionMessage.INVALID_LADDER_NUMBER.getMessage()); | ||
| } | ||
|
|
||
| return new GreaterThanOne(number); | ||
| } | ||
|
|
||
| private static boolean isGreaterThanOne(int number) { | ||
| return number > 1; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package ladder; | ||
|
|
||
| import ladder.creator.LadderCreator; | ||
|
|
||
| public class LadderGame { | ||
|
|
||
| private final LadderCreator ladderCreator; | ||
|
|
||
| public LadderGame(LadderCreator ladderCreator) { | ||
| this.ladderCreator = ladderCreator; | ||
| } | ||
|
|
||
| // 사다리에 position값을 넣어주고 반복문을 통해 | ||
| // 메세지를 보내면서 다음 좌표가 어딨는지 질문을 함 | ||
| public int run(Position position) { | ||
| LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); | ||
| ladderRunner.run(position); | ||
| return position.getPosition(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package ladder; | ||
|
|
||
| import ladder.creator.AutoLadderCreator; | ||
| import ladder.creator.LadderCreator; | ||
|
|
||
| public class LadderGameFactory { | ||
|
|
||
| private static LadderCreator ladderCreator; | ||
|
|
||
| public static LadderGame createRandomLadderGame(LadderSize ladderSize) { | ||
| AutoLadderCreator autoLadderCreator = new AutoLadderCreator(ladderSize.getNumberOfRow(), ladderSize.getNumberOfPerson()); | ||
| return new LadderGame(autoLadderCreator); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderPosition { | ||
| private final int row; | ||
| private final int col; | ||
|
|
||
| public LadderPosition(int row, int col) { | ||
| this.row = row; | ||
| this.col = col; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderRunner { | ||
|
|
||
| private final Row[] rows; | ||
|
|
||
| public LadderRunner(Row[] rows) { | ||
| this.rows = rows; | ||
| } | ||
|
|
||
| public int run(Position position) { | ||
| for (int i = 0; i < rows.length; i++) { | ||
| // Before 출력 | ||
| System.out.println("Before"); | ||
| printLadder(position, i); // 사다리 상태 출력 | ||
| System.out.println(); | ||
|
|
||
| // 현재 행에서 위치 이동 (왼쪽 또는 오른쪽으로) | ||
| rows[i].nextPosition(position); | ||
|
|
||
| // After 출력 | ||
| System.out.println("After"); | ||
| printLadder(position, i); // 사다리 상태 출력 | ||
| System.out.println(); | ||
| } | ||
|
|
||
| return position.getPosition(); | ||
| } | ||
|
|
||
| // 사다리 상태를 출력하는 메서드 | ||
| private void printLadder(Position position, int currentRow) { | ||
| for (int i = 0; i < rows.length; i++) { | ||
| if (currentRow == i) { | ||
| rows[i].printUserRow(position); // 사용자 위치를 표시하여 출력 | ||
| } else { | ||
| rows[i].printRow(); // 일반 행 출력 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderSize { | ||
| private final GreaterThanOne numberOfRow; | ||
| private final GreaterThanOne numberOfPerson; | ||
| private static final double LINE_PROBABILITY = 0.3; | ||
|
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. 오 가로선 비율을 상수로 설정한 점 좋은 것 같아요! 나중에 봐도 이 값의 의미를 바로 알겠네요 |
||
|
|
||
| public LadderSize(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { | ||
| this.numberOfRow = numberOfRow; | ||
| this.numberOfPerson = numberOfPerson; | ||
| } | ||
|
|
||
| public GreaterThanOne getNumberOfRow() { | ||
| return numberOfRow; | ||
| } | ||
|
|
||
| public GreaterThanOne getNumberOfPerson() { | ||
| return numberOfPerson; | ||
| } | ||
|
|
||
| public int calculateNumberOfLines() { | ||
| // 사다리 행 * 열 * 0.3에 해당하는 라인의 수 계산 | ||
| return (int) (numberOfRow.getNumber() * numberOfPerson.getNumber() * LINE_PROBABILITY); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package ladder; | ||
|
|
||
| import static ladder.Direction.*; | ||
|
|
||
| public class Node { | ||
|
|
||
| private Direction direction; | ||
|
|
||
| private Node(Direction direction) { | ||
| this.direction = direction; | ||
| } | ||
|
|
||
| public static Node from(Direction direction) { | ||
| return new Node(direction); | ||
| } | ||
|
|
||
| public void setRightNode(Position position) { | ||
| direction = RIGHT; | ||
| } | ||
|
|
||
| public void setLeftNode(Position position) { | ||
| direction = LEFT; | ||
| } | ||
|
|
||
| public void move(Position position) { | ||
|
|
||
| if (isRight()) { | ||
| position.next(); | ||
| return; | ||
| } | ||
| if (isLeft()) { | ||
| position.prev(); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| public boolean isAlreadySetDirection() { | ||
| return !isNone(); | ||
| } | ||
|
|
||
| private boolean isRight() { | ||
| return direction == RIGHT; | ||
| } | ||
|
|
||
| private boolean isLeft() { | ||
| return direction == LEFT; | ||
| } | ||
|
|
||
| private boolean isNone() { | ||
| return direction == NONE; | ||
| } | ||
|
|
||
| // 방향 값을 반환하는 메서드 | ||
| public int getDirectionValue() { | ||
| return switch (direction) { | ||
| case LEFT -> -1; | ||
| case RIGHT -> 1; | ||
| default -> 0; | ||
| }; | ||
| } | ||
| } |
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.
인자 row도 Position 객체이면 좋을 것 같네요