-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๊ธฐ๋ฌผ ํ์ฅ + DB ์ ์ฉ)] ๋ผ์ด ๋ฏธ์ ์ ์ถํฉ๋๋ค. #339
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
Changes from all commits
af7c379
e1eed41
0bdb3eb
b760bd2
7876dd6
8da12f5
9d90197
1b6fe6f
4a7fdc8
f8650f5
08e3241
6282079
251dccd
7fbd579
c835063
27eeaf8
302e2f4
94d60a2
3fe4d68
2bc5da1
a0c0a6d
144bf64
7533475
befc84f
b1ac0fb
685d374
d49e98f
0ff363c
8582e27
2a74c5e
1df6ec2
721049a
a1dfd6f
7d81530
fb4770a
3644ecd
d3fefd9
9117b0e
2b41da5
fc2bbd9
22d50c9
ab668cd
de79898
9277514
2021542
35377ee
14863b8
ecaa1a2
d9d96f5
e96778d
b21e8d7
f5aded6
4d6eb29
179241b
78fb80f
9091b22
944b092
6af0144
c2e041d
acef1fb
954f4f7
c5d3dae
a02b19b
4241395
0d01995
e37b843
99dcbd3
9d657f6
8a6d117
b9074a0
0062494
e83e2b9
8deb26b
a78d9db
332e529
37287a7
77c0599
40022e4
63e0e94
fbee38a
7b15c69
37bac28
b7db144
a65c89d
70060c7
2dd6e73
b2f29c6
225896e
4a6ab76
8b0c10c
eb7366f
6cd93d9
0062b4e
2a448d9
42d5896
1927274
adb296d
9034a38
7c687e6
8c3440c
6ad3d70
20dc50d
cab0746
c5955f0
6cb5762
2b74d1b
fc798c9
17df4d0
6912d59
2c08edd
69ad2f9
02bede2
b03e3db
c0d6d75
1752d36
9b73dfa
c701936
ce4d7ea
20ca9a6
38984a9
3e21c72
2d3e117
bf401fd
a33ab99
d7659e7
95683bd
377c95a
ea20693
419f077
9f9ed4d
e6dc70c
3d805ac
64f22ec
ed32917
914eed2
3f1d790
2ae4204
b0e4c54
e57de48
9f2f437
cecfeab
3e3a854
2877d0c
bca207b
745cdb0
abe7d2c
2d5897b
7efffe8
3d48adb
52866b9
eb57775
3446bf3
3bf2bba
cd54176
16d36bd
61ba532
071226b
2da1644
49407fe
d65acd8
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 |
|---|---|---|
|
|
@@ -30,3 +30,6 @@ out/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
|
|
||
| .DS_Store | ||
| **/.DS_Store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,12 @@ | ||
| package janggi; | ||
|
|
||
| import janggi.view.InputView; | ||
| import janggi.view.OutputView; | ||
| import janggi.config.AppConfig; | ||
|
|
||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| InputView inputView = new InputView(); | ||
| OutputView outputView = new OutputView(); | ||
| JanggiGame janggiGame = new JanggiGame(outputView, inputView); | ||
| janggiGame.run(); | ||
| inputView.close(); | ||
| AppConfig appConfig = new AppConfig(); | ||
| GameRunner gameRunner = appConfig.gameRunner(); | ||
| gameRunner.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package janggi; | ||
|
|
||
| import janggi.domain.board.Board; | ||
| import janggi.domain.game.Players; | ||
| import janggi.domain.game.PlayersSaveDTO; | ||
| import janggi.domain.game.Side; | ||
| import janggi.domain.repository.JanggiRepository; | ||
| import janggi.view.InputView; | ||
| import janggi.view.OutputView; | ||
| import java.util.Optional; | ||
| import java.util.function.Supplier; | ||
|
|
||
| public class GameRunner { | ||
| private final OutputView outputView; | ||
| private final InputView inputView; | ||
| private final JanggiRepository repository; | ||
|
|
||
| public GameRunner(OutputView outputView, InputView inputView, JanggiRepository repository) { | ||
| this.outputView = outputView; | ||
| this.inputView = inputView; | ||
| this.repository = repository; | ||
| } | ||
|
|
||
| public void run() { | ||
| Optional<Long> lastGameId = repository.findInProgressGameId(); | ||
|
|
||
| if (lastGameId.isPresent() && isContinued()) { | ||
| continuallyPlay(lastGameId.get()); | ||
| return; | ||
| } | ||
|
|
||
| startNewGame(); | ||
| inputView.close(); | ||
| } | ||
|
|
||
| private void startNewGame() { | ||
| Players players = initialPlayers(); | ||
| Long gameId = repository.save(PlayersSaveDTO.from(players)); | ||
| Board board = Board.initialize(); | ||
|
|
||
| new JanggiGame(outputView, inputView, repository, board, gameId).play(players); | ||
| } | ||
|
|
||
| private void continuallyPlay(Long id) { | ||
| Board board = repository.findBoardById(id); | ||
| Players players = repository.findPlayersById(id); | ||
|
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. ํ ํด์์ ๊ฒ์์ ์ข ๋ฃํด๋, ๋ฌด์กฐ๊ฑด ์ด ํด์ผ๋ก ์์๋๋ ๋ฒ๊ทธ๊ฐ ์๋ค์. ํด๋น ์ผ์ด์ค๋ ํ ์คํธ๋ก ์ปค๋ฒ๊ฐ ๋๊ณ ์๋์? 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. JanggiRepository์
Author
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.
|
||
| outputView.printResumeNotice(); | ||
|
|
||
| new JanggiGame(outputView, inputView, repository, board, id).play(players); | ||
| } | ||
|
|
||
| private Players initialPlayers() { | ||
| return retry(() -> { | ||
| String choPlayerName = readPlayerName(Side.CHO); | ||
| String hanPlayerName = readPlayerName(Side.HAN); | ||
| return Players.createInitial(choPlayerName, hanPlayerName); | ||
| }); | ||
| } | ||
|
|
||
| private String readPlayerName(Side side) { | ||
| outputView.printPlayerNameNotice(side.getDisplayName()); | ||
| return inputView.readPlayerName(); | ||
| } | ||
|
|
||
| private boolean isContinued() { | ||
| return retry(() -> { | ||
| outputView.printContinueGameNotice(); | ||
| return inputView.readContinueAnswer(); | ||
| }); | ||
| } | ||
|
|
||
| private <T> T retry(Supplier<T> supplier) { | ||
| Optional<T> result = Optional.empty(); | ||
| while (result.isEmpty()) { | ||
| result = tryOnce(supplier); | ||
| } | ||
| return result.get(); | ||
| } | ||
|
|
||
| private <T> Optional<T> tryOnce(Supplier<T> supplier) { | ||
| try { | ||
| return Optional.of(supplier.get()); | ||
| } catch (IllegalArgumentException e) { | ||
| outputView.printLine(e.getMessage()); | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.