-
Notifications
You must be signed in to change notification settings - Fork 26
2주차 미션 / 서버 4조 김재윤 #30
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
d888747
9757128
537d26a
9f0adab
8417f34
26b7f9b
deb2dd5
a94de76
db445c1
11855b1
b804dbe
dac741e
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.
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package ladder; | ||
|
|
||
| public enum Flag { | ||
|
|
||
| AFTER("After"), | ||
| BEFORE("Before"); | ||
|
|
||
|
|
||
| private final String flag; | ||
|
|
||
| Flag(String flag) { | ||
| this.flag = flag; | ||
| } | ||
|
|
||
| public String getFlag() { | ||
| return flag; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package ladder; | ||
|
|
||
| import ladder.creator.RandomNumber; | ||
|
|
||
| public class LadderPosition { | ||
| private int row; | ||
| private final Position col; | ||
|
|
||
| private LadderPosition(int col, int row){ | ||
| this.row = row; | ||
| this.col = Position.from(col); | ||
| } | ||
| private LadderPosition(Position position, int row){ | ||
| this.row = row; | ||
| this.col = position; | ||
| } | ||
|
|
||
| public static LadderPosition autoLadderPosition(int numberOfCol, int numberOfRow){ | ||
| int col = RandomNumber.from(numberOfCol-1); //line을 그려줘야 되기 때문에 옆으로 한칸 여유가 있어야 함 | ||
| int row = RandomNumber.from((numberOfRow)); | ||
|
|
||
| return new LadderPosition(col, row); | ||
| } | ||
|
|
||
| public static LadderPosition from(Position position, int row){ | ||
| return new LadderPosition(position, row); | ||
| } | ||
|
|
||
| public int getRow() { | ||
| return row; | ||
| } | ||
|
|
||
| public Position getCol() { | ||
| return col; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| public class Row { | ||
| private final Node[] nodes; | ||
| private StringBuilder rowStringBuilder; | ||
|
|
||
| public Row(GreaterThanOne numberOfPerson) { | ||
| nodes = new Node[numberOfPerson.getNumber()]; | ||
|
|
@@ -18,19 +19,80 @@ public void drawLine(Position startPosition) { | |
| setDirectionBetweenNextPosition(startPosition); | ||
| } | ||
|
|
||
| //사다리 한 개 층 문자열 생성 | ||
| public void setRowString(){ | ||
| rowStringBuilder = new StringBuilder(); | ||
|
|
||
| for (Node node : nodes) { | ||
| node.setNodeString(rowStringBuilder); //append(nodos.getValue()) 보다, node에 sb 넘겨줘서 처리 | ||
| } | ||
| rowStringBuilder.deleteCharAt(rowStringBuilder.length()-1); | ||
| rowStringBuilder.append("\n"); | ||
|
|
||
| } | ||
|
|
||
| public void nextPosition(Position position) { | ||
| validatePosition(position); | ||
|
|
||
| nodes[position.getValue()].move(position); | ||
| } | ||
|
|
||
| // '*'를 제거하고, '*' 없는 문자열 반환 | ||
| public StringBuilder getRowStringBuilder() { | ||
| clearStarInRowString(); | ||
|
|
||
| return rowStringBuilder; | ||
| } | ||
|
|
||
| // '*'를 제거하고, 새 위치에 '*'를 추가하여 문자열 반환 | ||
| public StringBuilder getRowStringBuilder(Position position) { | ||
| clearStarInRowString(); | ||
| insertStarAtPosition(position); | ||
|
|
||
| return rowStringBuilder; | ||
| } | ||
|
|
||
| // 문자열에서 '*'를 제거하는 메서드 | ||
| private void clearStarInRowString() { | ||
| int starIndex = rowStringBuilder.indexOf("*"); | ||
|
|
||
| if (starIndex != -1) { | ||
| rowStringBuilder.deleteCharAt(starIndex); | ||
| } | ||
| } | ||
|
Member
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 void insertStarAtPosition(Position position) { | ||
| int offset = calculateOffsetForStar(position); | ||
|
|
||
| rowStringBuilder.insert(position.getValue() * 2 + 1 + offset, "*"); | ||
| } | ||
|
|
||
| // '*'가 삽입될 위치를 계산하는 메서드 | ||
| private int calculateOffsetForStar(Position position) { | ||
| int offset = 0; | ||
| int col = 0; | ||
|
|
||
| // '*'가 들어갈 위치에 '-'가 있으면, 그만큼 offset을 증가 | ||
| for (int i = 0; i * 2 + offset < rowStringBuilder.length(); i++) { | ||
| if (col > position.getValue()) { | ||
| break; | ||
| } | ||
| col++; | ||
| if (rowStringBuilder.charAt(i * 2 + offset) == '-') { | ||
| offset++; | ||
| } | ||
| } | ||
| return offset; | ||
| } | ||
|
|
||
| private void setDirectionBetweenNextPosition(Position position) { | ||
| nodes[position.getValue()].setRightNode(); | ||
| position.next(); | ||
| nodes[position.getValue()].setLeftNode(); | ||
| } | ||
|
|
||
| private void validatePosition(Position position) { | ||
| public void validatePosition(Position position) { //일단 public으로 수정하여 진행 | ||
| if (isInvalidPosition(position) ) { | ||
| throw new IllegalArgumentException(ExceptionMessage.INVALID_POSITION.getMessage()); | ||
| } | ||
|
|
||
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.
LadderAutoCreator가 랜덤 처리에 관한 역할을 하고 있는 것 같은데 LadderPosition에서 랜덤 값을 직접 다루는 건 해당 클래스의 책임을 벗어나는 것 같습니다.
LadderAutoCreator 에서 랜덤 값을 다루고, 생성된 랜덤 값을 단순히 파라미터로 받아 LadderPosition 객체를 생성하는게 바람직해 보입니다.