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

๐Ÿš€ 4๋‹จ๊ณ„ - ์ž๋™์ฐจ ๊ฒฝ์ฃผ(์šฐ์Šน์ž) #6061

Open
wants to merge 7 commits into
base: kjy2844
Choose a base branch
from

Conversation

kjy2844
Copy link

@kjy2844 kjy2844 commented Mar 20, 2025

๊ตฌํ˜„ TODO ๋ชฉ๋ก

  1. ์ž๋™์ฐจ ์ด๋ฆ„ ๊ธฐ๋Šฅ

    • Car ํด๋ž˜์Šค์— ์ด๋ฆ„ ํ•„๋“œ ์ถ”๊ฐ€
    • ์ด๋ฆ„ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ (5์ž ์ดˆ๊ณผ ๋ถˆ๊ฐ€)
    • Car ์ƒ์„ฑ์ž์— ์ด๋ฆ„ ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€
    • CarTest์— ์ด๋ฆ„ ๊ด€๋ จ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
      • ์ด๋ฆ„์ด 5์ž๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ์˜ˆ์™ธ ๋ฐœ์ƒ
      • ์œ ํšจํ•œ ์ด๋ฆ„์œผ๋กœ ์ƒ์„ฑ ๊ฐ€๋Šฅ
  2. ์ž๋™์ฐจ ์ด๋ฆ„ ์ถœ๋ ฅ

    • ResultView ์ˆ˜์ •
      • ์ž๋™์ฐจ ์ด๋ฆ„๊ณผ ์œ„์น˜๋ฅผ ํ•จ๊ป˜ ์ถœ๋ ฅํ•˜๋Š” ํ˜•์‹ ๋ณ€๊ฒฝ
      • presentCars ๋ฉ”์†Œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆ˜์ • (์ด๋ฆ„ ์ •๋ณด ์ถ”๊ฐ€)
    • Race ํด๋ž˜์Šค ์ˆ˜์ •
      • getCarPositions ๋ฉ”์†Œ๋“œ๋ฅผ getCarStatus๋กœ ๋ณ€๊ฒฝ
      • ์ž๋™์ฐจ ์ด๋ฆ„๊ณผ ์œ„์น˜๋ฅผ ํ•จ๊ป˜ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ์ˆ˜์ •
  3. ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ

    • InputView ์ˆ˜์ •
      • ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์†Œ๋“œ ์ถ”๊ฐ€
      • ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„๋œ ์ด๋ฆ„ ๋ฌธ์ž์—ด ํŒŒ์‹ฑ ๋กœ์ง ์ถ”๊ฐ€
    • GameSettings ์ˆ˜์ •
      • ์ž๋™์ฐจ ์ด๋ฆ„ ๋ชฉ๋ก ํ•„๋“œ ์ถ”๊ฐ€
      • ์ƒ์„ฑ์ž ์ˆ˜์ •
  4. ์šฐ์Šน์ž ํŒ์ •

    • Race ํด๋ž˜์Šค์— ์šฐ์Šน์ž ํŒ์ • ๋กœ์ง ์ถ”๊ฐ€
      • getWinners ๋ฉ”์†Œ๋“œ ์ถ”๊ฐ€
      • ๊ฐ€์žฅ ๋ฉ€๋ฆฌ ๊ฐ„ ์ž๋™์ฐจ๋“ค ์ฐพ๊ธฐ
    • ResultView์— ์šฐ์Šน์ž ์ถœ๋ ฅ ๋ฉ”์†Œ๋“œ ์ถ”๊ฐ€
    • Game ํด๋ž˜์Šค ์ˆ˜์ •
      • ๊ฒฝ์ฃผ ์ข…๋ฃŒ ํ›„ ์šฐ์Šน์ž ์ถœ๋ ฅ ๋กœ์ง ์ถ”๊ฐ€

