-
Notifications
You must be signed in to change notification settings - Fork 26
2주차 미션/ 서버 1조 정주연 #48
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: 1week-completed
Are you sure you want to change the base?
Changes from all commits
08ba60a
715c678
8034534
941261d
3572277
1c6a33c
ad3d6b6
f4ed75c
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| package ladder; | ||
|
|
||
| import ladder.creator.LadderCreator; | ||
| import ladder.creator.LadderCreatorIF; | ||
|
|
||
| public class LadderGame { | ||
|
|
||
| private final LadderCreator ladderCreator; | ||
| //private final LadderCreator ladderCreator; | ||
| private final LadderCreatorIF ladderCreator; | ||
|
|
||
| public LadderGame(LadderCreator ladderCreator) { | ||
|
|
||
| public LadderGame(LadderCreatorIF ladderCreator) { | ||
| this.ladderCreator = ladderCreator; | ||
| } | ||
|
|
||
| public int run(Position position) { | ||
| public static LadderGame of(LadderCreator ladderCreator) { | ||
| return new LadderGame(ladderCreator); | ||
| } | ||
|
|
||
| public int run(LadderPosition position) { | ||
| LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); | ||
| ladderRunner.run(position); | ||
| return position.getValue(); | ||
| return position.getX(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package ladder; | ||
|
|
||
| import static ladder.ExceptionMessage.INVALID_LADDER_POSITION; | ||
|
|
||
| public class LadderPosition { | ||
| private int x, y; | ||
|
|
||
| public LadderPosition(int x, int y) { | ||
|
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. 정적 팩터리 of로 반환하니 private으로 만들어 무분별한 생성자 접근을 막는게 좋아보여요! |
||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| public static LadderPosition of(int x, int y) { | ||
| validatePosition(x, y); | ||
| return new LadderPosition(x, y); | ||
| } | ||
| private static void validatePosition(int x, int y) { | ||
| if (x < 0 || y < 0) { | ||
| throw new IllegalArgumentException(ExceptionMessage.INVALID_LADDER_POSITION.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public int getX() { | ||
| return x; | ||
| } | ||
|
|
||
| public void setX(int x) { | ||
| this.x = x; | ||
| } | ||
|
|
||
| public int getY() { | ||
| return y; | ||
| } | ||
|
|
||
| public void setY(int y) { | ||
| this.y = y; | ||
| } | ||
|
|
||
| public boolean isCurrentPosition(int x, int y) { | ||
| return this.x == x && this.y == y; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "(" + x + ", " + y + ")"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package ladder; | ||
|
|
||
| import static javax.swing.RowFilter.ComparisonType.AFTER; | ||
|
|
||
| public class LadderRunner { | ||
|
|
||
| private final Row[] rows; | ||
|
|
@@ -8,10 +10,39 @@ public LadderRunner(Row[] rows) { | |
| this.rows = rows; | ||
| } | ||
|
|
||
| public int run(Position position) { | ||
| public int run(LadderPosition position) { | ||
| for (int i = 0; i < rows.length; i++) { | ||
|
|
||
| printLadder(position, "BEFORE"); | ||
|
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. BEFORE를 String으로 주는것보다, enum값을 추가하여 넣어주는게 나을것 같네요! |
||
|
|
||
| // 현재 행(Row)에서 좌우로 이동 | ||
| rows[i].nextPosition(position); | ||
|
|
||
| // 사다리 진행 후 상태 출력 (AFTER) | ||
| printLadder(position, "AFTER"); | ||
|
|
||
| // 행을 한 칸 아래로 이동 | ||
| PositionMover.moveDown(position); | ||
| } | ||
| return position.getX(); | ||
| } | ||
| //사다리 출력 메소드 | ||
| private void printLadder(LadderPosition currentPosition, String state) { | ||
| //Row[] rows = ladderCreator.getRows(); | ||
| System.out.println(state + ": 현재 위치는 (" + currentPosition.getX() + ", " + currentPosition.getY() + ") 입니다."); | ||
|
|
||
| for (int y = 0; y < rows.length; y++) { | ||
| StringBuilder rowStr = new StringBuilder(); | ||
| for (int x = 0; x < rows[y].getNodes().length; x++) { | ||
| //현재 위치 *으로 표시 | ||
| if (currentPosition.isCurrentPosition(x, y)) { | ||
| rowStr.append("* "); | ||
| } else { | ||
| rowStr.append(rows[y].getNodes()[x].toString().trim()).append(" "); | ||
| } | ||
| } | ||
| System.out.println(rowStr.toString().trim()); | ||
|
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. System.out.print보다 logback을 사용하여 로그 형태로 출력하는게 나을것 같네요! |
||
| } | ||
| return position.getValue(); | ||
| System.out.println(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package ladder; | ||
|
|
||
| import static ladder.ExceptionMessage.INVALID_LADDER_NUMBER; | ||
|
|
||
| public class LadderSize { | ||
| private final GreaterThanOne numberOfRows; | ||
| private final GreaterThanOne numberOfPersons; | ||
|
|
||
| public LadderSize(int numberOfRows, int numberOfPersons) { | ||
|
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. 이 생성자도 private으로 만들고, from을 통해 초기화한 후 객체를 반환하는게 어떨까요? |
||
| validate(numberOfRows, numberOfPersons); | ||
| this.numberOfRows = new GreaterThanOne(numberOfRows); | ||
| this.numberOfPersons = new GreaterThanOne (numberOfPersons); | ||
| } | ||
|
|
||
| public int getNumberOfRows() { | ||
|
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. int로 반환하는것보다 GreaterThanOne 클래스로 반환하는것도 좋아보입니다! |
||
| return numberOfRows.getNumber(); | ||
| } | ||
|
|
||
| public int getNumberOfPersons() { | ||
| return numberOfPersons.getNumber(); | ||
| } | ||
| private void validate(int numberOfRows, int numberOfPersons) { | ||
| if (numberOfRows < 2 || numberOfPersons < 2) { | ||
|
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. 경계값을 그냥 2로 설정하는것보다 따로 상수로 빼서 관리하는것도 좋아보입니다! |
||
| throw new IllegalArgumentException(INVALID_LADDER_NUMBER.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package ladder; | ||
|
|
||
| public class PositionMover { | ||
| public static void moveLeft(LadderPosition position) { | ||
| position.setX(position.getX() - 1); | ||
| } | ||
|
|
||
| public static void moveRight(LadderPosition position) { | ||
| position.setX(position.getX() + 1); | ||
| } | ||
|
|
||
| public static void moveDown(LadderPosition position) { | ||
| position.setY(position.getY() + 1); | ||
| } | ||
|
|
||
| public static boolean isSmallerThan(LadderPosition position, int x) { | ||
| return position.getX() < x; | ||
| } | ||
|
|
||
| public static boolean isBiggerThan(LadderPosition position, int x) { | ||
| return position.getX() > x; | ||
| } | ||
| } |
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.
LadderCreatorIF 클래스를 만드신 이유가 있을까요?