-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Step5 #6146
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
Open
hyoojuu
wants to merge
9
commits into
next-step:hyoojuu
Choose a base branch
from
hyoojuu:step5
base: hyoojuu
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Step5 #6146
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
13f5e9e
refactor: refactor car position equals logic and add car positions class
hyoojuu c40bb33
fix: delete car manager class
hyoojuu 51dce55
feat: add race record classes
hyoojuu 4c773c1
test: add domain test case
hyoojuu a00a821
refactor: add controller class and refine view dependency
hyoojuu 6a39667
refactor: add controller class and refine view dependency
hyoojuu 3902ae8
refactor: simplify equals logic
hyoojuu fef0f20
refactor: add field to race record class
hyoojuu 5aaeef4
refactor: refactor getWinnerNames logic and remove unused class
hyoojuu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,11 @@ | ||
package racingcar; | ||
|
||
import java.util.List; | ||
|
||
import racingcar.domain.Cars; | ||
import racingcar.utils.NumberUtils; | ||
import racingcar.utils.StringUtils; | ||
import racingcar.view.InputView; | ||
import racingcar.view.ResultView; | ||
import racingcar.controller.RacingCarController; | ||
|
||
public class RacingCar { | ||
|
||
public static void main(String[] args) { | ||
play(); | ||
} | ||
|
||
private static void play() { | ||
List<String> carNames = StringUtils.splitByComma(InputView.getCarNames()); | ||
Cars cars = CarManager.initCars(carNames); | ||
|
||
int tryCount = NumberUtils.toInt(InputView.getTryCount()); | ||
|
||
ResultView.printInitialState(); | ||
CarManager.print(cars); | ||
|
||
Cars movedCars = CarManager.move(cars, tryCount); | ||
ResultView.printWinner(movedCars.getWinnerNames()); | ||
RacingCarController racingCarController = new RacingCarController(); | ||
racingCarController.play(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/racingcar/controller/RacingCarController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package racingcar.controller; | ||
|
||
import java.util.List; | ||
|
||
import racingcar.domain.Cars; | ||
import racingcar.domain.RaceRecords; | ||
import racingcar.utils.NumberUtils; | ||
import racingcar.utils.StringUtils; | ||
import racingcar.view.InputView; | ||
import racingcar.view.ResultView; | ||
|
||
public class RacingCarController { | ||
|
||
public void play() { | ||
List<String> carNames = StringUtils.splitByComma(InputView.getCarNames()); | ||
Cars cars = Cars.create(carNames); | ||
|
||
int tryCount = NumberUtils.toInt(InputView.getTryCount()); | ||
|
||
RaceRecords raceRecords = RaceRecords.init(cars); | ||
for (int sequence = 1; sequence <= tryCount; sequence++) { | ||
cars = cars.move(); | ||
raceRecords.record(sequence, cars); | ||
} | ||
|
||
raceRecords.getValues() | ||
.forEach(raceRecord -> { | ||
ResultView.printSequence(raceRecord.getSequence()); | ||
raceRecord.getCars() | ||
.getValues() | ||
.forEach(car -> ResultView.print(car.getName(), car.getPositionValue())); | ||
ResultView.printNewLine(); | ||
}); | ||
|
||
ResultView.printWinner(raceRecords.getWinnerNames()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package racingcar.domain; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class RaceRecord { | ||
|
||
private static final int SEQUENCE_INIT = 0; | ||
|
||
private final int sequence; | ||
private final Cars cars; | ||
|
||
public RaceRecord(Cars cars) { | ||
this.sequence = SEQUENCE_INIT; | ||
this.cars = cars; | ||
} | ||
|
||
public RaceRecord(int sequence, Cars cars) { | ||
this.sequence = sequence; | ||
this.cars = cars; | ||
} | ||
|
||
public int getSequence() { | ||
return this.sequence; | ||
} | ||
|
||
public Cars getCars() { | ||
return this.cars; | ||
} | ||
|
||
public List<String> getWinnerNames() { | ||
return getCars().getValues() | ||
.stream() | ||
.filter(this::isMaxPosition) | ||
.map(Car::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private boolean isMaxPosition(Car car) { | ||
return getCars().getMaxPosition() | ||
.equals(car.getPosition()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package racingcar.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RaceRecords { | ||
|
||
private final List<RaceRecord> values; | ||
|
||
public RaceRecords(List<RaceRecord> values) { | ||
this.values = new ArrayList<>(values); | ||
} | ||
|
||
public static RaceRecords init(Cars cars) { | ||
return new RaceRecords(List.of(new RaceRecord(cars))); | ||
} | ||
|
||
public void record(int sequence, Cars cars) { | ||
this.values.add(new RaceRecord(sequence, cars)); | ||
} | ||
|
||
public List<RaceRecord> getValues() { | ||
return this.values; | ||
} | ||
|
||
public List<String> getWinnerNames() { | ||
return getResult().getWinnerNames(); | ||
} | ||
|
||
private RaceRecord getResult() { | ||
return this.values.get(this.values.size() - 1); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,16 @@ | |
- [x] 사용자가 입력한 이름의 숫자 만큼 자동차 대수를 생성한다. | ||
- [x] 자동차 이름과 위치를 출력한다. | ||
- [x] 게임을 완료한 후 우승자를 출력한다.(공동 우승자 포함) | ||
<hr/> | ||
|
||
#### 5단계 전 리팩토링 | ||
- [x] CarPosition 리팩토링 (CarPositions 추가) | ||
|
||
### 🚀 5단계 - 자동차 경주(리팩토링) | ||
- [x] CarManager 제거 | ||
- [x] RaceRecord 추가 | ||
- [x] TC 추가 및 리팩토링 | ||
Comment on lines
+32
to
+34
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. 👍 |
||
- [x] Controller 추가 및 view 의존성 재정의 | ||
- [x] equals and hashCode 로직 수정 | ||
- [x] RaceRecord 리팩토링 | ||
- [x] getWinnerNames 메소드 리팩토링 및 CarPositions 삭제 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이렇게해도 차이점이 없을것 같아요!
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.
혹시 RaceRecord 객체에 sequence 필드를 추가했을 때, 기존 코드로 사용 가능한거 맞을까요??
sequence 필드 추가한 코드 커밋해보았습니다! 한 번 더 검토 부탁드립니다..!