-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
๐ 5๋จ๊ณ - ์๋์ฐจ ๊ฒฝ์ฃผ(๋ฆฌํฉํ ๋ง) #5818
base: jonghyeonleee
Are you sure you want to change the base?
Changes from 1 commit
e66ce53
065e71c
90057c1
d905f4a
9d3b593
99749ca
f6053fa
8d16b5f
516281d
1332ebf
f0c3b6a
ed49ad8
2591e7f
2a99564
c01dacd
ff2a4e7
8533d99
e386be1
4fd6712
7651e0c
094b6be
0bee42d
8e94225
1643450
9a3199f
16ee9f8
be64fc4
13b1a3c
0c567b0
8e329e8
81149cf
47bdbbc
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 |
---|---|---|
@@ -1,55 +1,9 @@ | ||
package com.racing; | ||
|
||
import com.racing.domain.Car; | ||
import com.racing.domain.Cars; | ||
import com.racing.ui.InputView; | ||
import com.racing.ui.ResultView; | ||
import com.racing.utils.CarHelper; | ||
import com.racing.utils.RacingHelper; | ||
|
||
import java.util.List; | ||
import com.racing.service.RacingService; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
String carNames = InputView.getCarName(); | ||
int tryNumber = InputView.getTryNumber(); | ||
|
||
List<String> validCarNames = CarHelper.splitCarName(carNames); | ||
|
||
Cars cars = createCars(validCarNames); | ||
|
||
runRace(cars, tryNumber); | ||
|
||
Cars winners = | ||
cars.determineWinners(); | ||
ResultView.printWinners(winners); | ||
} | ||
|
||
private static Cars createCars(List<String> carNames) { | ||
Cars cars = new Cars(); | ||
|
||
for (String carName : carNames) { | ||
cars.addCars(new Car(0, carName)); | ||
} | ||
|
||
return cars; | ||
} | ||
|
||
private static void runRace(Cars cars, int tryNumber) { | ||
ResultView.printStartMessage(); | ||
for (int i = 0; i < tryNumber; i++) { | ||
moveAllCars(cars); | ||
|
||
int roundNumber = i + 1; | ||
ResultView.printRoundResult(roundNumber, cars); | ||
} | ||
} | ||
|
||
private static void moveAllCars(Cars cars) { | ||
RacingHelper racingHelper = new RacingHelper(); | ||
|
||
for (Car car : cars.getCarList()) { | ||
car.move(racingHelper.shouldMove()); | ||
} | ||
RacingService.startRacingGame(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.racing.service; | ||
|
||
import com.racing.domain.Car; | ||
import com.racing.domain.Cars; | ||
import com.racing.ui.InputView; | ||
import com.racing.ui.ResultView; | ||
import com.racing.utils.CarHelper; | ||
import com.racing.utils.RacingHelper; | ||
|
||
import java.util.List; | ||
|
||
public class RacingService { | ||
public static void startRacingGame() { | ||
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. startRacingGame์์ input๊น์ง ๋ค ํ๊ธฐ๋ณด๋ค๋ input์ ๋ฏธ๋ฆฌ ๋ฐ์ ๋ค dto ๋ฑ์ผ๋ก ๋๊ธฐ๋ฉด ์กฐ๊ธ ๋ ๊น๋ํ๊ฒ ๊ตฌํํ ์ ์์ ๊ฒ ๊ฐ๋ค์. |
||
String carNames = InputView.getCarName(); | ||
int tryNumber = InputView.getTryNumber(); | ||
|
||
List<String> validCarNames = CarHelper.splitCarName(carNames); | ||
|
||
Cars cars = initializeRacingCars(validCarNames); | ||
|
||
executeRaceRounds(cars, tryNumber); | ||
|
||
Cars winners = | ||
cars.determineWinners(); | ||
ResultView.printWinners(winners); | ||
} | ||
|
||
private static Cars initializeRacingCars(List<String> carNames) { | ||
Cars cars = new Cars(); | ||
|
||
for (String carName : carNames) { | ||
cars.addCars(new Car(0, carName)); | ||
} | ||
|
||
return cars; | ||
} | ||
|
||
private static void executeRaceRounds(Cars cars, int tryNumber) { | ||
ResultView.printStartMessage(); | ||
for (int i = 0; i < tryNumber; i++) { | ||
advanceAllCars(cars); | ||
|
||
int roundNumber = i + 1; | ||
ResultView.printRoundResult(roundNumber, cars); | ||
} | ||
} | ||
|
||
private static void advanceAllCars(Cars cars) { | ||
RacingHelper racingHelper = new RacingHelper(); | ||
|
||
for (Car car : cars.getCarList()) { | ||
car.move(racingHelper.shouldMove()); | ||
} | ||
} | ||
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. startRacingGame์์ ์ง์ input์ ์ํํ์ง ์๊ณ Main(ํน์ ๋ค๋ฅธ ํด๋์ค)์์ input์ ์ํํ ๋ค์ dto๋ก ๋ณด๋ธ๋ค๋ฉด ์ด๋จ๊น์? startRacingGame ์์ฒด ํ ์คํธ๊ฐ ์ง๊ธ์ ๋ถ๊ฐ๋ฅํ๋ฐ ๊ฐ๋ฅํด์ง ์ ์์ต๋๋ค. ํ์ง๋ง ์์ง ๊ฑธ๋ฆผ๋์ด ํ๋ ์๋๋ฐ advanceAllCars ์์ ์ง์ ์ ์ผ๋ก
|
||
} |
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.
์ด๋ฒ์ Main์ ์ฑ ์์ ์ผ๋ถ ๋ถ๋ฆฌํด๋ณด๋๊ฑด ์ด๋จ๊น์?
Main์์๋ ๋ก์ง์ ์์ํ๋ ์ ๋์ ์ฑ ์๋ง ๊ฐ์ง๋๊ฒ ๋ ์ ์ ํฉ๋๋ค.
๊ทธ ์์ฒด๋ก๋ ์ง์ ์ ์ญํ ์ ํ๊ณ ์๊ฑฐ๋ ์.
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.
9a3199f
๋ฉ์ธ ์ง์ ์ ์ ๋ถ๋ฆฌํ์ต๋๋ค!