Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
adb3d07
feat : add basic code and test
hamhyeongju Sep 17, 2024
7c31908
move : move domain to ladder package
hamhyeongju Sep 19, 2024
0b34dd5
refactor : use Direction enum class instead of 1, -1, 0
hamhyeongju Sep 19, 2024
73cb92a
refactor : apply Direction
hamhyeongju Sep 19, 2024
8a8aa6a
refactor : static import Direction
hamhyeongju Sep 19, 2024
5eb6c3d
refactor : add GreaterThanOne for valid ladder constructor argument
hamhyeongju Sep 19, 2024
779ace3
refactor : apply GreaterThanOne
hamhyeongju Sep 19, 2024
c5caa08
refactor : add ExceptionMessage enum
hamhyeongju Sep 19, 2024
aff6206
refactor : apply ExceptionMessage
hamhyeongju Sep 19, 2024
beaf072
refactor : add Position
hamhyeongju Sep 20, 2024
d0e6790
refactor : apply Position
hamhyeongju Sep 20, 2024
8fa2890
refactor : add Node class for wrap int array value
hamhyeongju Sep 20, 2024
9b3a2d9
refactor : apply Node
hamhyeongju Sep 20, 2024
5ebaf3a
test : add test case for Node
hamhyeongju Sep 20, 2024
9f87691
refactor : extract LadderCreator class from Ladder
hamhyeongju Sep 20, 2024
0ea3ab6
refactor : extract LadderRunner class from Ladder
hamhyeongju Sep 20, 2024
7954a2b
refactor : apply LadderCreator and LadderRunner
hamhyeongju Sep 20, 2024
449a429
rename : from Ladder
hamhyeongju Sep 20, 2024
3e5115e
refactor : apply LadderCreator and LadderRunner
hamhyeongju Sep 20, 2024
79b8c4e
update : optimize code
hamhyeongju Sep 20, 2024
00035bb
feat: add ladder print logic
cyLee1111 Sep 26, 2024
edfafc1
test: change row value verification from print to assertion
cyLee1111 Sep 26, 2024
c08675a
feat: add auto ladder create logic
cyLee1111 Sep 27, 2024
b60a9e7
refactor: AutoLadderCreator.drawLine method
cyLee1111 Sep 27, 2024
b148d0b
refactor: LadderRunner.printRows method
cyLee1111 Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions src/main/java/Ladder.java

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/java/ladder/Direction.java

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum으로 관리 하다니 멋져요!

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;
}
}
20 changes: 20 additions & 0 deletions src/main/java/ladder/ExceptionMessage.java
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;
}
}
29 changes: 29 additions & 0 deletions src/main/java/ladder/GreaterThanOne.java
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;
}
}
25 changes: 25 additions & 0 deletions src/main/java/ladder/LadderGame.java
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

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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();
}
}
41 changes: 41 additions & 0 deletions src/main/java/ladder/LadderRunner.java

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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();
}
}
16 changes: 16 additions & 0 deletions src/main/java/ladder/LadderSize.java
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(); }
}
53 changes: 53 additions & 0 deletions src/main/java/ladder/Node.java
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

Choose a reason for hiding this comment

The 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;
}
}
Loading