-
Notifications
You must be signed in to change notification settings - Fork 26
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
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
0ae857e
757d288
26aeaf4
5728800
b114c65
4adc205
468e5f8
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.
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("사다리 위치는 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; | ||
} | ||
} |
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,30 @@ | ||
package ladder; | ||
|
||
import ladder.creator.LadderCreator; | ||
import ladder.creator.LadderManualCreator; | ||
import ladder.creator.LadderRandomCreator; | ||
|
||
public class LadderGame { | ||
|
||
LadderCreator ladderCreator; | ||
|
||
public LadderGame(LadderCreator ladderCreator){ | ||
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(); | ||
} | ||
} |
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
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. 지금 팩토리는 Creator를 주입하는 것 외에 하는 일이 없네요. 팩토리가 game 생성에 필요한 작업을 모두 수행하는 게 좋을 것 같아요. 그러면 나중에 수정할 때 팩토리만 수정하면 되니 편하겠죠? 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. 앗 조언 감사드립니다...!! |
||
|
||
// todo trouble-shooting | ||
// public LadderGame createRandomLadderGame(LadderCreator randomCreator) { | ||
// return ladderGame.RandomGame((LadderRandomCreator) randomCreator); | ||
// } | ||
// | ||
// public LadderGame createManualLadderGame(LadderCreator manualCreator) { | ||
// return ladderGame.ManualGame((LadderManualCreator) manualCreator); | ||
// } | ||
} | ||
|
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; | ||
} | ||
} |
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
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. 별을 찍을지 제어변수로 결정하는 아이디어 괜찮은 것 같아요. 그런데 이런 제어결합도는 혼란을 야기할 수 있으니 주의해서 사용하는 게 좋을 것 같습니다. |
||
|
||
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(); | ||
} | ||
|
||
} |
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); | ||
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 형변환이나 round() 둘 중 하나만 써도 될 것 같네요! |
||
} | ||
} |
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.
인터페이스를 이용하니 아래와 같이 같은 기능을 하는 코드의 중복을 줄일 수 있었네요!