Skip to content
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

2주차 미션 / 서버 3조 이윤희 #44

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
0ae857e
mission2 기능 구현
lylylylh Sep 24, 2024
757d288
LadderRandomCreator
lylylylh Sep 27, 2024
26aeaf4
creator interface
lylylylh Sep 27, 2024
5728800
factory 분리
lylylylh Sep 27, 2024
b114c65
random 기본 test
lylylylh Sep 27, 2024
4adc205
random test
lylylylh Sep 27, 2024
468e5f8
ramdom 오류 수정
lylylylh 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.

3 changes: 2 additions & 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.

1 change: 1 addition & 0 deletions .idea/vcs.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
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("사다리 위치는 0이상 입니다."),
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;
}
}
30 changes: 30 additions & 0 deletions src/main/java/ladder/LadderGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ladder;

import ladder.creator.LadderCreator;
import ladder.creator.LadderManualCreator;
import ladder.creator.LadderRandomCreator;

public class LadderGame {

LadderCreator ladderCreator;

public LadderGame(LadderCreator ladderCreator){

Choose a reason for hiding this comment

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

인터페이스를 이용하니 아래와 같이 같은 기능을 하는 코드의 중복을 줄일 수 있었네요!

this.ladderCreator = ladderCreator;
}

// public LadderGame RandomGame(LadderRandomCreator ladderRandomCreator) {
// this.ladderCreator = ladderRandomCreator;
// return this;
// }
//
// public LadderGame ManualGame(LadderManualCreator ladderManualCreator) {
// this.ladderCreator = ladderManualCreator;
// return this;
// }

public int run(Position position) {
LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows());
ladderRunner.run(position);
return position.getValue();
}
}
26 changes: 26 additions & 0 deletions src/main/java/ladder/LadderGameFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ladder;

import ladder.creator.LadderCreator;
import ladder.creator.LadderManualCreator;
import ladder.creator.LadderRandomCreator;

public class LadderGameFactory {

public static LadderGame createRandomLadderGame(LadderCreator randomCreator) {
return new LadderGame((LadderRandomCreator) randomCreator);
}

public static LadderGame createManualLadderGame(LadderCreator manualCreator) {
return new LadderGame((LadderManualCreator) manualCreator);
}
Comment on lines +9 to +15
Copy link

@JangIkhwan JangIkhwan Sep 28, 2024

Choose a reason for hiding this comment

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

지금 팩토리는 Creator를 주입하는 것 외에 하는 일이 없네요. 팩토리가 game 생성에 필요한 작업을 모두 수행하는 게 좋을 것 같아요. 그러면 나중에 수정할 때 팩토리만 수정하면 되니 편하겠죠?

Copy link
Author

Choose a reason for hiding this comment

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

앗 조언 감사드립니다...!!


// todo trouble-shooting
// public LadderGame createRandomLadderGame(LadderCreator randomCreator) {
// return ladderGame.RandomGame((LadderRandomCreator) randomCreator);
// }
//
// public LadderGame createManualLadderGame(LadderCreator manualCreator) {
// return ladderGame.ManualGame((LadderManualCreator) manualCreator);
// }
}

18 changes: 18 additions & 0 deletions src/main/java/ladder/LadderPosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ladder;

public class LadderPosition {

Position row, column;

public LadderPosition(Position row, Position column) {
this.row = row;
this.column = column;
}

public Position getRow() {
return row;
}
public Position getColumn() {
return column;
}
}
37 changes: 37 additions & 0 deletions src/main/java/ladder/LadderRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ladder;

public class LadderRunner {

private final Row[] rows;

public LadderRunner(Row[] rows) {
this.rows = rows;
}

// todo LadderPosition <- rowNumber + position
public void printRow(int rowNumber, int position, int currentRow) {
boolean isCurrent = (currentRow == rowNumber);
System.out.println(rows[rowNumber].rowToString(position, isCurrent));
}
Comment on lines +12 to +15

Choose a reason for hiding this comment

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

별을 찍을지 제어변수로 결정하는 아이디어 괜찮은 것 같아요. 그런데 이런 제어결합도는 혼란을 야기할 수 있으니 주의해서 사용하는 게 좋을 것 같습니다.


public void printLadder(int row, int position){
for (int i = 0; i < rows.length; i++) {
printRow(i, position, row);
}
System.out.println();
}
public int run(Position position) {
for (int i = 0; i < rows.length; i++) {

System.out.println("Before");
printLadder(i, position.getValue());

rows[i].nextPosition(position);

System.out.println("After");
printLadder(i, position.getValue());
}
return position.getValue();
}

}
15 changes: 15 additions & 0 deletions src/main/java/ladder/LadderSize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ladder;

public class LadderSize {

private GreaterThanOne numberOfRow, numberOfPerson;

public LadderSize(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) {
this.numberOfRow = numberOfRow;
this.numberOfPerson = numberOfPerson;
}

public int getNumberOfRandomLine() {
return (int)Math.round(this.numberOfRow.getNumber() * this.numberOfPerson.getNumber() * 0.3);

Choose a reason for hiding this comment

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

int 형변환이나 round() 둘 중 하나만 써도 될 것 같네요!

}
}
Loading