-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๊ธฐ๋ฌผ ํ์ฅ + DB ์ ์ฉ)] ๋ฒจ๋ก ๋ฏธ์ ์ ์ถํฉ๋๋ค. #270
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: juntae6942
Are you sure you want to change the base?
Changes from all commits
009de5d
53df5a9
ce78b3b
1aa202e
5a5da77
aa9a62f
0f1da61
fd63ca3
4f41b55
506a318
2ee2313
ee3d02f
1d3c1bf
c128726
f9952c7
6f79f85
db7292e
8fc3f25
5c2096f
e36b69f
b200d50
4cddc93
ac47705
27b3b6e
3b1797b
1dccc84
2d06433
80ea3f1
331725b
15aed38
0b13397
3856888
45b8fee
acaf869
96e2d3b
910b99c
ae7a073
0912c36
fcfd62a
5e2e0d9
a6b33cf
a3974b3
4432a08
4878c6d
1dc2d87
9cbd761
3e8cc8e
29cce32
cdb2bd0
4bddfbb
aca2eac
c1217e1
c4adcf9
40f5065
30d33bd
122afad
10f1024
bc289da
eb438b0
e436cf8
ad666f3
ebb4d6e
7b33741
8f147b5
12bf254
92f051a
73ba061
8359400
36c2748
8d2ca59
c404444
0029a5a
825229e
5f46ac9
6cb316d
ce5ea69
c631ad5
24c9daa
e0430f8
b04d73e
315983e
f4419bb
41a7302
dfd5eb3
8f1c77a
252829d
8bdf44d
40e5f49
db8cf19
d3297ea
2343f65
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 |
|---|---|---|
| @@ -1,37 +1,25 @@ | ||
| package janggi; | ||
|
|
||
| import janggi.domain.Board; | ||
| import janggi.domain.JanggiGame; | ||
| import janggi.domain.Point; | ||
| import janggi.domain.piece.Piece; | ||
| import janggi.presentation.dto.GameStatusInfo; | ||
| import janggi.presentation.dto.MoveCommand; | ||
| import janggi.presentation.dto.PositionInfo; | ||
| import janggi.application.JanggiGameService; | ||
| import janggi.domain.board.BoardRepository; | ||
| import janggi.infra.DataConnectionManager; | ||
| import janggi.infra.JdbcBoardRepository; | ||
| import janggi.presentation.JanggiGameController; | ||
| import janggi.presentation.ui.InputView; | ||
| import janggi.presentation.ui.OutputView; | ||
| import janggi.util.Console; | ||
| import janggi.util.FileParser; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.sql.SQLException; | ||
| import org.h2.tools.Server; | ||
|
|
||
| public class JanggiApplication { | ||
| public static void main(String[] args) { | ||
| List<PositionInfo> positionInfos = FileParser.readCsvFile("/janggi.csv"); | ||
| Map<Point, Piece> pieces = new LinkedHashMap<>(); | ||
| positionInfos.forEach(info -> pieces.put(info.point(), info.piece())); | ||
| Board board = new Board(); | ||
| board.init(pieces); | ||
| JanggiGame game = new JanggiGame(board); | ||
|
|
||
| OutputView.printGameStatus(GameStatusInfo.from(game.getBoardStatus())); | ||
| OutputView.printStartGame(); | ||
| while (!game.isFinished()) { | ||
| MoveCommand points = InputView.readPoints(); | ||
| game.play(points.from(), points.to()); | ||
| OutputView.printGameStatus(GameStatusInfo.from(game.getBoardStatus())); | ||
| } | ||
| OutputView.printWinner(game.getWinner()); | ||
| Console.close(); | ||
| public static void main(String[] args) throws SQLException { | ||
| Server server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092").start(); | ||
| DataConnectionManager manager = new DataConnectionManager(); | ||
| BoardRepository repository = new JdbcBoardRepository(manager); | ||
| JanggiGameService service = new JanggiGameService(repository); | ||
| InputView inputView = new InputView(); | ||
| OutputView outputView = new OutputView(); | ||
| JanggiGameController controller = new JanggiGameController(service, inputView, outputView); | ||
| controller.run(); | ||
| server.stop(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package janggi.application; | ||
|
|
||
| import janggi.domain.board.Board; | ||
| import janggi.domain.board.BoardRepository; | ||
| import janggi.domain.JanggiGame; | ||
| import janggi.domain.point.Point; | ||
| import janggi.domain.status.ChoTurn; | ||
| import janggi.domain.status.Team; | ||
| import janggi.presentation.dto.GameStatusInfo; | ||
|
|
||
| public class JanggiGameService { | ||
|
Member
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. ์ด๋ฒ ์ฌ์ดํด์์ ์๋ก ๋ค์ด์จ Service์ ์ฑ ์์ ์ด๋๊น์ง๋ผ๊ณ ๋ณด์๋์? Service๊ฐ ํ์ํ๊ฐ? ๋ฅผ ์ด์ผ๊ธฐํด๋ณด๊ณ ์ถ์ต๋๋ค.
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. ๋๋ฉ์ธ ๋ก์ง์ ์บก์ํํ๊ณ , ํธ๋์ญ์ ์ ๊ด๋ฆฌํ๊ธฐ ์ํด์ ํ์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋ํ ์ปจํธ๋กค๋ฌ์์ ๋ง์ฝ repository๋ฅผ ๋๊ณ , ์ฌ์ฉํ๊ฒ๋๋ค๋ฉด JanggiGame์ด ๋ฐ๋ก ๋ ธ์ถ๋์ด ์ธ๋ถ์ ๋ณ๊ฒฝ์ ์ํฅ์ ๋ฐ์ ์ ์์ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐํฉ๋๋ค. |
||
|
|
||
| private final BoardRepository repository; | ||
|
|
||
| public JanggiGameService(BoardRepository repository) { | ||
| this.repository = repository; | ||
| } | ||
|
|
||
| public long startNewGame(Board initBoard) { | ||
| JanggiGame game = new JanggiGame(initBoard, new ChoTurn()); | ||
| return repository.save(game); | ||
| } | ||
|
|
||
| public GameStatusInfo getBoardStatus(Long roomId) { | ||
| return GameStatusInfo.from(repository.loadGame(roomId).getBoardStatus()); | ||
| } | ||
|
|
||
| public boolean isFinished(Long roomId) { | ||
| return repository.loadGame(roomId) | ||
| .isFinished(); | ||
| } | ||
|
|
||
| public void play(Long roomId, Point from, Point to) { | ||
| JanggiGame game = repository.loadGame(roomId); | ||
| game.play(from, to); | ||
| repository.update(roomId, from, to, game); | ||
|
Comment on lines
+35
to
+36
Member
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. update์ ์คํจํ๋ฉด, ๋๋ฉ์ธ ๊ฐ์ฒด๋ ๋ณ๊ฒฝ๋์์ผ๋ DB์๋ ๋ฐ์๋์ง ์๋ ์ํฉ์ด ์ผ์ด๋ ์ ์์ง ์์๊น์?
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. ์ผ์ด๋ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋์ ๋ฌด์ํ์ฑ์ ์ ์งํ๋๋ก ์์ ํ์์ต๋๋ค! |
||
| } | ||
|
Member
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. PR ์ง๋ฌธ์ ๋ํ ์๊ฒฌ) play๊ฐ ๊ฐ์ฒด๋ฅผ ๋ณํํ๊ณ ์์ผ๋, ์ด๋ฅผ ๋ฐํํ์ฌ ํ์ฉํ๋ฉด DB ๋ถํ๋ฅผ ์ค์ผ ์ ์์ง ์์๊น์? ๋์์ฑ๊ณผ DB ๋ถํ ๋ชจ๋ ์ฑ๊ธธ ์ ์์ ๊ฒ ๊ฐ์์. |
||
|
|
||
| public Team winner(Long roomId) { | ||
| return repository.loadGame(roomId) | ||
| .getWinner(); | ||
| } | ||
|
|
||
| public Team currentTurn(Long roomId) { | ||
| return repository.loadGame(roomId) | ||
| .getTeam(); | ||
| } | ||
|
|
||
| public double getHanScore(Long roomId) { | ||
| return repository.loadGame(roomId) | ||
| .getHanScore(); | ||
| } | ||
|
|
||
| public double getChoScore(Long roomId) { | ||
| return repository.loadGame(roomId) | ||
| .getChoScore(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package janggi.domain.board; | ||
|
|
||
| import janggi.domain.JanggiGame; | ||
| import janggi.domain.point.Point; | ||
|
|
||
| public interface BoardRepository { | ||
| long save(JanggiGame game); | ||
| void update(Long roomId, Point from, Point to, JanggiGame game); | ||
| JanggiGame loadGame(Long gameRoomId); | ||
|
Member
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 comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ฐํ ์ด์ผ๊ธฐํ์๋ฉด, ์ ํ๋ฆฌ์ผ์ด์ ์์
DB ์๋ฒ๋ฅผ ์ผ๊ณ ๋๋ ์ฑ ์๋ ํจ๊ปํ๊ณ ์๋ค๊ณ ๋ณด์ฌ์ง๋ค์.build.gradle์ ์ ํ๋ฆฌ์ผ์ด์ ์ ์์กด ๊ด๊ณ๋ฅผ ํ์ธํ ์ ์๋๋ฐ,H2DB๋ Connector๋ฅผ ๋์ด Embedded server๋ก ๋์ํ๊ณ ์๊ธฐ๋ ํฉ๋๋ค.ํ์๋ก ๊ตฌํํด์ผํ๋ ๊ฒ์ ์๋์ง๋ง, ์ ํ๋ฆฌ์ผ์ด์ ์ด DB์ ์๋ช ์ฃผ๊ธฐ๋ฅผ ๊ด๋ฆฌํ์ง ์๋๋ก ํ๋ ค๋ฉด ์ด๋ค ๋ฐฉ๋ฒ์ด ์์๊น์?
Uh oh!
There was an error while loading. Please reload this page.
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.
docker๋ฅผ ์ฌ์ฉํ์ฌ ์ปจํ ์ด๋๋ฅผ ๋์์ ํ ์๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค. ํ์ฌ๋ ๊ฐ๋ฐ ํธ์์ฑ๊ณผ ๋ฏธ์ ํ๊ฒฝ์ ๊ณ ๋ คํด์ ์๋ฒ ๋๋ ๋ฐฉ์์ ์ ์งํ๋ ๊ฒ์ด ์ข๊ฒ ๋ค๊ณ ํ๋จํ์ฌ ์ฌ์ฉํ์์ต๋๋ค.
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.
(์ ํ) ์๊ฐ์ด ๋ง์ด ๋จ์ผ์๊ฑฐ๋ ์ฌ์ดํด์ ์ฐ์ฅ์ ์ผ๋ก ์๊ฐํ์ ๋ค๋ฉด ๋์ ํด๋ณด์ ๋ ์ข๊ฒ ์ต๋๋ค ใ ใ