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๋‹จ๊ณ„ - ์ž๋™์ฐจ ๊ฒฝ์ฃผ(์šฐ์Šน์ž) - ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ˆ˜์ • #5807

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
bb020a6
Step1 (#5615)
yunji1201 Sep 26, 2024
cdfb759
2๋‹จ๊ณ„ - ๋ฌธ์ž์—ด ๋ง์…ˆ ๊ณ„์‚ฐ๊ธฐ (#5715)
yunji1201 Oct 2, 2024
e06edf2
3๋‹จ๊ณ„ - ์ž๋™์ฐจ ๊ฒฝ์ฃผ (#5736)
yunji1201 Oct 5, 2024
3945b00
refactor : ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋ฆฌํŒฉํ† ๋ง ์ž‘์—…
yunji1201 Oct 7, 2024
0dc8a6b
refactor : ๋„๋ฉ”์ธ(Racing)์ด view(ResultView)์— ์˜์กดํ•˜์ง€ ์•Š๋„๋ก ๊ตฌ์กฐ ๋ณ€๊ฒฝ
yunji1201 Oct 7, 2024
d80b43b
docs : 4๋‹จ๊ณ„ ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ ์ •๋ฆฌ
yunji1201 Oct 9, 2024
ea596ee
test : ์ž๋™์ฐจ ์ด๋ฆ„์ด 5๊ธ€์ž ์ด์ƒ์ธ ๊ฒฝ์šฐ ์—๋Ÿฌ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” ํ…Œ์ŠคํŠธ
yunji1201 Oct 9, 2024
29fff60
feat : ์‚ฌ์šฉ์ž๊ฐ€ ์ž๋™์ฐจ์˜ ์ด๋ฆ„์„ ์ž…๋ ฅ ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ
yunji1201 Oct 9, 2024
badbbec
feat : ์ „์ง„ํ•˜๋Š” ์ž๋™์ฐจ๋ฅผ ์ถœ๋ ฅํ•  ๋•Œ ์ด๋ฆ„์„ ๊ฐ™์ด ์ถœ๋ ฅ
yunji1201 Oct 9, 2024
d986739
test : ๊ฐ€์žฅ ๋งŽ์€ ๊ฑฐ๋ฆฌ๋ฅผ ๊ฐ„ ์ž๋™์ฐจ๋ฅผ ์šฐ์Šน์ž๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” ํ…Œ์ŠคํŠธ ์ง„ํ–‰
yunji1201 Oct 9, 2024
0e5005e
feat : ๋ ˆ์ด์‹ฑ ์™„๋ฃŒ ํ›„ ์šฐ์Šน์ž๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๊ธฐ๋Šฅ ์ถ”๊ฐ€
yunji1201 Oct 9, 2024
13a7434
test : Racing ํด๋ž˜์Šค์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
yunji1201 Oct 9, 2024
f181330
refactor : ๊ฐ ๋„๋ฉ”์ธ์— ๋งž๊ฒŒ ํ…Œ์ŠคํŠธ ๋ถ„๋ฆฌ
yunji1201 Oct 9, 2024
68499a7
refactor : ์ฝ”๋“œ๋ฆฌ๋ทฐ ๋ฐ›์€๊ฑธ ๋ฐ”ํƒ•์œผ๋กœ ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰
yunji1201 Oct 9, 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
Prev Previous commit
Next Next commit
3๋‹จ๊ณ„ - ์ž๋™์ฐจ ๊ฒฝ์ฃผ (#5736)
* docs : ๊ธฐ๋Šฅ ๋ถ„์„ ํ›„ todo.md ์—…๋ฐ์ดํŠธ

* test : 0์—์„œ 9 ์‚ฌ์ด์—์„œ ๊ฐ’์ด 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ์—๋งŒ ์ „์ง„ํ•˜๊ณ  4 ์ดํ•˜์ผ ๊ฒฝ์šฐ ๋ฉˆ์ถฐ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ํ…Œ์ŠคํŠธ

* feat : ์‚ฌ์šฉ์ž๊ฐ€ ์ž๋™์ž ์ˆ˜, ์ด๋™ ์ˆ˜๋ฅผ ์ž…๋ ฅ ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ

* test : 0์—์„œ 9 ์‚ฌ์ด์—์„œ random ๊ฐ’์„ ๊ตฌํ•œ ํ›„ random ๊ฐ’์ด 4์ด์ƒ์ผ ๊ฒฝ์šฐ์—๋งŒ ์ „์ง„ํ•˜๋Š” ํ…Œ์ŠคํŠธ

* feat : ์ž๋™์ฐจ๊ฐ€ ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๊ฐ’์— ๋”ฐ๋ผ ๊ฒฝ๊ธฐ๋ฅผ ์ง„ํ–‰ํ•˜๊ณ  ์›€์ง์ด๋„๋ก ๊ธฐ๋Šฅ ์ถ”๊ฐ€

* feat : ์ž๋™์ฐจ์˜ ์ƒํƒœ๋ฅผ ํ™”๋ฉด์— ์ถœ๋ ฅ

* refactor : ์ค‘๋ณต๋œ ๋‚ด์šฉ์˜ ํ…Œ์ŠคํŠธ ๋ฉ”์†Œ๋“œ ์ œ๊ฑฐ

* refactor : ์ถ•์•ฝ๋œ ๋ฉ”์†Œ๋“œ๋ช…, ๋ณ€์ˆ˜๋ช… ๋ช…ํ™•ํ•œ ์˜๋ฏธ๋ฅผ ๊ฐ–๋„๋ก ์ˆ˜์ •

* refactor : private ์ƒ์„ฑ์ž๋กœ ๋ถˆํ•„์š”ํ•œ ์ธ์Šคํ„ด์Šคํ™” ๋ง‰๊ธฐ

* refactor : for๋ฌธ -> repeat ํ•จ์ˆ˜ ์‚ฌ์šฉ

* refactor : ์ฒซ๋ฒˆ์งธ ๋ผ์šด๋“œ์—์„œ ์ž๋™์ฐจ๊ฐ€ ๋ฐ˜๋“œ์‹œ ์ „์ง„ํ•˜์ง€ ์•Š์•„๋„ ๋˜๋„๋ก ์ฝ”๋“œ ์ˆ˜์ •

* refactor : ๋ ˆ์ด์‹ฑ ๋ผ์šด๋“œ ์‹œ์ž‘ ํ‘œ์‹œ ์ฝ˜์†”์„ VIEW์—์„œ ํ•˜๋„๋ก ์ˆ˜์ •

* refactor : ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๊ณผ UI ๋กœ์ง์„ ๋ถ„๋ฆฌํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ์˜์กด์„ฑ ์ฃผ์ž…์„ ์‚ฌ์šฉํ•œ๋‹ค
yunji1201 authored Oct 5, 2024
commit e06edf283def1db553d84b024a88dc79dbb5ed84
23 changes: 23 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### TODO

1. [x] ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ •๋ฆฌํ•ด ์ถ”๊ฐ€
2. [x] ์ž๋™์ž ์ˆ˜, ์ด๋™ ์ˆ˜ ์ž…๋ ฅ ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ
3. [x] ์ „์ง„ํ•˜๋Š” ์กฐ๊ฑด์€ 0์—์„œ 9 ์‚ฌ์ด์—์„œ random ๊ฐ’์„ ๊ตฌํ•œ ํ›„ random ๊ฐ’์ด 4์ด์ƒ์ผ ๊ฒฝ์šฐ
4. [x] ๋ชจ๋“  ์ž๋™์ฐจ๊ฐ€ ์ด๋™์„ ์™„๋ฃŒํ•˜๋ฉด ์ข…๋ฃŒ
5. [x] ์ž๋™์ฐจ์˜ ์ƒํƒœ๋ฅผ ํ™”๋ฉด์— ์ถœ๋ ฅ

- ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๋Š” API๋Š” Scanner๋ฅผ ์ด์šฉ
- ๋žœ๋ค ๊ฐ’์€ ์ž๋ฐ” java.util.Random ํด๋ž˜์Šค์˜ nextInt(10) ๋ฉ”์†Œ๋“œ๋ฅผ ํ™œ์šฉ
- else ์˜ˆ์•ฝ์–ด๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค
- ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— README.md ํŒŒ์ผ์— ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ •๋ฆฌํ•ด ์ถ”๊ฐ€
- git์˜ commit ๋‹จ์œ„๋Š” ์•ž ๋‹จ๊ณ„์—์„œ README.md ํŒŒ์ผ์— ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก ๋‹จ์œ„๋กœ ์ถ”๊ฐ€

### AngularJS Commit Message Conventions

* feat (feature)
* fix (bug fix)
* docs (documentation)
* style (formatting, missing semi colons, โ€ฆ)
* refactor
* test (when adding missing tests)
* chore (maintain)
19 changes: 19 additions & 0 deletions src/main/java/racingcar/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package racingcar;

public class Car {

public static final int MOVE_CONDITION = 4;
private int currentPosition;

public int moveCar(int randomNumber) {
if (randomNumber >= MOVE_CONDITION) {
currentPosition++;
}
return currentPosition;
}

public int getCurrentPosition() {
return currentPosition;
}

}
22 changes: 22 additions & 0 deletions src/main/java/racingcar/InputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package racingcar;

import java.util.Scanner;

public class InputView {

private static final Scanner SCANNER = new Scanner(System.in);

private InputView() {

}

public static int getCarNumber() {
System.out.println("์ž๋™์ฐจ ๊ฐœ์ˆ˜๋Š” ๋ช‡ ๊ฐœ ์ธ๊ฐ€์š”?");
return SCANNER.nextInt();
}

public static int getRoundNumber() {
System.out.println("์‹œ๋„ ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ๋ฒˆ ์ธ๊ฐ€์š”?");
return SCANNER.nextInt();
}
}
34 changes: 34 additions & 0 deletions src/main/java/racingcar/Racing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package racingcar;

import java.util.List;
import java.util.Random;

public class Racing {

private static final Random RANDOM = new Random();

private final List<Car> cars;
private final int roundNum;
private final ResultView resultView;

public Racing(List<Car> cars, int roundNum, ResultView resultView) {
this.cars = cars;
this.roundNum = roundNum;
this.resultView = resultView;
}

public void start() {
for (int i = 0; i < roundNum; i++) {
resultView.roundStart(i + 1);
play();
}
}

private void play() {
for (Car car : cars) {
int position = car.moveCar(RANDOM.nextInt(10));
resultView.drawCarPosition(position);
}
}

}
22 changes: 22 additions & 0 deletions src/main/java/racingcar/RacingCarMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package racingcar;

import java.util.ArrayList;
import java.util.List;

public class RacingCarMain {

public static void main(String[] args) {
int carNum = InputView.getCarNumber();
int roundNum = InputView.getRoundNumber();

List<Car> cars = new ArrayList<>();
for (int i = 0; i < carNum; i++) {
cars.add(new Car());
}

ResultView resultView = new ResultView();
Racing racing = new Racing(cars, roundNum, resultView);
racing.start();
}

}
19 changes: 19 additions & 0 deletions src/main/java/racingcar/ResultView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package racingcar;

import java.util.Scanner;

public class ResultView {

private static final Scanner scanner = new Scanner(System.in);
public static final String LINE = "-".repeat(5);

public static void roundStart(int roundNumber) {
System.out.println(LINE + roundNumber + " ๋ผ์šด๋“œ ์‹œ์ž‘!" + LINE);
}

public static void drawCarPosition(int position) {
StringBuilder sb = new StringBuilder();
sb.append("-".repeat(position));
System.out.println(sb.toString());
}
}
34 changes: 34 additions & 0 deletions src/test/java/racingcar/RacingCarTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package racingcar;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Random;
import java.util.stream.IntStream;

import static org.assertj.core.api.Assertions.assertThat;

public class RacingCarTest {

@ParameterizedTest
@MethodSource("randomNum")
@DisplayName("์ž๋™์ฐจ๊ฐ€ ์ด๋™ํ•˜๋Š” ๊ฐ’์ด 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ์—๋งŒ ์ „์ง„ํ•˜๊ณ  ๊ทธ๋ ‡์ง€์•Š์œผ๋ฉด ๋ฉˆ์ถฐ์žˆ๋Š”์ง€ ํ™•์ธ")
void carMovesOrStopsByRandomNum(int num) {
Car car = new Car();
car.moveCar(num);

System.out.println("num :: " + num);
if (num >= 4) {
assertThat(car.getCurrentPosition()).isEqualTo(1);
return;
}
assertThat(car.getCurrentPosition()).isEqualTo(0);
}

static IntStream randomNum() {
Random random = new Random();
return IntStream.generate(() -> random.nextInt(10)).limit(1);
}
}