-
Notifications
You must be signed in to change notification settings - Fork 60
[사다리 - 3단계] 김성환 미션 제출합니다. #24
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: fanngineer
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,21 @@ | |
| import java.util.List; | ||
|
|
||
| public class Ladder { | ||
| private final List<Participant> participants; | ||
| private final List<Line> lines; | ||
|
|
||
| public Ladder(Size ladderSize, Size lineSize) { | ||
| this.participants = generateParticipants(lineSize); | ||
| this.lines = generateLines(ladderSize, lineSize); | ||
| getResult(); | ||
|
||
| } | ||
|
|
||
| private List<Participant> generateParticipants(Size lineSize) { | ||
| List<Participant> participants = new ArrayList<>(); | ||
| for (int i = 0; i < lineSize.getSize(); i++) { | ||
| participants.add(new Participant(i)); | ||
| } | ||
| return participants; | ||
| } | ||
|
|
||
| private List<Line> generateLines(Size ladderSize, Size lineSize) { | ||
|
|
@@ -18,7 +29,35 @@ private List<Line> generateLines(Size ladderSize, Size lineSize) { | |
| return lines; | ||
| } | ||
|
|
||
| private void getResult(){ | ||
| for (Line line : lines) { | ||
| changeByLine(line); | ||
| } | ||
| } | ||
|
|
||
| private void changeByLine(Line line){ | ||
| for(int i = 0; i< line.getPoints().size() ; i++){ | ||
| changeByPoint(i,line.getPoints().get(i)); | ||
| } | ||
| } | ||
|
|
||
| private void changeByPoint(int idx, Point point){ | ||
| if(point.isConnected()){ | ||
| swapEnds(idx); | ||
| } | ||
| } | ||
|
|
||
| private void swapEnds(int idx){ | ||
| int temp = participants.get(idx).getEnd(); | ||
| participants.get(idx).setEnd(participants.get(idx+1).getEnd()); | ||
| participants.get(idx+1).setEnd(temp); | ||
| } | ||
|
||
|
|
||
| public List<Line> getLines() { | ||
| return lines; | ||
| } | ||
|
|
||
| public List<Participant> getParticipants() { | ||
| return participants; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package domain; | ||
|
|
||
| public class Participant { | ||
| private final int start; | ||
| private int end; | ||
|
|
||
| public Participant(int start) { | ||
| this.start = start; | ||
| this.end = start; | ||
| } | ||
|
|
||
| public int getStart() { | ||
| return start; | ||
| } | ||
|
|
||
| public int getEnd() { | ||
| return end; | ||
| } | ||
|
|
||
| public void setEnd(int end) { | ||
| this.end = end; | ||
| } | ||
|
||
| } | ||
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.
Ladder에서는 Participant를 직접 의존하는 것보다 사다리를 타는 과정에서만 협력을 하는 방안은 어떻게 생각하시나요?
혹시 Participant를 직접 의존하신 이유는 무엇인가요?
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.
저는 일반적으로 사다리게임이 1회성이라 생각해서 하나의 사다리게임 안에 참여자들이 속해있다고 생각해서 그처럼 구현했습니다. 그런데 말씀 듣고나니 고정된 생각을 벗어나서 의존성을 줄이는 방법으로 구현하는게 좋을 것 같아 반영하겠습니다!