๊ฐœ๋ฐœ ๊ตฌ์กฐ

  • Game: ๊ฒŒ์ž„์˜ ์ „์ฒด ์ƒ๋ช…์ฃผ๊ธฐ ๊ด€๋ฆฌ ๋ฐ ์‚ฌ์šฉ์ž ์ธํ„ฐ๋ž™์…˜ ์กฐ์ •
  • Race: ๊ฒฝ์ฃผ ์ง„ํ–‰ ์ƒํƒœ ๊ด€๋ฆฌ, ์ž๋™์ฐจ ์ด๋™ ์ฒ˜๋ฆฌ, ์šฐ์Šน์ž ํŒ์ •
  • GameSettings: ๊ฒŒ์ž„ ์„ค์ •๊ฐ’(์ž๋™์ฐจ ์ด๋ฆ„, ๋ผ์šด๋“œ ์ˆ˜) ๊ฒ€์ฆ ๋ฐ ๊ด€๋ฆฌ
  • Car: ์ž๋™์ฐจ์˜ ๊ธฐ๋ณธ ์†์„ฑ(์ด๋ฆ„, ์œ„์น˜) ๊ด€๋ฆฌ
  • InputView: ์‚ฌ์šฉ์ž ์ž…๋ ฅ ์ฒ˜๋ฆฌ ๋ฐ ๊ฒ€์ฆ
  • ResultView: ๊ฒŒ์ž„ ์ง„ํ–‰ ์ƒํƒœ ๋ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
  • CarStatus: ์ž๋™์ฐจ์˜ ํ˜„์žฌ ์ƒํƒœ๋ฅผ ๋ถˆ๋ณ€ ๊ฐ์ฒด๋กœ ํ‘œํ˜„
  • MoveStrategy: ์ž๋™์ฐจ ์ด๋™ ์ „๋žต ์ •์˜ (RandomMoveStrategy, FixedMoveStrategy)

kjy2844 added 7 commits March 20, 2025 13:20
   - [x] `Car` ํด๋ž˜์Šค์— ์ด๋ฆ„ ํ•„๋“œ ์ถ”๊ฐ€
   - [x] ์ด๋ฆ„ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ (5์ž ์ดˆ๊ณผ ๋ถˆ๊ฐ€)
   - [x] `Car` ์ƒ์„ฑ์ž์— ์ด๋ฆ„ ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€
   - [x] `CarTest`์— ์ด๋ฆ„ ๊ด€๋ จ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
     - [x] ์ด๋ฆ„์ด 5์ž๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ์˜ˆ์™ธ ๋ฐœ์ƒ
     - [x] ์œ ํšจํ•œ ์ด๋ฆ„์œผ๋กœ ์ƒ์„ฑ ๊ฐ€๋Šฅ
   - [x] `ResultView` ์ˆ˜์ •
     - [x] ์ž๋™์ฐจ ์ด๋ฆ„๊ณผ ์œ„์น˜๋ฅผ ํ•จ๊ป˜ ์ถœ๋ ฅํ•˜๋Š” ํ˜•์‹ ๋ณ€๊ฒฝ
     - [x] `presentCars` ๋ฉ”์†Œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆ˜์ • (์ด๋ฆ„ ์ •๋ณด ์ถ”๊ฐ€)
   - [x] `Race` ํด๋ž˜์Šค ์ˆ˜์ •
     - [x] `getCarPositions` ๋ฉ”์†Œ๋“œ๋ฅผ `getCarStatus`๋กœ ๋ณ€๊ฒฝ
     - [x] ์ž๋™์ฐจ ์ด๋ฆ„๊ณผ ์œ„์น˜๋ฅผ ํ•จ๊ป˜ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ์ˆ˜์ •
   - [x] `InputView` ์ˆ˜์ •
     - [x] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์†Œ๋“œ ์ถ”๊ฐ€
     - [x] ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„๋œ ์ด๋ฆ„ ๋ฌธ์ž์—ด ํŒŒ์‹ฑ ๋กœ์ง ์ถ”๊ฐ€
   - [x] `GameSettings` ์ˆ˜์ •
     - [x] ์ž๋™์ฐจ ์ด๋ฆ„ ๋ชฉ๋ก ํ•„๋“œ ์ถ”๊ฐ€
     - [x] ์ƒ์„ฑ์ž ์ˆ˜์ •
   - [x] `Race` ํด๋ž˜์Šค์— ์šฐ์Šน์ž ํŒ์ • ๋กœ์ง ์ถ”๊ฐ€
     - [x] `getWinners` ๋ฉ”์†Œ๋“œ ์ถ”๊ฐ€
     - [x] ๊ฐ€์žฅ ๋ฉ€๋ฆฌ ๊ฐ„ ์ž๋™์ฐจ๋“ค ์ฐพ๊ธฐ
   - [x] `ResultView`์— ์šฐ์Šน์ž ์ถœ๋ ฅ ๋ฉ”์†Œ๋“œ ์ถ”๊ฐ€
   - [x] `Game` ํด๋ž˜์Šค ์ˆ˜์ •
     - [x] ๊ฒฝ์ฃผ ์ข…๋ฃŒ ํ›„ ์šฐ์Šน์ž ์ถœ๋ ฅ ๋กœ์ง ์ถ”๊ฐ€
