Skip to content

Commit

Permalink
refactor : 불필요한 메서드 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
fucct committed Apr 8, 2020
1 parent 2754a72 commit 2f4375b
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chess.service;
package chess.command;

public enum Command {
START,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/chess/controller/ChessController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ChessController {

public void run() {
OutputView.printInitialMessage();
while (!chessService.isEnd()) {
while (!chessService.isEnd(0)) {
RequestDto requestDto = InputView.inputRequest();
ResponseDto responseDto = chessService.run(requestDto);
OutputView.printResponse(responseDto);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/chess/controller/ChessWebController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package chess.controller;

import chess.command.Command;
import chess.controller.dto.RequestDto;
import chess.controller.dto.ResponseDto;
import chess.controller.dto.WebDto;
import chess.service.ChessService;
import chess.service.Command;
import spark.ModelAndView;
import spark.Request;
import spark.template.handlebars.HandlebarsTemplateEngine;
Expand All @@ -19,6 +19,10 @@ public class ChessWebController {

private ChessService chessService = new ChessService();

private static String render(Map<String, Object> model, String templatePath) {
return new HandlebarsTemplateEngine().render(new ModelAndView(model, templatePath));
}

public void run() {
get("/", (req, res) -> {
Map<String, Object> model = new HashMap<>();
Expand Down Expand Up @@ -123,10 +127,6 @@ private List<WebDto> makeBoardDto(final ResponseDto responseDto) {
new WebDto(entry.getKey().getName(), entry.getValue()))
.collect(Collectors.toList());
}

private static String render(Map<String, Object> model, String templatePath) {
return new HandlebarsTemplateEngine().render(new ModelAndView(model, templatePath));
}
//
//
// get("/", (req, res) -> {
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/chess/controller/dto/RequestDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package chess.controller.dto;

import chess.service.Command;
import chess.command.Command;

import java.util.List;

Expand All @@ -9,19 +9,18 @@ public class RequestDto {
private List<String> parameter;
private long id;

public RequestDto(Command command, List<String> parameter) {
public RequestDto(Command command) {
this.command = command;
this.parameter = parameter;
}

public RequestDto(final Command command, final List<String> parameter, final long id) {
this.command = command;
public RequestDto(Command command, List<String> parameter) {
this(command);
this.parameter = parameter;
this.id = id;
}

public RequestDto(Command command) {
this.command = command;
public RequestDto(final Command command, final List<String> parameter, final long id) {
this(command, parameter);
this.id = id;
}

public Command getCommand() {
Expand Down
42 changes: 17 additions & 25 deletions src/main/java/chess/controller/dto/ResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public ResponseDto(Map<Position, String> board, Turn turn, Status status, long i
this.id = id;
}

public ResponseDto(Status status) {
this.status = status;
}

public ResponseDto(final String message) {
this.message = message;
}
Expand All @@ -42,21 +38,37 @@ public Map<Position, String> getBoard() {
return board;
}

public void setBoard(final Map<Position, String> board) {
this.board = board;
}

public Map<Player, Double> getStatus() {
if (Objects.nonNull(status)) {
return status.getStatus();
}
return null;
}

public void setStatus(final Status status) {
this.status = status;
}

public Player getWinner() {
return status.getWinner();
}

public void setWinner(final Player winner) {
this.winner = winner;
}

public String getMessage() {
return message;
}

public void setMessage(final String message) {
this.message = message;
}

public Turn getTurn() {
return turn;
}
Expand All @@ -66,31 +78,11 @@ public long getId() {
return id;
}

public void setBoard(final Map<Position, String> board) {
this.board = board;
}

public void setStatus(final Status status) {
this.status = status;
}

public void setMessage(final String message) {
this.message = message;
}

public void setWinner(final Player winner) {
this.winner = winner;
}

public void setId(final long id) {
this.id = id;
}

public List<Long> getRoomId() {
return roomId;
}

public void setRoomId(final List<Long> roomId) {
this.roomId = roomId;
}
}
}
22 changes: 11 additions & 11 deletions src/main/java/chess/domain/piece/Pawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ protected Pawn(Position position, Player player) {
super(PieceType.PAWN, position, player);
}

public static PieceState of(final Position position, final Player player) {
Position whitePawnPosition = Position.of("a2");
Position blackPawnPosition = Position.of("a7");

if (whitePawnPosition.getRankDifference(position) == 0 && player.equals(Player.WHITE) ||
blackPawnPosition.getRankDifference(position) == 0 && player.equals(Player.BLACK)) {
return new NotMovedPawn(position, player);
}
return new MovedPawn(position, player);
}

@Override
protected void validateMovingPolicy(Position target, Map<Position, PieceDto> boardDto) {
MovingDirection movingDirection = MovingDirection.getDirection(position, target);
Expand Down Expand Up @@ -70,15 +81,4 @@ public String getFigure() {
public String toString() {
return pieceType.toString();
}

public static PieceState of(final Position position, final Player player) {
Position whitePawnPosition = Position.of("a2");
Position blackPawnPosition = Position.of("a7");

if (whitePawnPosition.getRankDifference(position) == 0 && player.equals(Player.WHITE) ||
blackPawnPosition.getRankDifference(position) == 0 && player.equals(Player.BLACK)) {
return new NotMovedPawn(position, player);
}
return new MovedPawn(position, player);
}
}
31 changes: 17 additions & 14 deletions src/main/java/chess/service/ChessService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package chess.service;

import chess.command.Command;
import chess.controller.dto.RequestDto;
import chess.controller.dto.ResponseDto;
import chess.dao.ChessDAO;
Expand Down Expand Up @@ -69,12 +70,8 @@ public ResponseDto end(RequestDto requestDto) {
List<String> parameter = requestDto.getParameter();
ResponseDto responseDto = new ResponseDto("");
try {
if ("save".equals(parameter.get(0))) {
chessDAO.addBoard(id, chessGame);
}
if ("".equals(parameter.get(0))) {
chessDAO.deleteGame(id);
}
saveGame(id, chessGame, parameter);
endGame(id, parameter);
chessGames.remove(id);
responseDto.setRoomId(chessDAO.getRoomId());
} catch (SQLException e) {
Expand All @@ -83,19 +80,25 @@ public ResponseDto end(RequestDto requestDto) {
return responseDto;
}

// private ResponseDto status(RequestDto requestDto) {
//// chessGame.status();
//// return new ResponseDto(chessGame.getStatus());
// return null;
// }
private void endGame(final long id, final List<String> parameter) throws SQLException {
if ("".equals(parameter.get(0))) {
chessDAO.deleteGame(id);
}
}

private void saveGame(final long id, final ChessGame chessGame, final List<String> parameter) throws SQLException {
if ("save".equals(parameter.get(0))) {
chessDAO.addBoard(id, chessGame);
}
}


private ResponseDto unknown(RequestDto requestDto) {
return new ResponseDto("알 수 없는 명령어 입니다.");
}

public boolean isEnd() {
// return chessGame.isEnd();
return false;
public boolean isEnd(long id) {
return chessGames.get(id).isEnd();
}

public ResponseDto getRoomId() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/chess/view/InputView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package chess.view;

import chess.command.Command;
import chess.controller.dto.RequestDto;
import chess.service.Command;

import java.util.Arrays;
import java.util.List;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/chessGame.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
document.getElementById("{{turn.key}}-player-turn").innerText = '현재 턴'




</script>

<script>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</head>

<body>
<form action="/loadChessGame" method="post" id="load-form">
<input id="idInput" type="hidden" name="id" value="{{id}}">
<form action="/loadChessGame" id="load-form" method="post">
<input id="idInput" name="id" type="hidden" value="{{id}}">
</form>
</body>

Expand Down

0 comments on commit 2f4375b

Please sign in to comment.