-
Notifications
You must be signed in to change notification settings - Fork 0
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
나는 허브의 내일이란다 #12
base: main
Are you sure you want to change the base?
나는 허브의 내일이란다 #12
Changes from all commits
ff4f19d
1bab9ff
98598c0
8a6140a
e22fcb3
8a78c7b
4e41311
8659523
85e3615
547058d
d878f8b
b904300
319563d
5d450b8
0441806
d9522c7
0119bd3
de53b5d
b1b6758
65739a2
0ad4ac9
2e408fc
505143e
392be91
a87dc9d
abceac6
e986881
7130470
01fe9d9
4e8d1c2
87dc039
2ebb089
4746e46
62ecd3a
b476169
6484578
beb6237
3f4e9c6
76f20e7
73fe527
0b7ba9d
ace0bbc
0f87826
5d4f8ff
97207dc
15536f5
0b811a0
eb8f6b9
5f14eec
7bb6ce1
e9271bd
535553d
5315ae3
0dc4140
c5c6b43
c9352d3
7dc8153
0dea052
a9a0f2f
20824ad
ffac2e8
b9d5966
0ed5a87
ecd5232
e025164
1ffb77c
ef1ce69
1149eae
682dd16
fb10477
9717a43
515fbd1
995fd19
89d8395
41e1643
172151a
ba1baf4
8751e86
0d5f686
a8adb91
1a13e1f
e971899
f9f953a
e24049a
602c24f
9c8b418
80a91e0
a538ee0
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package chess; | ||
|
||
import chess.controller.ControllerFactory; | ||
import chess.controller.main.MainController; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class ChessGameApplication { | ||
public static void main(String[] args) { | ||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
executor.execute(() -> { | ||
final MainController controller = ControllerFactory.mainController(); | ||
controller.run(); | ||
}); | ||
executor.shutdown(); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package chess.controller; | ||
|
||
import java.util.List; | ||
|
||
@FunctionalInterface | ||
public interface Action { | ||
Action EMPTY = ignore -> { | ||
}; | ||
|
||
void execute(final List<String> commands); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package chess.controller; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CommandMapper<K, V> { | ||
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 쿨하네요 |
||
private final Map<K, V> commandMapper = new HashMap<>(); | ||
|
||
public CommandMapper(final Map<K, V> commandMapper) { | ||
this.commandMapper.putAll(commandMapper); | ||
} | ||
|
||
public V getValue(final K command) { | ||
return commandMapper.get(command); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package chess.controller; | ||
|
||
import chess.controller.game.GameController; | ||
import chess.controller.main.MainCommand; | ||
import chess.controller.main.MainController; | ||
import chess.controller.room.RoomController; | ||
import chess.controller.user.UserController; | ||
import chess.db.FixedConnectionPool; | ||
import chess.db.JdbcTemplate; | ||
import chess.repository.GameDao; | ||
import chess.repository.GameJdbcDao; | ||
import chess.repository.RoomDao; | ||
import chess.repository.RoomJdbcDao; | ||
import chess.repository.UserDao; | ||
import chess.repository.UserJdbcDao; | ||
import chess.service.GameService; | ||
import chess.service.RoomService; | ||
import chess.service.UserService; | ||
import chess.view.input.InputView; | ||
import chess.view.output.GameOutputView; | ||
import chess.view.output.MainOutputView; | ||
import chess.view.output.RoomOutputView; | ||
import chess.view.output.UserOutputView; | ||
import java.util.Map; | ||
import java.util.Scanner; | ||
|
||
public class ControllerFactory { | ||
private static final MainController INSTANCE; | ||
private static final InputView INPUT_VIEW = new InputView(new Scanner(System.in)); | ||
private static final JdbcTemplate JDBC_TEMPLATE = new JdbcTemplate(FixedConnectionPool.getInstance()); | ||
|
||
static { | ||
final CommandMapper<MainCommand, SubController> mainCommandMapper = new CommandMapper<>(Map.of( | ||
MainCommand.USER, userController(), | ||
MainCommand.ROOM, roomController(), | ||
MainCommand.START, gameController(), | ||
MainCommand.END, () -> { | ||
} | ||
)); | ||
INSTANCE = new MainController(INPUT_VIEW, new MainOutputView(), mainCommandMapper); | ||
} | ||
|
||
private static SubController userController() { | ||
return new UserController(INPUT_VIEW, new UserOutputView(), new UserService(userDao())); | ||
} | ||
|
||
private static UserDao userDao() { | ||
return new UserJdbcDao(JDBC_TEMPLATE); | ||
} | ||
|
||
private static SubController roomController() { | ||
return new RoomController(INPUT_VIEW, new RoomOutputView(), new RoomService(roomDao())); | ||
} | ||
|
||
private static RoomDao roomDao() { | ||
return new RoomJdbcDao(JDBC_TEMPLATE); | ||
} | ||
|
||
private static SubController gameController() { | ||
return new GameController(INPUT_VIEW, new GameOutputView(), new GameService(gameDao())); | ||
} | ||
|
||
private static GameDao gameDao() { | ||
return new GameJdbcDao(JDBC_TEMPLATE); | ||
} | ||
|
||
public static MainController mainController() { | ||
return INSTANCE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package chess.controller; | ||
|
||
@FunctionalInterface | ||
public interface SubController { | ||
void run(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package chess.controller.game; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public enum GameCommand { | ||
MOVE(3), | ||
STATUS(1), | ||
END(1), | ||
EMPTY(0), | ||
; | ||
|
||
private final int size; | ||
|
||
GameCommand(final int size) { | ||
this.size = size; | ||
} | ||
|
||
public static final int MOVE_SOURCE_INDEX = 1; | ||
public static final int MOVE_TARGET_INDEX = 2; | ||
private static final int COMMAND_INDEX = 0; | ||
private static final String INVALID_COMMAND_MESSAGE = "올바른 명령어를 입력해주세요."; | ||
|
||
public static GameCommand from(final List<String> commands) { | ||
return Arrays.stream(values()) | ||
.filter(command -> command != EMPTY) | ||
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. empty를 거르는 모습 정말 꼼꼼하네요 |
||
.filter(command -> command.name().equalsIgnoreCase(commands.get(COMMAND_INDEX))) | ||
.findFirst() | ||
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. findAny() 도 있는데 first를 쓰신 이유 궁금 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. 둘다 똑같다고 생각합니다 |
||
.orElseThrow(() -> new IllegalArgumentException(INVALID_COMMAND_MESSAGE)); | ||
} | ||
|
||
public void validateCommandsSize(final List<String> commands) { | ||
if (size != commands.size()) { | ||
throw new IllegalArgumentException(INVALID_COMMAND_MESSAGE); | ||
} | ||
} | ||
} |
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.
나무위키 같아서 좋네요
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.
어떻게 알았지?