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

๐Ÿš€ 5๋‹จ๊ณ„ - ์ž๋™์ฐจ ๊ฒฝ์ฃผ(๋ฆฌํŒฉํ† ๋ง) #5818

Open
wants to merge 32 commits into
base: jonghyeonleee
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e66ce53
refactor: state๋ฅผ position์œผ๋กœ ๋ณ€๊ฒฝ
Oct 15, 2024
065e71c
refactor: random ์ธํ„ฐํŽ˜์ด์Šค์— ๋Œ€ํ•œ ๋ช…์นญ์„ ์ถ”์ƒ์ ์œผ๋กœ ๋ณ€๊ฒฝ
Oct 15, 2024
90057c1
feat: Cars ์ผ๊ธ‰ ์ฝœ๋ž™์…˜ ๊ตฌํ˜„
Oct 15, 2024
d905f4a
refactor: ์ฝ”๋“œ ์ •๋ฆฌ
Oct 15, 2024
9d3b593
refactor: Random์„ controller ๋‹จ์—์„œ ์ œ์–ดํ•˜๋„๋ก ์ˆ˜์ •
Oct 15, 2024
99749ca
refactor: ์™ธ๋ถ€์—์„œ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฐ’์˜ ์ ‘๊ทผ ์ œ์–ด์ž ๋ณ€๊ฒฝ
Oct 15, 2024
f6053fa
refactor: ๊ฐ„์ ‘ ํ…Œ์ŠคํŠธ ์ œ๊ฑฐ
Oct 15, 2024
8d16b5f
feat: position ๊ตฌํ˜„
Oct 15, 2024
516281d
feat: position ์ƒ์„ฑ์ž ์ถ”๊ฐ€ ๊ตฌํ˜„
Oct 15, 2024
1332ebf
feat: postion add, get ํ•จ์ˆ˜ ๊ตฌํ˜„
Oct 15, 2024
f0c3b6a
refator: ํ”„๋ฆฌ๋ฏธํ‹ฐ๋ธŒ ํƒ€์ž…์˜ position์„ ๊ฐ์ฒด๋กœ ๋ณ€๊ฒฝ
Oct 15, 2024
ed49ad8
refactor: ๋Œ€์‹œ๋ฅผ ๋ฐ˜ํ™˜ํ•  ๋•Œ position ๊ฐ์ฒด์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ๊ธฐ๋Šฅ ์ˆ˜์ •
Oct 15, 2024
2591e7f
feat: ํฐ ๊ฐ’์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ ๊ตฌํ˜„ ๋ฐ car ๋ฉ”์„œ๋“œ ๋Œ€์ฒด
Oct 15, 2024
2a99564
refator: ๊ฐ„์ ‘ ํ…Œ์ŠคํŠธ ์ œ๊ฑฐ
Oct 15, 2024
c01dacd
refactor: ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ฝ”๋“œ ์ œ๊ฑฐ
Oct 15, 2024
ff2a4e7
refactor: cars ์ผ๊ธ‰ ์ฝœ๋ž™์…˜์— car ๊ฐ์ฒด๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ์ฝ”๋“œ ๊ตฌํ˜„
Oct 15, 2024
8533d99
refactor: List๋กœ ์„ ์–ธ๋œ ํŒŒ๋ผ๋ฏธํ„ฐ, ๋ฐ˜ํ™˜ ๊ฐ’์„ Cars๋กœ ๋ณ€๊ฒฝ
Oct 15, 2024
e386be1
refactor: cars ๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰
Oct 15, 2024
4fd6712
feat: carName ๊ฐ์ฒด ๊ตฌํ˜„
Oct 15, 2024
7651e0c
refactor: String ํ”„๋ฆฌ๋ฏธํ‹ฐ๋ธŒ ํƒ€์ž…์—์„œ CarName ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์ˆ˜์ •
Oct 15, 2024
094b6be
refactor: cars์—์„œ maxposition์„ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰
Oct 15, 2024
0bee42d
refactor: Cars ๊ฐ์ฒด ๋‚ด๋ถ€์—์„œ ์šฐ์Šน์ž๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๋ฆฌํŒฉํ† ๋ง
Oct 15, 2024
8e94225
refactor: carSize๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋งค์„œ๋“œ ๊ตฌํ˜„
Oct 15, 2024
1643450
refactor: resultview์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ Cars ํด๋ž˜์Šค ๋‚ด๋ถ€์—์„œ ๊ตฌํ˜„ํ•˜์—ฌ ํ…Œ์ŠคํŠธ ํ•˜๋„๋ก ์ˆ˜์ •
Oct 15, 2024
9a3199f
refactor: ๋ฉ”์ธ ํ•จ์ˆ˜๋Š” ์‹œ์ž‘์  ์—ญํ• ๋งŒ ํ•˜๊ณ  ์‹ค์ œ ์„œ๋น„์Šค(์ปจํŠธ๋กค)๋Š” ๋ถ„๋ฆฌ, ํ•จ์ˆ˜๋ช…์„ ๋ช…ํ™•ํ•˜๊ฒŒ ์ˆ˜์ •
Oct 22, 2024
16ee9f8
refactor: sout์„ view ๋‹จ์œผ๋กœ ๋ถ„๋ฆฌ, ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ œ๊ฑฐ
Oct 22, 2024
be64fc4
refactor: carlist -> caritems๋กœ ๋„ค์ด๋ฐ ์ˆ˜์ •, ์ผ๊ธ‰ ๊ฐ์ฒด์˜ item์„ private๋กœ ์„ ์–ธ
Oct 22, 2024
13b1a3c
refactor: ๋ฐฉ์–ด์  ๋ณต์‚ฌ ๊ธฐ๋ฒ• ์‚ฌ์šฉํ•˜์—ฌ get์œผ๋กœ ๋ฆฌํ„ด๋ฐ›์€ ๊ฐ’์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋„๋ก ์ˆ˜์ •
Oct 22, 2024
0c567b0
refactor: ๊ฐ„์ ‘ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ตํ•œ private ํ•จ์ˆ˜ ํ…Œ์ŠคํŠธ, ๊ธฐ์กด ํ…Œ์ŠคํŠธ ์ œ๊ฑฐ
Oct 22, 2024
8e329e8
fix: ํ…Œ์ŠคํŠธ ์˜ค๋ฅ˜ ์ˆ˜์ •
Oct 22, 2024
81149cf
refactor: ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ๊ตฌ์ฒด์ ์ธ ๋‚ด์šฉ์„ ๋ฐฉํ–ฅ์„ฑ์„ ๋‚˜ํƒ€๋‚ด๋„๋ก ๋ณ€๊ฒฝ
Oct 22, 2024
47bdbbc
refactor: ์ž๋™์ฐจ ์›€์ง์ž„์— ํ•ด๋‹นํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ํ‘œํ˜„
Oct 22, 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
50 changes: 2 additions & 48 deletions src/main/java/com/racing/Main.java
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 {
Copy link
Member

Choose a reason for hiding this comment

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

์ด๋ฒˆ์—” Main์˜ ์ฑ…์ž„์„ ์ผ๋ถ€ ๋ถ„๋ฆฌํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
Main์—์„œ๋Š” ๋กœ์ง์„ ์‹œ์ž‘ํ•˜๋Š” ์ •๋„์˜ ์ฑ…์ž„๋งŒ ๊ฐ€์ง€๋Š”๊ฒŒ ๋” ์ ์ ˆํ•ฉ๋‹ˆ๋‹ค.
๊ทธ ์ž์ฒด๋กœ๋„ ์ง„์ž…์  ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ๊ฑฐ๋“ ์š”.

Copy link
Author

Choose a reason for hiding this comment

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

9a3199f

๋ฉ”์ธ ์ง„์ž…์ ์„ ๋ถ„๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค!

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();
}
}
55 changes: 55 additions & 0 deletions src/main/java/com/racing/service/RacingService.java
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() {
Copy link
Member

Choose a reason for hiding this comment

The 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());
}
}
Copy link
Member