Copy link
Member

@Hyeon9mak Hyeon9mak left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” panya ๋‹˜~ 4๋‹จ๊ณ„๋„ ๋น ๋ฅด๊ฒŒ ์ž˜ ์ง„ํ–‰ํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค!
์™„์„ฑ๋„๊ฐ€ ๋†’๊ธฐ ๋•Œ๋ฌธ์— ๋ช‡ ๊ฐ€์ง€ ๊ณ ๋ฏผํ•ด๋ณด์‹ค๋งŒํ•œ ํฌ์ธํŠธ์— ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒผ์Šต๋‹ˆ๋‹ค.
๊ถ๊ธˆํ•˜์‹  ์  ์–ธ์ œ๋“ ์ง€ ํŽธํ•˜๊ฒŒ ์งˆ๋ฌธ์ฃผ์„ธ์š”~

Comment on lines +11 to 17
private void validateName(String name) {
if (name == null || name.trim().isBlank()) {
throw new IllegalArgumentException("Name cannot be blank");
}
if (name.length() > 5) {
throw new IllegalArgumentException("Name cannot be longer than 5 characters");
}
Copy link
Member

Choose a reason for hiding this comment

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

๊ณต๋ฐฑ์— ๋Œ€ํ•œ ๊ฒ€์ฆ์„ ํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด trim() ์€ ์ƒ๋žต ๋˜์–ด๋„ ๊ฐ™์€ ํšจ๊ณผ๊ฐ€ ๋‚˜์˜ฌ๊ฑฐ ๊ฐ™์•„์š” ๐Ÿ˜„

Comment on lines +18 to +22
for (String name : carNames) {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("์ž๋™์ฐจ ์ด๋ฆ„์€ ๋น„์–ด์žˆ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ isBlank() ๋กœ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”!

Comment on lines 3 to +17
public class InputView {

public static final String CAR_NAME_DELIMITER = ",";
private final Scanner scanner;

public InputView() {
this.scanner = new Scanner(System.in);
}

public GameSettings getGameSettings() {
int carCount = promptInt("์ž๋™์ฐจ ๋Œ€์ˆ˜๋Š” ๋ช‡ ๋Œ€ ์ธ๊ฐ€์š”?");
String inputCarNames = prompt("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”(์ด๋ฆ„์€ ์‰ผํ‘œ(,)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„).");
String[] carNames = inputCarNames.split(CAR_NAME_DELIMITER);
int roundCount = promptInt("์‹œ๋„ํ•  ํšŒ์ˆ˜๋Š” ๋ช‡ ํšŒ ์ธ๊ฐ€์š”?");
return new GameSettings(carCount, roundCount);
return new GameSettings(carNames, roundCount);
}
Copy link
Member

Choose a reason for hiding this comment

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

InputView ๋Š” ๋ณ„๋„๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ์ƒํƒœ๋ฅผ ๊ฐ–๊ณ  ์žˆ์ง€ ์•Š๊ณ , ๋ช‡ ๋ฒˆ์˜ ์ž๋™์ฐจ ๊ฒŒ์ž„์—์„œ๋„ ์žฌํ™œ์šฉ์ด ๊ฐ€๋Šฅํ•  ๊ฑธ๋กœ ๋ณด์ด๋Š”๋ฐ์š”,
InputView ์ธ์Šคํ„ด์Šค๋ฅผ ๋งค๋ฒˆ ์ƒ์„ฑํ•  ํ•„์š” ์—†์ด static ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋‹ค๋“ฌ์–ด๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?

Comment on lines +1 to +5
@FunctionalInterface
public interface MoveStrategy {

boolean shouldMove();
}
Copy link
Member

Choose a reason for hiding this comment

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

ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค ์„ ์–ธ ๐Ÿ‘

Comment on lines +64 to +66
private boolean isWinner(Car car, int maxPosition) {
return car.getPosition() == maxPosition;
}
Copy link
Member

Choose a reason for hiding this comment

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

์ž๋™์ฐจ ๊ฐ์ฒด๋กœ๋ถ€ํ„ฐ ๊ฐ’์„ ์ถ”์ถœํ•˜๊ณ  ๋น„๊ตํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์ง€๋งŒ, ๊ฐ’์„ ์ž๋™์ฐจ ๊ฐ์ฒด์—๊ฒŒ ์ „๋‹ฌํ•˜์—ฌ ์›ํ•˜๋Š” ๊ฑธ ๋ฌผ์–ด๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?

๊ฐ์ฒด์—๊ฒŒ ์งˆ๋ฌธํ•˜๋ผ

์ด๋Ÿฐ ์ฝ”๋“œ์—๋Š” ์–ด๋–ค ์žฅ์ ์ด ์ƒ๊ธธ๊นŒ์š”?

Comment on lines +68 to +80
private List<CarStatus> findWinnersWithPosition(int maxPosition) {
List<CarStatus> winners = new ArrayList<>();
for (Car car : cars) {
addWinnerIfQualified(winners, car, maxPosition);
}
return winners;
}

private void addWinnerIfQualified(List<CarStatus> winners, Car car, int maxPosition) {
if (isWinner(car, maxPosition)) {
winners.add(new CarStatus(car));
}
}
Copy link
Member

Choose a reason for hiding this comment

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

ํ˜„์žฌ List<Car> cars ์ปฌ๋ ‰์…˜์—๊ฒŒ ์ปฌ๋ ‰์…˜ ๊ทธ ์ด์ƒ์˜ ์š”๊ตฌ, ๋น„์ฆˆ๋‹ˆ์Šค์ ์ธ ์š”๊ตฌ๊ฐ€ ๋งŽ์•„์ง€๊ณ  ์žˆ์–ด์š”.
์ €๋Š” ์ด ์‹œ์ ์ด ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜์„ ๋„์ž…ํ•˜๊ธฐ ๊ฐ€์žฅ ์ข‹์€ ์‹œ์ ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ์š”,
ํ•œ๋ฒˆ ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜ ๋„์ž…์„ ์‹œ๋„ํ•ด๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”? ๐Ÿ˜‰
https://jojoldu.tistory.com/412

Comment on lines +3 to +6
public class RandomMoveStrategy implements MoveStrategy {

public static final int RANDOM_NUMBER_RANGE = 10;
private static final int MOVE_THRESHOLD = 4;
Copy link
Member

Choose a reason for hiding this comment

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

private ์œผ๋กœ ์ˆจ๊ฒจ์ค˜๋„ ๋˜๊ฒ ๋„ค์š”!
intelliJ ๋ฅผ ์ด์šฉํ•˜์‹ ๋‹ค๋ฉด ์ƒ์ˆ˜์ƒ์„ฑ ๋‹จ์ถ•ํ‚ค๋ฅผ ์—ฐ์† 2ํšŒ ์ž…๋ ฅํ•˜์‹œ๋ฉด ์˜ต์…˜ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants