Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/newbranchnetwork' into newbranch…
Browse files Browse the repository at this point in the history
…network

# Conflicts:
#	src/main/java/model/Board.java
#	src/main/java/servercontroller/GameController.java
  • Loading branch information
bhrdbn committed Jul 21, 2021
2 parents 0afbf5e + 677767c commit cafc710
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 107 deletions.
88 changes: 23 additions & 65 deletions src/main/java/clientcontroller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand Down
35 changes: 12 additions & 23 deletions src/main/java/clientview/Duel.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,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()) {
Expand Down Expand Up @@ -119,9 +119,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");
}
Expand All @@ -133,9 +133,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) {
Expand Down Expand Up @@ -166,20 +166,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));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public Board(PlayBoard playBoardPlayer, PlayBoard playBoardOpponent) {
@Override
public String toString() {
String board = "";
// board += getOpponentPlayBoardByTurn().rotateToString();
board += playBoard2.rotateToString();
board += "\n----------------------\n";
// board += getPlayBoardByTurn().toString();
board += playBoard1.toString();
board += "\n\n----------------------\n\n";
return board;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sample/sample.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<Button layoutX="171.0" layoutY="21.0" mnemonicParsing="false" onMouseClicked="#rewatchPastGames" prefHeight="32.0" prefWidth="126.0" text="rewatchPastGames" />
<Button layoutX="553.0" layoutY="20.0" mnemonicParsing="false" onMouseClicked="#Back" prefHeight="39.0" prefWidth="75.0" text="back" />
</children>
</AnchorPane>
</AnchorPane>
10 changes: 2 additions & 8 deletions src/main/java/servercontroller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ public class Controller {
ArrayList<SpellCard> allSpells = new ArrayList<>();
ArrayList<TrapCard> allTraps = new ArrayList<>();
private static Controller loginController = null;
int rounds;
Player firstWinner;
Player secondWinner;
Player thirdWinner;
int firstLp;
int secondLp;
int thirdLP;


private Controller() {
shopInit();
Expand Down Expand Up @@ -492,7 +486,7 @@ public String request(String token, String round) {
}


private String setBoard(String token, Player player) {
public String setBoard(String token, Player player) {
PlayBoard playBoard1 = new PlayBoard(player);
PlayBoard playBoard2 = new PlayBoard(GlobalVariable.getPlayers().get(token));
Board board = new Board(playBoard2, playBoard1);
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/servercontroller/GameController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package servercontroller;

import clientview.MainClient;
import clientview.Main;
import clientview.MainView;
import model.*;


public class GameController {
int rounds;
Player firstWinner;
Player secondWinner;
Player thirdWinner;
int firstLp;
int secondLp;
int thirdLP;
private static GameController duelController = null;
public static GameController getInstance() {
if (duelController == null)
Expand All @@ -25,15 +34,15 @@ else if (!((SpellCard) card).getIcon().equals("Ritual") || GlobalVariable.getBoa
return "you should ritual summon right now";
else {
System.out.println("please enter the cards(the number of cards) that you want to tribute");
String monster1 = MainClient.scanner.nextLine();
String monster2 = MainClient.scanner.nextLine();
String monster1 = Main.scanner.nextLine();
String monster2 = Main.scanner.nextLine();
if (!isLevelMatched(monster1, monster2, card, token))
return "selected monsters levels don't match with ritual monster";
else {
tributeMonsters(Integer.parseInt(monster1), token);
tributeMonsters(Integer.parseInt(monster2), token);
System.out.println("please enter the attack or defence status");
String status = MainClient.scanner.nextLine();
String status = Main.scanner.nextLine();
if (status.equals("attacking")) {
((MonsterCard) card).setIsAttack(true);
card.setSide(false);
Expand Down Expand Up @@ -449,7 +458,7 @@ else if (((MonsterCard) GlobalVariable.getBoards().get(token).getPlayBoardByTurn
if (countNokhodi(token) == 5)
return "there are not enough cards for tribute";
else {
String s = MainClient.scanner.nextLine();
String s = Main.scanner.nextLine();
if (s.equals("cancel")) {
deselect(token);
return "";
Expand Down Expand Up @@ -547,7 +556,7 @@ else if (((MonsterCard) GlobalVariable.getBoards().get(token).getPlayBoardByTurn
getPlayBoardByTurn().getSelectedCard().getName().equals("BeastKingBarbaros")) {
int i;
System.out.println("please enter which mode you want to sacrifice press 1 else 0");
i = MainClient.scanner.nextInt();
i = Main.scanner.nextInt();
ActionMonster actionMonster = new ActionMonster();
if (i == 0) {
actionMonster.setAction(8, (MonsterCard) GlobalVariable.getBoards().get(token).
Expand All @@ -567,8 +576,8 @@ else if (((MonsterCard) GlobalVariable.getBoards().get(token).getPlayBoardByTurn
if (countNokhodi(token) > 3)
return "there are not enough cards for tribute";
else {
int monster = Integer.parseInt(MainClient.scanner.nextLine());
int monster1 = Integer.parseInt(MainClient.scanner.nextLine());
int monster = Integer.parseInt(Main.scanner.nextLine());
int monster1 = Integer.parseInt(Main.scanner.nextLine());
if (GlobalVariable.getBoards().get(token).getPlayBoardByTurn().getMonsters().get(monster - 1).getName().equals("nokhodi") ||
GlobalVariable.getBoards().get(token).getPlayBoardByTurn().getMonsters().get(monster1 - 1).getName().equals("nokhodi"))
return "there no monsters one this address";
Expand Down Expand Up @@ -940,8 +949,8 @@ public void activateCardAndChangeTurn(Card card, String token) {
System.out.println("now it will be " + GlobalVariable.getPlayers().get(token).getUsername() + " turn");
System.out.println(GlobalVariable.getBoards().get(token).getPlayBoardByTurn());
System.out.println("do you want to activate your trap and spell?");
String input = MainClient.scanner.nextLine();
String activation = MainClient.scanner.nextLine();
String input = Main.scanner.nextLine();
String activation = Main.scanner.nextLine();
if (input.equals("no")) {
System.out.println("now it will be " + GlobalVariable.getPlayers().get(token).getUsername() + " turn");
System.out.println(GlobalVariable.getBoards().get(token).getPlayBoardByTurn());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/serverview/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ else if(command.equals("show opponent graveyard"))
return GameController.getInstance().showOpponentGraveyard(parts[3]) + "\n" + GlobalVariable.getBoards().get(parts[3]).toString();
else if(command.equals("show card"))
return GameController.getInstance().showCard(parts[2]) + "\n" + GlobalVariable.getBoards().get(parts[2]).toString();
else if(command.equals("next phase"))
return GameController.getInstance().goNextPhase(parts[2], parts[3]) + "\n" + GlobalVariable.getBoards().get(parts[2]).toString();
// else if(command.equals("surrender"))
// return GameController.getInstance().setWin();
return "";
}
}

0 comments on commit cafc710

Please sign in to comment.