-
Notifications
You must be signed in to change notification settings - Fork 452
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
[디디] 레이싱게임 리뷰요청 드립니다. #86
Changes from 1 commit
c993438
13da028
9a2da16
78fb041
b1c8abc
963e17a
8477099
dc3016c
dfe2f5d
ef0d1e2
128f1a7
de18aea
1e5178e
ad00e5a
673f887
58eb502
ab8154e
2c80e2d
8f2c39e
64c1f48
f133dd5
1017249
e672def
154d381
5728858
0d2db11
16ca493
062f133
316334d
6b35e41
0141793
a615c2d
4fe2c6d
6d3910e
a96232c
0065e52
9c23b44
866bc51
96cad54
6ae1619
83093f1
06b8a34
de7cb6c
147a221
9619d06
f7891c9
722f72a
6d62621
7a8676f
9637bf0
5fe8b2e
8602a96
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 |
---|---|---|
|
@@ -11,6 +11,10 @@ public Cars(Names names) { | |
cars = names.makeCars(); | ||
} | ||
|
||
public Cars(List<Car> cars){ | ||
this.cars = cars; | ||
} | ||
|
||
public Winners makeWinners(int maxPosition) { | ||
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. 외부로 부터 maxPosition을 받아오지말고 아래처럼 내부에 있는 Car list를 통해 maxPosition을 구해도 되지 않을까요?
|
||
List<Car> winners = new ArrayList<>(); | ||
|
||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package racinggame.domain; | ||
|
||
public class MoveGenerator implements Strategy { | ||
public int generateRandom() { | ||
return 5; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package racinggame.domain; | ||
|
||
import java.util.Random; | ||
|
||
public class RacingGame implements Strategy { | ||
public class RacingGame { | ||
public static final int NUMBER_BOUND = 10; | ||
private Cars cars; | ||
|
||
public static int generateRandom() { | ||
Random rand = new Random(); | ||
rand.setSeed(System.nanoTime()); | ||
return rand.nextInt(NUMBER_BOUND); | ||
public RacingGame(Cars cars) { | ||
this.cars = cars; | ||
} | ||
|
||
public int moveCars(Cars cars, int maxPosition) { | ||
public int moveCars(Strategy randomGenerator) { | ||
int maxPosition = 0; | ||
for (Car car : cars) { | ||
if (car.move(generateRandom())) { | ||
if (car.move(randomGenerator)) { | ||
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. randomGenerator에 전략패턴을 사용했군요! 👍 |
||
maxPosition = car.getMaxPosition(maxPosition); | ||
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. 음... 매번 움직일때 마다 MaxPosition을 선정 해 줄 필요가 있을까요? |
||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package racinggame.domain; | ||
|
||
import java.util.Random; | ||
|
||
import static racinggame.domain.RacingGame.NUMBER_BOUND; | ||
|
||
public class RandomGenerator implements Strategy { | ||
|
||
public int generateRandom() { | ||
Random rand = new Random(); | ||
rand.setSeed(System.nanoTime()); | ||
return rand.nextInt(NUMBER_BOUND); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package racinggame.domain; | ||
|
||
public class StopGenerator implements Strategy { | ||
public int generateRandom() { | ||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package racinggame.domain; | ||
|
||
public interface Strategy { | ||
int moveCars(Cars cars, int maxPosition); | ||
int generateRandom(); | ||
} |
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.
이 부분에 전략패턴을 적용 해 보세요!