From e2d94ff8923693139458e203b182ff98871112ac Mon Sep 17 00:00:00 2001 From: junhaa <2171326@hansung.ac.kr> Date: Sun, 17 Dec 2023 04:28:11 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20FEAT.=20=EB=A3=A8=EB=AF=B8?= =?UTF-8?q?=ED=81=90=EB=B8=8C=20=EB=A9=94=EC=9D=B8=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 예외처리 에러 구문 표시 및 게임 상태 enum 변경 Related to : #3 --- src/Controller/GameController.java | 51 ++++++++++++++++++++++++------ src/Model/Game.java | 10 ++---- src/View/GameView.java | 3 -- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/Controller/GameController.java b/src/Controller/GameController.java index b272489..160e555 100644 --- a/src/Controller/GameController.java +++ b/src/Controller/GameController.java @@ -1,14 +1,19 @@ package Controller; +import Exceptions.NotEmptySpaceException; +import Exceptions.OnProgressException; import Model.Player; import View.GameView; -import java.awt.*; import java.net.UnknownHostException; - // 서버 플레이어가 게임 진행을 관리 public class GameController { + + public enum GameState{ + IN_PROGRESS, FINISHED + } + private GameView view; public static final int PORT = 12345; // 포트 번호 @@ -24,6 +29,10 @@ public class GameController { public static final int HAND_HEIGHT = 2; public static final int HAND_WIDTH = 10; + public static GameState gameState = GameState.FINISHED; + + public Player curPlayer; + private Player[] players = new Player[MAX_PLAYER_COUNT]; @@ -36,27 +45,51 @@ public void start(){ view.startUI(); } + public Player getCurPlayer() { + return curPlayer; + } + + + public static GameState getGameState() { + return gameState; + } + + public static void setGameState(GameState gameState) { + GameController.gameState = gameState; + } + + protected Player[] getPlayers() { + return players; + } + + protected void setPlayers(Player[] players) { + this.players = players; + } // 방 만드는 함수 - 서버 public void makeRoom() { - server = new Server(PORT); + server = new Server(PORT, this); isServer = true; // 뷰에서 화면 전환함수 view.changePanel("RoomPanel"); } - public boolean connectRoom(String address) { + public void connectRoom(String address) { client = new Client(); isServer = false; + String name = view.getNameTF().getText(); try { - client.connect(address, PORT); - CardLayout cardLayout = (CardLayout) view.getFrame().getContentPane().getLayout(); - cardLayout.next(view.getFrame().getContentPane()); + client.connect(address, PORT, name); + view.changePanel("RoomPanel"); + curPlayer = new Player(name); } catch (UnknownHostException e) { - return false; + view.getLoginErrorLabel().setText("IP주소로 접속할 수 없습니다. IP주소를 다시 확인해주세요."); + } catch (NotEmptySpaceException e){ + view.getLoginErrorLabel().setText("현재 방이 가득 차 참가할 수 없습니다."); + } catch (OnProgressException e){ + view.getLoginErrorLabel().setText("현재 게임이 진행 중인 방입니다."); } - return true; } } diff --git a/src/Model/Game.java b/src/Model/Game.java index 42f797c..2593c85 100644 --- a/src/Model/Game.java +++ b/src/Model/Game.java @@ -7,17 +7,12 @@ import java.util.Random; public class Game { - - private enum GameState{ - IN_PROGRESS, FINISHED - } // 게임 진행 플레이어들 private Player[] players; // 현재 보드판 private Board board; // 현재 턴인 플레이어의 인덱스 번호 private int currentPlayerIndex; - private GameState gameState; private int playerCount = 0; @@ -25,7 +20,6 @@ public Game(){ players = new Player[GameController.MAX_PLAYER_COUNT]; this.board = new Board(); this.currentPlayerIndex = 0; - gameState = GameState.IN_PROGRESS; } @@ -81,7 +75,7 @@ public void start(){ // 게임 진행 상태를 관리하는 메서드 public void manageGameProgress() { - while (gameState == GameState.IN_PROGRESS) { + while (true) { Player currentPlayer = players[currentPlayerIndex]; performPlayerTurn(currentPlayer); @@ -89,7 +83,7 @@ public void manageGameProgress() { // 게임이 끝난 경우 if (checkWinCondition(currentPlayer)) { //TODO - gameState = GameState.FINISHED; + break; } diff --git a/src/View/GameView.java b/src/View/GameView.java index f54071e..1d8cbcb 100644 --- a/src/View/GameView.java +++ b/src/View/GameView.java @@ -227,9 +227,6 @@ else if(address.isEmpty() || address.isBlank() || !isValidIP(address)){ } System.out.println(nameTF.getText().isEmpty()); System.out.println("IP주소 : " + addressTF.getText() + "로 연결을 시도합니다."); - if(!gameController.connectRoom(address)) { - loginErrorLabel.setText("IP주소로 연결할 수 없습니다. IP주소를 확인해주세요."); - } } });