-
Notifications
You must be signed in to change notification settings - Fork 26
2주차 미션 / 서버 2조 이찬양 #42
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
0b34dd5
73cb92a
8a8aa6a
5eb6c3d
779ace3
c5caa08
aff6206
beaf072
d0e6790
8fa2890
9b3a2d9
5ebaf3a
9f87691
0ea3ab6
7954a2b
449a429
3e5115e
79b8c4e
00035bb
edfafc1
c08675a
b60a9e7
b148d0b
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.
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,16 @@ | ||
| 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,29 @@ | ||
| package ladder; | ||
|
|
||
| public class GreaterThanOne { | ||
|
|
||
| private final int number; | ||
|
|
||
| public GreaterThanOne(int number) { | ||
| validate(number); | ||
| this.number = number; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| public static GreaterThanOne from(int number) { | ||
| return new GreaterThanOne(number); | ||
| } | ||
|
|
||
| private void validate(int number) { | ||
| if (!isGreaterThanOne(number)) { | ||
| throw new IllegalArgumentException(ExceptionMessage.INVALID_LADDER_NUMBER.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private static boolean isGreaterThanOne(int number) { | ||
| return number > 1; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package ladder; | ||
|
|
||
| import ladder.creator.AutoLadderCreator; | ||
| import ladder.creator.LadderCreator; | ||
|
|
||
| public class LadderGame { | ||
|
|
||
| private final LadderCreator ladderCreator; | ||
|
|
||
| public LadderGame(LadderCreator ladderCreator) { | ||
| this.ladderCreator = ladderCreator; | ||
| } | ||
|
Comment on lines
+10
to
+12
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. DI 잘 활용하셨습니다!! |
||
|
|
||
| public static LadderGame createAutoLadderGame(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { | ||
| LadderCreator ladderCreator = LadderCreator.autoCreator(numberOfRow, numberOfPerson); | ||
| ladderCreator.drawLine(); | ||
| return new LadderGame(ladderCreator); | ||
| } | ||
|
|
||
| public int run(Position position) { | ||
|
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. position으로 받는 거 좋은 아이디어인거 같습니다 👍 |
||
| LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); | ||
| ladderRunner.run(position); | ||
| return position.getValue(); | ||
| } | ||
| } | ||
|
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. 출력의 책임을 LadderRunner에 위임한게 인상적이네요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package ladder; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| 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++) { | ||
| System.out.println("Before"); | ||
| printRows(position.getValue(), i); | ||
|
|
||
| rows[i].nextPosition(position); | ||
|
|
||
| System.out.println("After"); | ||
| printRows(position.getValue(), i); | ||
| } | ||
| return position.getValue(); | ||
| } | ||
|
|
||
| private void printRows(int moveX, int moveY) { | ||
|
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. position대신 int를 쓰셨는데, 이유가 뭔가요? |
||
| for (int i = 0; i < rows.length; i++) { | ||
| printRow(i, moveX, moveY); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| private void printRow(int rowIndex, int moveX, int moveY) { | ||
| int[] values = rows[rowIndex].getRowValue(); | ||
| for (int j = 0; j < rows[0].getSize(); j++) { | ||
| String moveCheck = (moveY == rowIndex && moveX == j) ? "* " : " "; | ||
| System.out.print(values[j] + moveCheck); | ||
| } | ||
| System.out.println(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderSize { | ||
|
|
||
| private final GreaterThanOne numberOfRow; | ||
| private final GreaterThanOne numberOfPerson; | ||
|
|
||
| public LadderSize(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { | ||
| this.numberOfRow = numberOfRow; | ||
| this.numberOfPerson = numberOfPerson; | ||
| } | ||
|
|
||
| public int getNumberOfRow() { return numberOfRow.getNumber(); } | ||
|
|
||
| public int getNumberOfPerson() { return numberOfPerson.getNumber(); } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| 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 move(Position position) { | ||
| if (isRight()) { | ||
| position.next(); | ||
| return; | ||
| } | ||
| if (isLeft()) { | ||
| position.prev(); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| public int getDirectionValue() { return this.direction.getValue(); } | ||
|
|
||
| public void setRightNode() { | ||
| direction = RIGHT; | ||
| } | ||
|
|
||
| public void setLeftNode() { | ||
| direction = LEFT; | ||
| } | ||
|
|
||
| public boolean isAlreadySetDirection() { | ||
| return !isNone(); | ||
| } | ||
|
Comment on lines
+30
to
+40
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. Node의 값이 변경될때, 새로운 node를 생성하는 방식으로 처리해도 될거 같은데, setter을 사용한 특별한 이유가 있나요? |
||
|
|
||
| private boolean isRight() { | ||
| return direction == RIGHT; | ||
| } | ||
|
|
||
| private boolean isLeft() { | ||
| return direction == LEFT; | ||
| } | ||
|
|
||
| private boolean isNone() { | ||
| return direction == NONE; | ||
| } | ||
| } | ||
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.
Enum으로 관리 하다니 멋져요!