Skip to content

Commit

Permalink
✨ FEAT. 루미큐브 메인로직 구현
Browse files Browse the repository at this point in the history
예외처리 에러 구문 표시 및 게임 상태 enum 변경

Related to : #3
  • Loading branch information
junhaa committed Dec 16, 2023
1 parent 408a079 commit e2d94ff
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
51 changes: 42 additions & 9 deletions src/Controller/GameController.java
Original file line number Diff line number Diff line change
@@ -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; // 포트 번호
Expand All @@ -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];

Expand All @@ -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;
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/Model/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@
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;

public Game(){
players = new Player[GameController.MAX_PLAYER_COUNT];
this.board = new Board();
this.currentPlayerIndex = 0;
gameState = GameState.IN_PROGRESS;
}


Expand Down Expand Up @@ -81,15 +75,15 @@ public void start(){

// 게임 진행 상태를 관리하는 메서드
public void manageGameProgress() {
while (gameState == GameState.IN_PROGRESS) {
while (true) {
Player currentPlayer = players[currentPlayerIndex];
performPlayerTurn(currentPlayer);


// 게임이 끝난 경우
if (checkWinCondition(currentPlayer)) {
//TODO
gameState = GameState.FINISHED;
break;
}


Expand Down
3 changes: 0 additions & 3 deletions src/View/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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주소를 확인해주세요.");
}
}
});

Expand Down

0 comments on commit e2d94ff

Please sign in to comment.