-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๊ธฐ๋ฌผ ํ์ฅ + DB ์ ์ฉ)] ์ฐ๋ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #274
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
base: armd482
Are you sure you want to change the base?
Changes from all commits
ea8a875
0392115
bce6ed8
bc7846a
0bc4f56
20564a3
0314ed8
89b3f7a
5bebc61
8e63e17
23514d6
200784c
b99a5f2
aa8337e
b0b67d9
54d5e64
e38c5ec
fc60b03
cb946b8
e47ab05
e56bb2e
b8c0b00
346c19b
ef592d6
00ed4b0
2ae0b21
4fdd10b
b42a62c
95941a1
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 |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| - ์์ ์ ์ด/ํ ์ง์์ ๊ธฐ๋ณธ ๊ธฐ๋ฌผ ๋ฐฐ์น์ ๋ง์ ๋ฐฐ์น๋ฅผ ๋ฐ์ํด ์ด๊ธฐํํ๋ค. | ||
| - ์ฅ๊ธฐํ์ ํ์ฌ ์์น์ ๊ธฐ๋ฌผ ์กฐํ, ๋น ์นธ ์ฌ๋ถ, ์๊ตฐ/์ ๊ตฐ ์ฌ๋ถ๋ฅผ ํ๋จํ๋ค. | ||
| - ์ฅ๊ธฐํ์ ๊ธฐ๋ฌผ ์ด๋ ์์ฒญ์ ๋ฐ์ ์ค์ ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ค. | ||
| - ์ฅ๊ธฐํ์ ์๋ ๊ธฐ๋ฌผ์ ์ก์์ ๋ ํด๋น ์ง์์ ์ ์๋ฅผ ์ค์๊ฐ์ผ๋ก ์ฐจ๊ฐํ๋ค. | ||
| - ์ฅ๊ธฐํ์ ์ด๋ ํ ์ง์์ ๊ถ์ด ์กํ๋ฉด ์ฆ์ ๊ฒ์ ์ข ๋ฃ ์ํ๋ก ๋ณ๊ฒฝํ๋ค. | ||
|
|
||
| ### ๊ธฐ๋ฌผ | ||
| - ๊ธฐ๋ฌผ์ ์ข ๋ฅ์ ์ง์ ์ ๋ณด๋ฅผ ๊ฐ์ง๋ค. | ||
|
|
@@ -23,20 +25,27 @@ | |
| - ์ขํ๋ ์ ๋ ฅ๊ฐ์ ๊ฒ์ฆํ์ฌ ์์ฑํ๋ค. | ||
|
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.
๋น์ฐํ ์ด๋ ํ ์ ๋ต์ ์๋๊ฒ ์๋๊ธฐ์ ์ ์ ๊ธฐ์ค์ ์๊ธฐํ ๊ฒ์. ์ ๋ ํ์์ ์ํด ์ฐ๋ ๊ฒ ๊ฐ์์. ์๋ฌด๋๋ view์ ๋ณ๊ฒฝ์ด ๋ง๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์ controller์์ view๋ก ๋์ด๊ฐ ๋๋ DTO๋ฅผ ์ฌ์ฉํ๋๋ฐ, DAO์ ์๋น์ค ์ฌ์ด์๋ ์ฃผ๋ก ์ฐ์ง ์์์. ์๊ฐ๋ณด๋ค DAO์ ๋ณ๊ฒฝ์ ์ ์ค์ ๊ฐํ๊ธฐ ๋๋ฌธ์ ์๋น์ค์ ๋ณ๊ฒฝ์ผ๋ก ์ธํด DAO๊ฐ ๋ณํ๋ ๊ฒฝ์ฐ๊ฐ view-controller์ ๋นํด ์ ๊ธฐ ๋๋ฌธ์ด์์. ๋๊ฒจ์ผ ๋๋ ์ธ์๊ฐ ๋ง์ผ๋ฉด ํ์ํ๋ค๊ณ ๋๊ปด์ ์ฐ๊ธฐ๋ ํ๊ณ ์. ์ถ๊ฐ๋ก, ๋ ์ด์ด ๊ฐ ์์กด ๋ฐฉํฅ์ ์งํค๊ธฐ ์ํด DTO๋ฅผ ์ฐ๋ ๊ฒฝ์ฐ๋ ์์ด์. ๋๋ฉ์ธ ๊ฐ์ฒด๋ฅผ DAO๊น์ง ๊ทธ๋๋ก ์ ๋ฌํ๋ฉด DAO๊ฐ ๋๋ฉ์ธ ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ์์์ผ ํ๊ณ , DB ์คํค๋ง๊ฐ ๋ฐ๋์์ ๋ ๋๋ฉ์ธ ๊ฐ์ฒด๊น์ง ์ํฅ์ด ์ ํ๋ ์ ์๊ฑฐ๋ ์. DTO๊ฐ ๋ ๋ ์ด์ด ์ฌ์ด์ ๊ฒฝ๊ณ๋ฅผ ๋ช ์์ ์ผ๋ก ๋ง๋ค์ด์ ์๋ก ๋ ๋ฆฝ์ ์ผ๋ก ๋ณ๊ฒฝํ ์ ์๊ฒ ํด์ค ์๋ ์์ด์.
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. ์ ์ฒด์ ์ผ๋ก ํ ์คํธ๊ฐ ๋ถ์กฑํ ๊ฒ ๊ฐ์ต๋๋ค! ๋ชจ๋ ์ผ์ด์ค์ ๋ํด ํ ์คํธ๊ฐ ์ปค๋ฒ๋์๋์ง ํ์ธ ๋ถํ๋๋ฆด๊ฒ์! |
||
| - ์ขํ๋ ๋ณด๋ ๋ฒ์(ํ 1~10, ์ด 1~9)๋ฅผ ๋ฒ์ด๋ ์ ์๋ค. | ||
| - ์ขํ๋ ์ด๋๊ฐ(`Movement`)์ ์ ์ฉํด ๋ค์ ์์น๋ฅผ ๊ณ์ฐํ ์ ์๋ค. | ||
| - ์ขํ๋ ๋ค๋ฅธ ์์น์ ๋ํด์ ์ ํ(์ง์ , ๋๊ฐ์ )์ฌ๋ถ๋ฅผ ํ๋จํ ์ ์๋ค. | ||
| - ์ขํ๋ ํน์ ์ขํ ๋ฒ์(ํ: 1~3ํ/4~6์ด, ์ด: 8~10ํ/4~6์ด)๋ฅผ '๊ถ์ฑ'์ผ๋ก ์ ์ํ๋ค. | ||
|
|
||
| ### ์ด๋ ์ ๋ต | ||
| - ๊ฐ ๊ธฐ๋ฌผ์ ๋ชฉ์ ์ง๊น์ง์ ๊ฒฝ๋ก๋ฅผ ๊ณ์ฐํ๋ค. | ||
| - ๊ฒฝ๋ก ๊ฒ์ฆ์ `RoutePolicy`๋ฅผ ํตํด ์ํํ๋ค. | ||
| - ์ผ๋ฐ ๊ธฐ๋ฌผ์ ๊ฒฝ๋ก๊ฐ ๋น์ด ์๊ณ ๋์ฐฉ ์ง์ ์ ์๊ตฐ์ด ์์ ๋ ์ด๋ํ ์ ์๋ค. | ||
| - ํฌ๋ ์ด๋ ๊ฒฝ๋ก ์ค ์ ํํ ํ๋์ ๊ธฐ๋ฌผ์ ๋์ด์ผ ํ๋ฉฐ, ํฌ๋ฅผ ๋์ ์ ์๋ค. | ||
| - ๊ถ์ฑ ๋ด๋ถ์ ์์นํ ๊ธฐ๋ฌผ(๊ถ, ์ฌ, ์ฐจ, ํฌ, ์กธ)์ ๊ถ์ฑ ๋ผ์ธ์ ๋ฐ๋ฅธ ๋๊ฐ์ ์ด๋์ด ๊ฐ๋ฅํ๋ค. | ||
| - ๋ชฉ์ ์ง ์์ฒด๊ฐ ์ด๋ ๊ท์น์ ๋ง์ง ์์ผ๋ฉด ์์ธ๋ฅผ ๋ฐ์์ํจ๋ค. | ||
|
|
||
| ### ๊ฒ์ ์งํ | ||
| - ๊ฒ์์ ์ด ์ง์๋ถํฐ ์์ํ๋ค. | ||
| - ํ๋ ์ด์ด๋ ํด๋ง๋ค ์์ ์ขํ์ ๋์ฐฉ ์ขํ๋ฅผ ์ ๋ ฅํ๋ค. | ||
| - ์ฌ์ฉ์๊ฐ ์์ ์ขํ ์ ๋ ฅ ์ '์ข ๋ฃ'๋ฅผ ์ ๋ ฅํ๋ฉด ๊ฒ์ ์ค๋จ ์ฌ๋ถ๋ฅผ ์ฌํ์ธํ๋ค. | ||
| - ์๋ํธ์ด ๋์(์ข ๋ฃ ์ ๋ ฅ)ํ๋ฉด ๊ฒ์์ ์ฆ์ ์ข ๋ฃํ๋ค. | ||
| - ๋์ํ์ง ์์ผ๋ฉด(์ข ๋ฃ๊ฐ ์๋ ๋ค๋ฅธ ๊ฐ์ ์ ๋ ฅ) ํ์ฌ ํด์ ์ ์งํ๋ฉฐ ๋ค์ ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - ํ์ฌ ํด์ ์ง์๋ง ์์ ์ ๊ธฐ๋ฌผ์ ์ด๋ํ ์ ์๋ค. | ||
| - ์ด๋์ด ์๋ฃ๋๋ฉด ํด์ด ์๋ ์ง์์ผ๋ก ๋์ด๊ฐ๋ค. | ||
| - ๊ฒ์ ์ํ๋ `ChoTurn`, `HanTurn`, `Finish`๋ก ๊ตฌ๋ถ๋๋ค. | ||
| - 200ํด์ด ๋์ด๊ฐ๋ฉด ์ข ๋ฃ๋๋ค. | ||
|
|
||
| ### ์ด๊ธฐ ๋ฐฐ์น | ||
| - ์ด์ ํ์ ๊ฐ๊ฐ ๋ง์ ๋ฐฐ์น๋ฅผ ์ ๋ ฅํ ์ ์๋ค. | ||
|
|
@@ -46,16 +55,27 @@ | |
| ### ์ ๋ ฅ | ||
| - ํ ์ง์์ ๋ง์ ๋ฐฐ์น๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. | ||
| - ์ด ์ง์์ ๋ง์ ๋ฐฐ์น๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. | ||
| - ์ด๋ํ ๊ธฐ๋ฌผ์ ์์ ์ขํ๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. (์: `3,4`) | ||
| - ์ด๋ํ ๊ธฐ๋ฌผ์ ์์ ์ขํ ๋๋ ์ข ๋ฃ๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. (์: `3,4` ๋๋ `์ข ๋ฃ` ) | ||
| - ์ข ๋ฃ ์ฌํ์ธ ์ ์ข ๋ฃ ๋์ ์ฌ๋ถ๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. (์: `์ข ๋ฃ`) | ||
| - ์ด๋ํ ๊ธฐ๋ฌผ์ ๋์ฐฉ ์ขํ๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. (์: `4,4`) | ||
| - ์๋ชป๋ ์ ๋ ฅ์ด ๋ค์ด์ค๋ฉด ์์ธ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๊ณ ๋ค์ ์ ๋ ฅ๋ฐ๋๋ค. | ||
|
|
||
| ### ์ถ๋ ฅ | ||
| - ํ์ฌ ์ฅ๊ธฐํ ์ํ๋ฅผ ํ/์ด ์ขํ์ ํจ๊ป ์ถ๋ ฅํ๋ค. | ||
| - ์ด์ ํ ๊ธฐ๋ฌผ์ ANSI ์์์ผ๋ก ๊ตฌ๋ถํด ์ถ๋ ฅํ๋ค. | ||
| - ํ์ฌ ํด์ ์ง์์ ์ถ๋ ฅํ๋ค. | ||
| - ๋งค ํด ์ด๋์ด ์ฑ๊ณตํ๋ฉด ํ์ฌ ์ ์ง์์ ์ ์ ํฉ๊ณ๋ฅผ ์ถ๋ ฅํ๋ค. | ||
| - ๊ฒ์ ์ข ๋ฃ ์ ์ต์ข ์ ์์ ํจ๊ป ์น๋ฆฌํ ์ง์์ ์ถ๋ ฅํ๋ค. | ||
| - ์์ธ๊ฐ ๋ฐ์ํ๋ฉด `[ERROR]` ํ์์ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๋ค. | ||
|
|
||
| ### ๋ฐ์ดํฐ๋ฒ ์ด์ค | ||
| - ํ์ฌ DB์ ์ ์ฅ๋ ์ ์ฒด ์ฅ๊ธฐ ๊ฒ์๋ฐฉ ๋ชฉ๋ก์ ์กฐํํ๋ค. | ||
| - ์ ํํ ๊ฒ์๋ฐฉ์ ID๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํด๋น ํ์ ๋ชจ๋ ๊ธฐ๋ฌผ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ ๋ณด๋๋ฅผ ๋ณต์ํ๋ค. | ||
| - ์๋ก์ด ๊ฒ์ ์์ ์ ์ ๋ ฅ๋ฐ์ ๊ฒ์๋ฐฉ ์ ๋ณด(์ด๋ฆ, ์์ฑ ์๊ฐ ๋ฑ)๋ฅผ DB์ ์ ์ฅํ๋ค. | ||
| - ์๋ก์ด ๊ฒ์์ ์ด๊ธฐ ๊ธฐ๋ฌผ ๋ฐฐ์น ์ ๋ณด๋ฅผ DB์ ์ผ๊ด ์ ์ฅํ๋ค. | ||
| - ๊ธฐ๋ฌผ ์ด๋ ์, ์ด์ ์์น์ ๊ธฐ๋ฌผ ๋ฐ์ดํฐ๋ฅผ ์ญ์ ํ๊ณ ์๋ก์ด ์์น์ ์ ๋ณด๋ฅผ ์ ๋ฐ์ดํธํ์ฌ ์ํ๋ฅผ ์์ํํ๋ค. | ||
| - ๊ฒ์ ์ข ๋ฃ ์(๊ถ์ด ์กํ๊ฑฐ๋ ์ค๋จ ๋์ ์, ๋๋ 200ํด์ ๋๊ธธ ์) ํด๋น ๊ฒ์๋ฐฉ๊ณผ ๊ด๋ จ๋ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ DB์์ ์ญ์ ํ๋ค. | ||
|
|
||
| ### ์์ธ ์ฒ๋ฆฌ | ||
| - ์กด์ฌํ์ง ์๋ ๋ง์ ๋ฐฐ์น๋ฅผ ์ ๋ ฅํ ๊ฒฝ์ฐ | ||
| - ์ซ์๊ฐ ์๋ ์ขํ๋ฅผ ์ ๋ ฅํ ๊ฒฝ์ฐ | ||
|
|
@@ -65,3 +85,4 @@ | |
| - ํ์ฌ ํด์ ์ง์์ด ์๋ ๊ธฐ๋ฌผ์ ์์ง์ด๋ ค๋ ๊ฒฝ์ฐ | ||
| - ๊ธฐ๋ฌผ์ ์ด๋ ๊ท์น์ ๋ง์ง ์๋ ๋ชฉ์ ์ง๋ฅผ ์ ๋ ฅํ ๊ฒฝ์ฐ | ||
| - ์ด๋ ๊ฒฝ๋ก๊ฐ ๋งํ ์๊ฑฐ๋ ๋์ฐฉ ์ง์ ์ ์๊ตฐ ๊ธฐ๋ฌผ์ด ์๋ ๊ฒฝ์ฐ | ||
| - ์ ์ ์ฐจ๊ฐ ์ ์ ํจํ์ง ์์ ์ ์๊ฐ(์์ ๋ฑ)์ด ๊ณ์ฐ๋๋ ๊ฒฝ์ฐ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,31 @@ | ||
| package janggi; | ||
|
|
||
| import janggi.dao.GameRoom; | ||
| import janggi.dao.Piece; | ||
| import janggi.db.SQLManager; | ||
| import janggi.db.TransactionManager; | ||
| import janggi.domain.Game; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| Runner runner = new Runner(); | ||
| runner.run(); | ||
| SQLManager sqlManager = new SQLManager("jdbc:sqlite:src/main/resources/janggi.db"); | ||
| TransactionManager transactionManager = new TransactionManager(sqlManager); | ||
|
|
||
| GameRoom gameRoom = new GameRoom(sqlManager); | ||
| gameRoom.initTable(); | ||
|
|
||
| Piece piece = new Piece(sqlManager); | ||
| piece.initTable(); | ||
|
|
||
| JanggiService janggiService = new JanggiService(transactionManager, gameRoom, piece); | ||
|
|
||
| Game game = new Game(); | ||
|
|
||
| Runner runner = new Runner(janggiService, game); | ||
|
|
||
| int gameId = runner.initBoard(); | ||
| runner.runJanggi(gameId); | ||
|
|
||
| sqlManager.closeConnection(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package janggi; | ||
|
|
||
| import janggi.dao.GameRoom; | ||
| import janggi.dao.Piece; | ||
| import janggi.db.TransactionManager; | ||
| import janggi.domain.Position; | ||
| import janggi.domain.Side; | ||
| import janggi.domain.piece.PieceType; | ||
| import janggi.dto.GameDto; | ||
| import janggi.dto.GameResponseDto; | ||
| import janggi.dto.PieceDto; | ||
| import janggi.dto.TurnDto; | ||
| import java.util.List; | ||
|
|
||
| public class JanggiService { | ||
| private final TransactionManager transactionManager; | ||
| private final GameRoom gameRoom; | ||
| private final Piece piece; | ||
|
|
||
| public JanggiService(TransactionManager transactionManager, GameRoom gameRoom, Piece piece) { | ||
| this.transactionManager = transactionManager; | ||
| this.gameRoom = gameRoom; | ||
| this.piece = piece; | ||
| } | ||
|
|
||
| public List<GameResponseDto> getEntireGame() { | ||
| return gameRoom.findAllGames(); | ||
| } | ||
|
|
||
| public int addGameData(GameDto gameDto, List<PieceDto> pieceDtos) { | ||
| return transactionManager.sync((connection) -> { | ||
| int gameId = gameRoom.insertGame(connection, gameDto); | ||
| piece.updatePieces(connection, gameId, pieceDtos); | ||
|
|
||
| return gameId; | ||
| }); | ||
| } | ||
|
|
||
| public void removeGame(int id) { | ||
| transactionManager.sync((connection) -> { | ||
| gameRoom.removeGame(connection, id); | ||
| }); | ||
| } | ||
|
|
||
| public List<PieceDto> getPieceInitInfos(int gameId) { | ||
| return piece.getAllPieces(gameId); | ||
| } | ||
|
|
||
|
|
||
| public void movePiece(int gameId, Position start, Position end, Side side, PieceType pieceType, TurnDto turnDto) { | ||
| transactionManager.sync(connection -> { | ||
| gameRoom.updateGameTurn(connection, gameId, turnDto); | ||
| piece.deletePiece(connection, gameId, start.getX(), start.getY()); | ||
|
|
||
| PieceDto pieceDto = new PieceDto(end.getX(), end.getY(), pieceType.getName(), side.getName()); | ||
| piece.updatePiece(connection, gameId, pieceDto); | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,45 +2,110 @@ | |||||
|
|
||||||
| import janggi.domain.Arrangement; | ||||||
| import janggi.domain.Game; | ||||||
| import janggi.domain.GameInfo; | ||||||
| import janggi.domain.GameInfos; | ||||||
| import janggi.domain.GameName; | ||||||
| import janggi.domain.MoveResult; | ||||||
| import janggi.domain.PieceInitInfo; | ||||||
| import janggi.domain.Position; | ||||||
| import janggi.domain.Side; | ||||||
| import janggi.domain.SideScore; | ||||||
| import janggi.domain.piece.PieceType; | ||||||
| import janggi.dto.GameDto; | ||||||
| import janggi.dto.PieceDto; | ||||||
| import janggi.dto.TurnDto; | ||||||
| import janggi.view.InputView; | ||||||
| import janggi.view.OutputView; | ||||||
| import java.time.LocalDateTime; | ||||||
| import java.time.format.DateTimeFormatter; | ||||||
| import java.util.List; | ||||||
| import java.util.Optional; | ||||||
| import java.util.function.Supplier; | ||||||
| import java.util.logging.Level; | ||||||
| import java.util.logging.Logger; | ||||||
|
|
||||||
| public class Runner { | ||||||
| public static final String END_TEXT = "์ข ๋ฃ"; | ||||||
|
|
||||||
| private static final String UNEXPECTED_SERVER_ERROR_LOG_MESSAGE = "์์ธกํ์ง ๋ชปํ ์์คํ ์ค๋ฅ ๋ฐ์"; | ||||||
| private static final String SYSTEM_ERROR_MESSAGE = "์์คํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ฌ ๊ฒ์์ ์ข ๋ฃํฉ๋๋ค."; | ||||||
|
|
||||||
| private static final Logger logger = Logger.getLogger(Runner.class.getName()); | ||||||
| private Game game; | ||||||
|
|
||||||
| public void run() { | ||||||
| initArrangeGame(); | ||||||
| turnGame(); | ||||||
| private final JanggiService janggiService; | ||||||
| private final Game game; | ||||||
|
|
||||||
| public Runner(JanggiService janggiService, Game game) { | ||||||
| this.janggiService = janggiService; | ||||||
| this.game = game; | ||||||
| } | ||||||
|
|
||||||
| public int initBoard() { | ||||||
| Optional<Integer> previousBoard = getPreviousBoard(); | ||||||
| return previousBoard.orElseGet(() -> createNewBoard().id()); | ||||||
| } | ||||||
|
|
||||||
| private void initArrangeGame() { | ||||||
| public void runJanggi(int gameId) { | ||||||
| while (playTurnGame(gameId)) { | ||||||
| } | ||||||
| endGame(gameId); | ||||||
| } | ||||||
|
|
||||||
| private Optional<Integer> getPreviousBoard() { | ||||||
| GameInfos gameInfos = new GameInfos(janggiService.getEntireGame().stream() | ||||||
|
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. ์ฌ๊ธฐ๋ ๋น์ทํ๊ฒ ์ ์ฉํ ์ ์๊ฒ ๋ค์. |
||||||
| .map(gameResponseDto -> new GameInfo(gameResponseDto.id(), gameResponseDto.name(), gameResponseDto.createdAt(), gameResponseDto.updatedAt(), Side.from(gameResponseDto.side()), gameResponseDto.turn())) | ||||||
| .toList()); | ||||||
|
|
||||||
|
|
||||||
| if(gameInfos.isEmpty()) { | ||||||
| return Optional.empty(); | ||||||
| } | ||||||
|
|
||||||
| GameInfo selectedGame = askUntilValid(() -> getSelectedGame(gameInfos)); | ||||||
|
|
||||||
| List<PieceInitInfo> pieceInitInfos = janggiService.getPieceInitInfos(selectedGame.id()).stream().map(pieceDto -> new PieceInitInfo(new Position(pieceDto.x(), pieceDto.y()), Side.from(pieceDto.side()), | ||||||
|
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. |
||||||
| PieceType.from(pieceDto.pieceType()))).toList(); | ||||||
|
|
||||||
| game.init(pieceInitInfos, selectedGame.side(), selectedGame.turn()); | ||||||
| return Optional.of(selectedGame.id()); | ||||||
| } | ||||||
|
|
||||||
| private GameInfo getSelectedGame(GameInfos gameInfos) { | ||||||
| OutputView.printGameRoom(gameInfos.getGameInfos()); | ||||||
| Optional<Integer> input = InputView.askLoadGame(); | ||||||
|
|
||||||
| if(input.isEmpty()) { | ||||||
| return createNewBoard(); | ||||||
| } | ||||||
| return gameInfos.getGameInfo(input.get()); | ||||||
| } | ||||||
|
|
||||||
| private GameInfo createNewBoard() { | ||||||
| GameName gameName = new GameName(InputView.askGameName()); | ||||||
| DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||||||
| String formattedNow = LocalDateTime.now().format(formatter); | ||||||
|
|
||||||
| String hanArrangementInput = InputView.askHanArrangement(); | ||||||
| Arrangement hanArrangement = Arrangement.from(hanArrangementInput); | ||||||
|
|
||||||
| String choArrangementInput = InputView.askChoArrangement(); | ||||||
| Arrangement choArrangement = Arrangement.from(choArrangementInput); | ||||||
|
|
||||||
| game = new Game(choArrangement, hanArrangement); | ||||||
| } | ||||||
| List<PieceDto> pieceDtos = game.init(choArrangement, hanArrangement).stream() | ||||||
| .map(pieceInitInfo -> new PieceDto(pieceInitInfo.position().getX(), pieceInitInfo.position().getY(), pieceInitInfo.pieceType().getName(), pieceInitInfo.side().getName())) | ||||||
|
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. PieceDto์์ ์ ์ ๋ฉ์๋๋ฅผ ๋ง๋ค์ด๋ ์ข์ ๊ฒ ๊ฐ์๋ฐ, ์ด๋ป๊ฒ ์๊ฐํ์๋์?
Suggested change
|
||||||
| .toList(); | ||||||
|
|
||||||
| private void turnGame() { | ||||||
| while (playTurnGame()) { | ||||||
| } | ||||||
| int id = janggiService.addGameData(new GameDto(gameName.name(), formattedNow, formattedNow, Side.CHO.getName(), 1), pieceDtos); | ||||||
| return new GameInfo(id, gameName.name(), formattedNow, formattedNow, Side.CHO, 1); | ||||||
| } | ||||||
|
|
||||||
| private boolean playTurnGame() { | ||||||
| private boolean playTurnGame(int gameId) { | ||||||
| try { | ||||||
| printCurrentStatus(); | ||||||
| movePiece(); | ||||||
| return isFinishedGame(); | ||||||
| OutputView.printLine(); | ||||||
| OutputView.printBoard(game.getCurrentBoardDto()); | ||||||
| OutputView.printTurn(game.getCurrentSide()); | ||||||
|
|
||||||
| return executeTurn(gameId); | ||||||
| } catch (IllegalArgumentException e) { | ||||||
| OutputView.printErrorMessage(e.getMessage()); | ||||||
| return true; | ||||||
|
|
@@ -51,26 +116,68 @@ private boolean playTurnGame() { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void printCurrentStatus() { | ||||||
| OutputView.printBoard(game.getCurrentBoardDto()); | ||||||
| OutputView.printTurn(game.getCurrentSide()); | ||||||
| } | ||||||
| private boolean executeTurn(int gameId) { | ||||||
| Optional<List<Integer>> startPositionInput = InputView.askStartPosition(); | ||||||
|
|
||||||
| private void movePiece() { | ||||||
| List<Integer> startPositionInput = InputView.askStartPosition(); | ||||||
| Position startPosition = Position.from(startPositionInput); | ||||||
| if(startPositionInput.isEmpty()) { | ||||||
| return consentEndGame(gameId); | ||||||
| } | ||||||
|
|
||||||
| Position startPosition = Position.from(startPositionInput.get()); | ||||||
|
|
||||||
| List<Integer> endPositionInput = InputView.askEndPosition(); | ||||||
| Position endPosition = Position.from(endPositionInput); | ||||||
|
|
||||||
| game.move(startPosition, endPosition); | ||||||
| OutputView.printLine(); | ||||||
|
|
||||||
| MoveResult moveResult = game.move(startPosition, endPosition); | ||||||
| TurnDto turnDto = new TurnDto(moveResult.turnAttribute().side().getName(), moveResult.turnAttribute().turn()); | ||||||
|
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. ๋๋ฏธํฐ ๋ฒ์น ์๋ฐ์ด๋ค์. ์ด๋ป๊ฒ ๊ฐ์ ํด๋ณผ ์ ์์๊น์?
|
||||||
|
|
||||||
| janggiService.movePiece(gameId, startPosition, endPosition, moveResult.pieceAttribute().side(), moveResult.pieceAttribute().pieceType(), turnDto); | ||||||
|
|
||||||
| OutputView.printScore(game.getCurrentSideScore()); | ||||||
| return !game.isFinished(); | ||||||
| } | ||||||
|
|
||||||
| private boolean isFinishedGame() { | ||||||
| if (game.isFinished()) { | ||||||
| OutputView.printWinner(game.getWinnerSide()); | ||||||
| private void endGame(int gameId) { | ||||||
| janggiService.removeGame(gameId); | ||||||
|
|
||||||
| Side winnerSide = game.getWinnerSide(); | ||||||
|
|
||||||
| if(winnerSide == null) { | ||||||
|
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.printScore(game.getCurrentSideScore()); | ||||||
| printScoreWinner(); | ||||||
| return; | ||||||
| } | ||||||
| OutputView.printWinner(winnerSide); | ||||||
| } | ||||||
|
|
||||||
| private boolean consentEndGame(int gameId) { | ||||||
| String consentInput = InputView.consentEnd(); | ||||||
|
|
||||||
| if(consentInput.equals(END_TEXT)) { | ||||||
| return false; | ||||||
| } | ||||||
| return true; | ||||||
|
|
||||||
| return executeTurn(gameId); | ||||||
| } | ||||||
|
|
||||||
| private void printScoreWinner() { | ||||||
| SideScore score = game.getCurrentSideScore(); | ||||||
| if(score.cho() > score.han()) { | ||||||
|
Comment on lines
+166
to
+167
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. getter๋ก ๊บผ๋ด์์ ๋น๊ตํด์ผํ๋์? |
||||||
| OutputView.printWinner(Side.CHO); | ||||||
| return; | ||||||
| } | ||||||
| OutputView.printWinner(Side.HAN); | ||||||
|
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. ๋์ ์ํฉ์์๋ HAN ์น๋ฆฌ๋ฅผ ์ถ๋ ฅํ๋์? |
||||||
| } | ||||||
|
|
||||||
| private static <T> T askUntilValid(Supplier<T> supplier) { | ||||||
| while (true) { | ||||||
| try { | ||||||
| return supplier.get(); | ||||||
| } catch (Exception e) { | ||||||
| System.out.println(e.getMessage()); | ||||||
|
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๊ฐ ์๋๋ฐ๋, ์ฌ๊ธฐ์ ์ถ๋ ฅํ๋ ์ด์ ๊ฐ ์๋์? |
||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
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.
๊ธฐ๋ฅ๋ชฉ๋ก ๐ฏ