Choose a reason for hiding this comment

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

startRacingGame์—์„œ ์ง์ ‘ input์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๊ณ  Main(ํ˜น์€ ๋‹ค๋ฅธ ํด๋ž˜์Šค)์—์„œ input์„ ์ˆ˜ํ–‰ํ•œ ๋‹ค์Œ dto๋กœ ๋ณด๋‚ธ๋‹ค๋ฉด ์–ด๋–จ๊นŒ์š”?

startRacingGame ์ž์ฒด ํ…Œ์ŠคํŠธ๊ฐ€ ์ง€๊ธˆ์€ ๋ถˆ๊ฐ€๋Šฅํ•œ๋ฐ ๊ฐ€๋Šฅํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์•„์ง ๊ฑธ๋ฆผ๋Œ์ด ํ•˜๋‚˜ ์žˆ๋Š”๋ฐ advanceAllCars ์—์„œ ์ง์ ‘์ ์œผ๋กœ Random ๋กœ์ง์— ์˜์กดํ•˜๊ณ  ์žˆ์–ด์š”.
DM์œผ๋กœ ๋ง์”€๋“œ๋ ธ๋“ฏ ์—ฌ๊ธฐ์„œ ์ด๋ ‡๊ฒŒ ์ง์ ‘ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— startRacingGame ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•ด ์ง€๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

RacingService ์˜ ํ•„๋“œ๋กœ Strategy๋ฅผ ๊ฐ€์ ธ๊ฐ€๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์œผ๋‹ˆ ํ•œ ๋ฒˆ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”.

}