Skip to content

Commit

Permalink
reformat code & make ready for presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazlghalandary committed Jul 10, 2021
1 parent ffc9664 commit a6c1db1
Show file tree
Hide file tree
Showing 35 changed files with 301 additions and 367 deletions.
6 changes: 3 additions & 3 deletions src/main/java/yugioh/controller/CheatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public String selectHandForce(String cardName, GameController gameController) th
return response;
}

public String addOptionalCardAndSelect(String cardName, GameController gameController,boolean shouldBeSelected) throws GameException {
public String addOptionalCardAndSelect(String cardName, GameController gameController, boolean shouldBeSelected) throws GameException {
Card toBeAdded = Card.getNewCardObjectByName(cardName);
if (toBeAdded == null)
throw new GameException(Responses.NO_CARD_EXISTS.response);
gameController.getDrawPhaseController().addCardToHandDeck(gameController.getCurrentTurnPlayer(), toBeAdded,shouldBeSelected);
gameController.getDrawPhaseController().addCardToHandDeck(gameController.getCurrentTurnPlayer(), toBeAdded, shouldBeSelected);
return "new card added to the hand and selected: " + cardName;
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public String processCommand(String command) {
} else if (command.matches(GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex)) {
Matcher matcher = ViewInterface.getCommandMatcher(command, GameRegexes.CHEAT_ADD_OPTIONAL_CARD.regex);
try {
response = addOptionalCardAndSelect(matcher.group(1), Duel.getGameController(),false);
response = addOptionalCardAndSelect(matcher.group(1), Duel.getGameController(), false);
} catch (GameException e) {
response = e.toString();
}
Expand Down
106 changes: 54 additions & 52 deletions src/main/java/yugioh/controller/DataBaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,20 @@ public static void saveUserInfo(User user) throws IOException {
}

public static void saveCardInfo(Card card) throws IOException {
// writeJSON(card,"src\\resources\\cards\\" + card.getName() + ".json");
// writeJSON(card,"src\\resources\\cards\\" + card.getName() + ".json");
if (card.getCardKind() == Card.Kind.MAGIC) {
SpellAndTrap spellAndTrap = (SpellAndTrap) card;
writeJSON(spellAndTrap, "src\\resources\\cards\\SpellAndTraps\\" + card.getName() + ".json");
} else {
Monster monster = (Monster) card;
if(!card.isCustom)
writeJSON(monster, "src\\resources\\cards\\Monsters\\" + card.getName() + ".json");
else{
if (!card.isCustom)
writeJSON(monster, "src\\resources\\cards\\Monsters\\" + card.getName() + ".json");
else {
writeJSON(monster, "src\\resources\\cards\\Monsters\\Customs\\" + card.getName() + ".json");
}
}
}
public void setImportExportMenuBackground(){
MediaPlayer mediaPlayer = new MediaPlayer(new Media(new File("src\\resources\\yugioh\\Backgrounds\\main.mp4").toURI().toString()));
mediaPlayer.play();
mediaPlayer.setCycleCount(-1);
importExportMenuBackground.setMediaPlayer(mediaPlayer);
}

public static void writeFile(String fileAddress, String content) throws IOException {
FileWriter writer = new FileWriter(fileAddress);
writer.write(content);
Expand All @@ -118,21 +113,21 @@ public static void usersDataBaseInitialization() throws FileNotFoundException {
User.setAllUsers(dataBaseUsers);
}

public static void cardsDataBaseInitialization()throws FileNotFoundException {
public static void cardsDataBaseInitialization() throws FileNotFoundException {
initializeMonsterCards();
initializeMagicCards();
}

private static void initializeMonsterCards() throws FileNotFoundException{
File cardsFolder=new File("src\\resources\\cards\\Monsters\\Customs");
private static void initializeMonsterCards() throws FileNotFoundException {
File cardsFolder = new File("src\\resources\\cards\\Monsters\\Customs");
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
for(File file:cardsFolder.listFiles()){
if(file.getPath().endsWith(".json")){
for (File file : cardsFolder.listFiles()) {
if (file.getPath().endsWith(".json")) {
BufferedReader bufferedReader = new BufferedReader(
new FileReader(file.getPath())
);
Monster monster=gson.fromJson(bufferedReader,Monster.class);
Monster monster = gson.fromJson(bufferedReader, Monster.class);
Card.allCards.add(monster);
}
}
Expand Down Expand Up @@ -179,7 +174,7 @@ private static void initializeMonsterCards() throws FileNotFoundException{
Card CommandKnight = new CommandKnight();
}

private static void initializeMagicCards()throws FileNotFoundException {
private static void initializeMagicCards() throws FileNotFoundException {
// File cardsFolder=new File("src\\resources\\cards\\SpellAndTraps");
// GsonBuilder builder = new GsonBuilder();
// Gson gson = builder.create();
Expand All @@ -192,41 +187,48 @@ private static void initializeMagicCards()throws FileNotFoundException {
// Card.allCards.add(spellAndTrap);
// }
// }
Card TrapHole = new TrapHole();
Card MirrorForce = new MirrorForce();
Card MagicCylinder = new MagicCylinder();
Card MindCrush = new MindCrush();
Card TorrentialTribute = new TorrentialTribute();
Card TimeSeal = new TimeSeal();
Card NegateAttack = new NegateAttack();
Card SolemnWarning = new SolemnWarning();
Card MagicJamamer = new MagicJamamer();
Card CallofTheHaunted = new CallofTheHaunted();
Card VanitysEmptiness = new VanitysEmptiness();
Card WallofRevealingLight = new WallofRevealingLight();
Card MonsterReborn = new MonsterReborn();
Card Terraforming = new Terraforming();
Card PotofGreed = new PotofGreed();
Card Raigeki = new Raigeki();
Card ChangeofHeart = new ChangeofHeart();
Card SwordsofRevealingLight = new SwordsofRevealingLight();
Card HarpiesFeatherDuster = new HarpiesFeatherDuster();
Card DarkHole = new DarkHole();
Card SupplySquad = new SupplySquad();
Card SpellAbsorption = new SpellAbsorption();
Card Messengerofpeace = new Messengerofpeace();
Card TwinTwisters = new TwinTwisters();
Card Mysticalspacetyphoon = new Mysticalspacetyphoon();
Card Ringofdefense = new Ringofdefense();
Card Yami = new Yami();
Card Forest = new Forest();
Card ClosedForest = new ClosedForest();
Card Umiiruka = new Umiiruka();
Card Swordofdarkdestruction = new Swordofdarkdestruction();
Card BlackPendant = new BlackPendant();
Card UnitedWeStand = new UnitedWeStand();
Card MagnumShield = new MagnumShield();
Card AdvancedRitualArt = new AdvancedRitualArt();
Card TrapHole = new TrapHole();
Card MirrorForce = new MirrorForce();
Card MagicCylinder = new MagicCylinder();
Card MindCrush = new MindCrush();
Card TorrentialTribute = new TorrentialTribute();
Card TimeSeal = new TimeSeal();
Card NegateAttack = new NegateAttack();
Card SolemnWarning = new SolemnWarning();
Card MagicJamamer = new MagicJamamer();
Card CallofTheHaunted = new CallofTheHaunted();
Card VanitysEmptiness = new VanitysEmptiness();
Card WallofRevealingLight = new WallofRevealingLight();
Card MonsterReborn = new MonsterReborn();
Card Terraforming = new Terraforming();
Card PotofGreed = new PotofGreed();
Card Raigeki = new Raigeki();
Card ChangeofHeart = new ChangeofHeart();
Card SwordsofRevealingLight = new SwordsofRevealingLight();
Card HarpiesFeatherDuster = new HarpiesFeatherDuster();
Card DarkHole = new DarkHole();
Card SupplySquad = new SupplySquad();
Card SpellAbsorption = new SpellAbsorption();
Card Messengerofpeace = new Messengerofpeace();
Card TwinTwisters = new TwinTwisters();
Card Mysticalspacetyphoon = new Mysticalspacetyphoon();
Card Ringofdefense = new Ringofdefense();
Card Yami = new Yami();
Card Forest = new Forest();
Card ClosedForest = new ClosedForest();
Card Umiiruka = new Umiiruka();
Card Swordofdarkdestruction = new Swordofdarkdestruction();
Card BlackPendant = new BlackPendant();
Card UnitedWeStand = new UnitedWeStand();
Card MagnumShield = new MagnumShield();
Card AdvancedRitualArt = new AdvancedRitualArt();
}

public void setImportExportMenuBackground() {
MediaPlayer mediaPlayer = new MediaPlayer(new Media(new File("src\\resources\\yugioh\\Backgrounds\\main.mp4").toURI().toString()));
mediaPlayer.play();
mediaPlayer.setCycleCount(-1);
importExportMenuBackground.setMediaPlayer(mediaPlayer);
}

public String readFileContent(String address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void activateTrapIfCanBeActivated(GameController gameController, boolean
}
}
new Thread(() -> {
Platform.runLater(()->{
Platform.runLater(() -> {
while (!gameController.getGameMenuController().choiceHasBeenMade ||
gameController.getGameMenuController().shouldActivateEffectsNow == true) {
}
Expand Down Expand Up @@ -194,7 +194,8 @@ private String attackToDefensiveHiddenCell(Cell attackerCell, Cell attackedCell,
response += Marshmallon.handleEffect(gameController, attackerCell, attackedCell);
if (!Marshmallon.isMarshmallon(attackedCell)) {
Rectangle graveyard = GameMenuController.getGameMenuController().rivalGraveyard;
if (CardActionsMenu.isBoardInverse()) graveyard = GameMenuController.getGameMenuController().userGraveyard;
if (CardActionsMenu.isBoardInverse())
graveyard = GameMenuController.getGameMenuController().userGraveyard;
Rectangle finalGraveyard = graveyard;
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), event -> {
moveCardToGraveyard(attackedCell, finalGraveyard, gameController.currentTurnOpponentPlayer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,59 @@
package yugioh.controller.gamephasescontrollers;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.control.ScrollPane;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import yugioh.model.board.Cell;
import yugioh.model.exceptions.GameException;
import yugioh.view.gamephases.CardSelectionMenu;
import yugioh.view.gamephases.Duel;

import java.awt.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

public class CardSelectionMenuController implements Initializable {
public ScrollPane scrollBar;
public static ArrayList<Cell> cardsToShow=new ArrayList<>();
public static ArrayList<Cell> cardsToShow = new ArrayList<>();

static {

}

public ScrollPane scrollBar;

public static void setCardsToShow(ArrayList<Cell> cardsToShow) {
CardSelectionMenuController.cardsToShow = cardsToShow;
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
GridPane cardsPane = new GridPane();
cardsPane.setHgap(10);
cardsPane.setVgap(10);
cardsPane.setPadding(new Insets(10, 10, 10, 10));
for(Cell cell : cardsToShow){
Rectangle rectangle =cell.getCellRectangle();
for (Cell cell : cardsToShow) {
Rectangle rectangle = cell.getCellRectangle();
rectangle.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
Cell.setSelectedCell(Cell.getSelectedCellByRectangle(rectangle));
GameController gameController= Duel.getGameController();
try {
gameController.getMainPhase1Controller().specialSummon(gameController);
} catch (GameException e) {
e.printStackTrace();
}
GameController gameController = Duel.getGameController();
try {
gameController.getMainPhase1Controller().specialSummon(gameController);
} catch (GameException e) {
e.printStackTrace();
}
CardSelectionMenu.cardSelectionStage.close();
Cell.deselectCell();
gameController.changeTurn(true,true);
Cell.deselectCell();
gameController.changeTurn(true, true);
}
});
cardsPane.getChildren().add(cell.getCellRectangle());
}
scrollBar.contentProperty().set(cardsPane);
}

public static void setCardsToShow(ArrayList<Cell> cardsToShow) {
CardSelectionMenuController.cardsToShow = cardsToShow;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public DrawPhaseController(GameController gameController) {
this.gameController = gameController;
}

public void addCardToHandDeck(Player player, Card toBeAdded,boolean shouldBeSelected) {
Cell cell=new Cell(toBeAdded);
if(shouldBeSelected){
public void addCardToHandDeck(Player player, Card toBeAdded, boolean shouldBeSelected) {
Cell cell = new Cell(toBeAdded);
if (shouldBeSelected) {
Cell.setSelectedCell(cell);
}
player.getGameBoard().addCardToHandDeck(toBeAdded,true);
player.getGameBoard().addCardToHandDeck(toBeAdded, true);
}

public String removeFirstDeckCardFromDeckToPlay(Player player) throws GameException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import yugioh.model.board.GameBoard;
import yugioh.model.cards.Card;
import yugioh.model.cards.Deck;
import yugioh.model.cards.SpellAndTrap;
import yugioh.model.exceptions.GameException;
import yugioh.view.GameRegexes;
import yugioh.view.ViewInterface;
Expand All @@ -36,8 +35,6 @@
import java.net.URL;
import java.util.ArrayList;

import static yugioh.view.SoundPlayable.playButtonSound;

public class GameController {

public Player currentTurnPlayer;
Expand Down Expand Up @@ -204,8 +201,8 @@ public void deselect() throws GameException {
public void changePhase() {
// Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(3.5), event -> {
CardActionsMenu.close();
// if (isGameEnded()) {
endGameRound();
// if (isGameEnded()) {
endGameRound();
// return;
// }
switch (currentPhase) {
Expand Down Expand Up @@ -244,12 +241,12 @@ public void changePhase() {
}

public void changeTurn(boolean isTemporary, boolean backToPlayer) {
if(isTemporary){
Platform.runLater(()->{
if (isTemporary) {
Platform.runLater(() -> {
if (isTemporary && !backToPlayer) {
ViewInterface.showResult("now it will be " + currentTurnOpponentPlayer.getUser().getNickname() + "’s turn");
ViewInterface.showResult(mainPhase1Controller.showGameBoard(currentTurnOpponentPlayer, currentTurnPlayer));
Toast.makeText(WelcomeMenu.getStage(),"now it will be " + currentTurnOpponentPlayer.getUser().getNickname() + "’s turn");
Toast.makeText(WelcomeMenu.getStage(), "now it will be " + currentTurnOpponentPlayer.getUser().getNickname() + "’s turn");

gameMenuController.changeGameBoard();
gameMenuController.nextPhaseTriangle.setDisable(true);
Expand All @@ -275,8 +272,7 @@ public void changeTurn(boolean isTemporary, boolean backToPlayer) {
mainPhase1Controller.showGameBoard(currentTurnPlayer,
currentTurnOpponentPlayer);
});
}
else {
} else {
gameMenuController.changeGameBoard();
Player player = currentTurnPlayer;
currentTurnPlayer = currentTurnOpponentPlayer;
Expand Down Expand Up @@ -304,21 +300,21 @@ public void activateTrapEffect(ArrayList<String> trapsCanBeActivated) {
Pane pane = FXMLLoader.load(url);
Scene scene = WelcomeMenu.createScene(pane);
activateStage.setScene(scene);
Button yesButton = (Button) ((HBox)((VBox)pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(0);
Button noButton = (Button) ((HBox)((VBox)pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(1);
Button yesButton = (Button) ((HBox) ((VBox) pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(0);
Button noButton = (Button) ((HBox) ((VBox) pane.getChildren().get(0)).getChildren().get(1)).getChildren().get(1);
yesButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
activateStage.close();
gameMenuController.choiceHasBeenMade=true;
gameMenuController.shouldActivateEffectsNow=true;
gameMenuController.canBeActivatedCards=trapsCanBeActivated;
gameMenuController.choiceHasBeenMade = true;
gameMenuController.shouldActivateEffectsNow = true;
gameMenuController.canBeActivatedCards = trapsCanBeActivated;
}
});
noButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
gameMenuController.choiceHasBeenMade=true;
gameMenuController.choiceHasBeenMade = true;
activateStage.close();
}
});
Expand Down Expand Up @@ -417,7 +413,7 @@ public void endGameRound() {
ViewInterface.showResult(response);
isGameEnded = true;
try {
new EndOfGameMenu().execute(response,true);
new EndOfGameMenu().execute(response, true);
new DuelMenu().execute();
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -429,8 +425,8 @@ public void endGameRound() {
//changeCards(currentTurnPlayer);
//changeCards(currentTurnOpponentPlayer);
try {
new EndOfGameMenu().execute(response,false);
}catch (Exception e){
new EndOfGameMenu().execute(response, false);
} catch (Exception e) {
e.printStackTrace();
}

Expand Down
Loading

0 comments on commit a6c1db1

Please sign in to comment.