From 677767cf9ef9b76a68c88eac5aa2d9e0a80a83e3 Mon Sep 17 00:00:00 2001 From: aylasalehi Date: Wed, 21 Jul 2021 19:51:23 +0430 Subject: [PATCH] edit --- .../java/clientcontroller/Controller.java | 88 ++--- src/main/java/clientview/Duel.java | 35 +- src/main/java/model/Board.java | 6 +- src/main/java/sample/sample.fxml | 2 +- .../java/servercontroller/Controller.java | 10 +- .../java/servercontroller/GameController.java | 345 ++++++------------ src/main/java/serverview/Main.java | 4 + 7 files changed, 157 insertions(+), 333 deletions(-) diff --git a/src/main/java/clientcontroller/Controller.java b/src/main/java/clientcontroller/Controller.java index 8b71243..6ec5ebd 100644 --- a/src/main/java/clientcontroller/Controller.java +++ b/src/main/java/clientcontroller/Controller.java @@ -541,40 +541,6 @@ public String selectOpponentField() { } } - // public String managePhase() { -// Phase phase = GlobalVariable.getBoard().getPhase(); -// switch (phase) { -// case DRAW: -// return "draw phase\n" + -// (GlobalVariable.getBoard().addToHand(GlobalVariable.getBoard().getPlayBoardByTurn())); -// case STANDBY: -// return "standby phase"; -// -// case MAIN1: -// return "1st Main phase"; -// -// case BATTLE: -// return "battle phase"; -// -// case MAIN2: -// return "2nd main phase"; -// -// case END: -// GlobalVariable.getBoard().changePhase(Phase.END); -// GlobalVariable.getBoard().getPlayBoardByTurn().setCardSummonedOrSet(false); -// GlobalVariable.getBoard().getPlayBoardByTurn().setSetSummonedMonster(null); -// GlobalVariable.getBoard().reverseTurn(); -// if (GlobalVariable.getBoard().getPlayBoardByTurn().getPlayer() instanceof AI) { -// return manageAIPhaseAndPlay(); -// } else return "End phase\n" + GlobalVariable.getBoard().getTurn().getNickname() + "'s turn" + "\n" + -// "draw phase\n" + -// (GlobalVariable.getBoard().addToHand(GlobalVariable.getBoard().getPlayBoardByTurn())); -// -// default: -// return ""; -// } -// } -// // public String manageAIPhaseAndPlay() { // String finalOut = "End phase\n" + GlobalVariable.getBoard().getTurn().getNickname() + "'s turn" + "\n" + // "draw phase\n" + @@ -723,17 +689,19 @@ public String selectOpponentField() { // GlobalVariable.setBoard(board); // } // -// public String goNextPhase() { -// if (GlobalVariable.getBoard().getPhase() == Phase.MAIN2 && (GlobalVariable.getBoard().isDeckFinished() || -// GlobalVariable.getBoard().getPlayBoardByTurn().getLifePoint() <= 0)) { -// lose(); -// -// } -// GlobalVariable.getBoard().changePhase(GlobalVariable.getBoard().getPhase()); -// return managePhase(); -// } -// -// + public String goNextPhase() { + try { + dataOutputStream.writeUTF("next phase " + boardToken + token); + dataOutputStream.flush(); + String result = dataInputStream.readUTF(); + return result; + } catch (IOException ioException) { + ioException.printStackTrace(); + return "exception"; + } + } + + public String deselect() { try { dataOutputStream.writeUTF("select -d " + boardToken); @@ -746,26 +714,16 @@ public String deselect() { } } -// public void setWin() { -// if (rounds == 1) { -// GlobalVariable.getBoard().getPlayBoardByTurn().getPlayer().increasePlayerMoney(100); -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().increasePlayerMoney(1000 + -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getLifePoint()); -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().increaseScore(1000); -// System.out.println(GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().getUsername() + " won the game : " + -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().getScore()); -// MainView.getInstance().run(); -// } else { -// GlobalVariable.getBoard().getPlayBoardByTurn().getPlayer().increasePlayerMoney(300); -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().increasePlayerMoney(3000 + -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getLifePoint()); -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().increaseScore(3000); -// System.out.println(GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().getUsername() + " won whole match : " + -// GlobalVariable.getBoard().getOpponentPlayBoardByTurn().getPlayer().getScore()); -// MainView.getInstance().run(); -// } -// -// } + public void setWin() { + try { + dataOutputStream.writeUTF("surrender " + boardToken); + dataOutputStream.flush(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + + + } //// ** monster ba ehzare vizhe ro nazadam ** public String summon() { diff --git a/src/main/java/clientview/Duel.java b/src/main/java/clientview/Duel.java index 350ab24..3345b87 100644 --- a/src/main/java/clientview/Duel.java +++ b/src/main/java/clientview/Duel.java @@ -87,9 +87,9 @@ else if (matcherSelect.find()) { selectOpponentMonster(Integer.parseInt(matcherSelect6.group(1))); } else if (matcherback.find()) MenuHandler.runBack(Menu.DUEL); -// else if (nextPhase.find()) { -// goNextPhase(); -// } + else if (nextPhase.find()) { + goNextPhase(); + } else if (matchersummon.find()) { summon(matchersummon); } else if (matcherSet.find()) { @@ -120,9 +120,9 @@ else if (matcherSetSpell.find()) else if(matcherSetTrap.find()){ setTrap(matcherSetTrap); } -// else if(surrender.find()){ -// setWin(); -// } + else if(surrender.find()){ + setWin(); + } else System.out.println("invalid command"); } @@ -134,9 +134,9 @@ public void setTrap(Matcher matcherSetTrap) { System.out.println(controller.setTrapCard()); } -// public void setWin(){ -// controller.setWin(); -// } + public void setWin(){ + controller.setWin(); + } public void activateEffect(Matcher activateEffect) { @@ -167,20 +167,9 @@ public void set() { System.out.println(controller.setMonster()); } -// public void newDuel(Matcher matcherPlayer, int flag) { -// if (flag == 0) -// System.out.println(controller.newDuel(Integer.parseInt -// (matcherPlayer.group(2)), matcherPlayer.group(1), GlobalVariable.getPlayer().getUsername())); -// else -// System.out.println(controller.getInstance().newDuel(Integer.parseInt -// (matcherPlayer.group(1)), matcherPlayer.group(2), GlobalVariable.getPlayer().getUsername())); -// System.out.println(GlobalVariable.getBoard().toString()); -// } -// -// public void goNextPhase() { -// System.out.println(controller.goNextPhase()); -// System.out.println(GlobalVariable.getBoard().toString()); -// } + public void goNextPhase() { + System.out.println(controller.goNextPhase()); + } public void selectOwnMonster(int number) { System.out.println(controller.selectOwnMonster(number)); diff --git a/src/main/java/model/Board.java b/src/main/java/model/Board.java index b960b6d..fc7edea 100644 --- a/src/main/java/model/Board.java +++ b/src/main/java/model/Board.java @@ -20,9 +20,11 @@ public Board(PlayBoard playBoardPlayer, PlayBoard playBoardOpponent) { @Override public String toString() { String board = ""; - board += getOpponentPlayBoardByTurn().rotateToString(); +// board += getOpponentPlayBoardByTurn().rotateToString(); + board += playBoard2.rotateToString(); board += "\n----------------------\n"; - board += getPlayBoardByTurn().toString(); +// board += getPlayBoardByTurn().toString(); + board += playBoard1.toString(); board += "\n\n----------------------\n\n"; return board; } diff --git a/src/main/java/sample/sample.fxml b/src/main/java/sample/sample.fxml index 8e8c549..fa6dd68 100644 --- a/src/main/java/sample/sample.fxml +++ b/src/main/java/sample/sample.fxml @@ -11,4 +11,4 @@