Skip to content

Commit

Permalink
-code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AHMHKashi committed Jul 21, 2021
1 parent ef99c15 commit a8953e9
Show file tree
Hide file tree
Showing 89 changed files with 419 additions and 440 deletions.
2 changes: 1 addition & 1 deletion Client/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.google.gson.*;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import controller.ApplicationManger;
import controller.User;
Expand Down
4 changes: 2 additions & 2 deletions Client/src/main/java/controller/CardCreatorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class CardCreatorController {

private User activeUser;
private CardCreatorScene scene;
private final User activeUser;
private final CardCreatorScene scene;

public CardCreatorController(CardCreatorScene cardCreatorScene) {
activeUser = ApplicationManger.getLoggedInUser();
Expand Down
15 changes: 8 additions & 7 deletions Client/src/main/java/controller/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void importCard(String cardName) {

}

public static void importCardGraphic(String cardName){
public static void importCardGraphic(String cardName) {
File importDir = new File("importCards");
importDir.mkdir();
String fileLocation = "importCards/" + cardName + ".json";
Expand All @@ -85,15 +85,16 @@ public static void importCardGraphic(String cardName){
cardData = new ReadSpellTrapCardsData().readACardData(fileData.split(","));
break;
default:
CardOptionsScene.setMessage("couldn't find card type");
CardOptionsScene.setMessage("couldn't find card type");
return;
}
CardOptionsScene.setMessage("card imported successfully.");
CardOptionsScene.setMessage("card imported successfully.");
} catch (IOException e) {
CardOptionsScene.setMessage(e.getMessage());
CardOptionsScene.setMessage(e.getMessage());
}
}
public static void exportCardGraphic(CardData cardData){

public static void exportCardGraphic(CardData cardData) {
File exportDir = new File("exportedCards");
exportDir.mkdir();
String fileLocation = "exportedCards/" + cardData.getCardName() + ".json";
Expand All @@ -103,9 +104,9 @@ public static void exportCardGraphic(CardData cardData){
FileWriter fileWriter = new FileWriter(fileLocation);
fileWriter.write(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(cardData));
fileWriter.close();
CardOptionsScene.setMessage("card exported successfully.");
CardOptionsScene.setMessage("card exported successfully.");
} catch (IOException e) {
CardOptionsScene.setMessage("the file isn't saved yet.");
CardOptionsScene.setMessage("the file isn't saved yet.");
}
}
}
23 changes: 9 additions & 14 deletions Client/src/main/java/controller/DeckController.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import model.Command;
import model.Deck;
import model.cards.Card;
import model.cards.data.CardData;
import model.cards.data.SpellCardData;
import model.cards.data.TrapCardData;
Expand All @@ -23,7 +20,6 @@
import model.exceptions.ParseCommandException;
import view.menus.DeckMenu;
import view.menus.SceneName;
import view.menus.ShopScene;

import java.util.ArrayList;
import java.util.Comparator;
Expand Down Expand Up @@ -67,11 +63,11 @@ public void showMessage(String message) {
addOrDeleteMessage.setOpacity(1);
addOrDeleteMessage.setText(message);
if (message.equals("card removed from main deck successfully") ||
message.equals("card removed from side deck successfully")||
message.equals("card added to side deck successfully")||
message.equals("card removed from side deck successfully") ||
message.equals("card added to side deck successfully") ||
message.equals("card added to main deck successfully"))
addOrDeleteMessage.setTextFill(Color.GREEN);
else addOrDeleteMessage.setTextFill(Color.RED);
else addOrDeleteMessage.setTextFill(Color.RED);
}

public Button getGoToMainDeckButton() {
Expand All @@ -97,7 +93,7 @@ public void setDecks(VBox scrollPane, ArrayList<Deck> decks) {
hBox.getChildren().add(0, deckButton);
hBox.getChildren().add(1, deleteButton);
System.out.println(ApplicationManger.getLoggedInUser().getUserData().getActiveDeck());
if (ApplicationManger.getLoggedInUser().getUserData().isThereADeckThatActivated()&&
if (ApplicationManger.getLoggedInUser().getUserData().isThereADeckThatActivated() &&
ApplicationManger.getLoggedInUser().getUserData().getActiveDeck().getName().equals(deck.getName())) {
Label setActiveLabel = new Label();
setActiveLabel.setText("active");
Expand Down Expand Up @@ -207,12 +203,11 @@ public Label getMessage() {

public void nextDeckCreate() {
String deckName = deckNameTextField.getText();
if (deckName.equals("")){
if (deckName.equals("")) {
message.setTextFill(Color.RED);
message.setOpacity(1);
message.setText("You have not entered any names");
}
else {
} else {
if (Deck.isThereADeckWithThisName(deckName)) {
message.setTextFill(Color.RED);
message.setOpacity(1);
Expand Down
1 change: 0 additions & 1 deletion Client/src/main/java/controller/FirstSceneController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import view.menus.SceneName;

public class FirstSceneController {
Expand Down
9 changes: 5 additions & 4 deletions Client/src/main/java/controller/GamePlaySceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class GamePlaySceneController {
}};
private static int currentRound;
private boolean isDuelStarted = false;
private GamePlayScene scene;
private final GamePlayScene scene;
private GameManager gameManager;
private DuelData currentDuelData;

Expand Down Expand Up @@ -126,9 +126,10 @@ public void gameFinished(int winnerNumber, int player1LP, int player2LP) {
}

public static class DuelData {
private int rounds;
private boolean isPlayer;
private UserData firstPlayer, secondPlayer;
private final int rounds;
private final boolean isPlayer;
private final UserData firstPlayer;
private final UserData secondPlayer;

private int firstPlayerWins, secondPlayerWins;
private int maxLP1, maxLP2;
Expand Down
9 changes: 3 additions & 6 deletions Client/src/main/java/controller/ImportController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package controller;

import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import model.cards.data.CardData;
import view.menus.ImportScene;

import java.awt.*;

public class ImportController {

private ImportScene importScene;
private final ImportScene importScene;

public ImportController(ImportScene importScene) {
this.importScene = importScene;
Expand All @@ -27,7 +23,8 @@ public void exportCard(String cardName) {
}
DataManager.exportCard(cardData);
}
public void f(){

public void f() {

}

Expand Down
2 changes: 1 addition & 1 deletion Client/src/main/java/controller/ProfileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class ProfileController {

private User activeUser;
private ProfileScene profileScene;
private final ProfileScene profileScene;

public ProfileController(ProfileScene profileScene) {
this.activeUser = ApplicationManger.getLoggedInUser();
Expand Down
14 changes: 2 additions & 12 deletions Client/src/main/java/controller/RegisterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,20 @@
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import model.Command;
import model.UserData;
import model.cards.data.CardData;
import model.enums.ChatType;
import model.enums.CommandFieldType;
import model.exceptions.ParseCommandException;
import view.menus.SceneName;
import view.menus.ShopScene;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;

public class RegisterController {
public TextField usernameOfSignup;
Expand Down Expand Up @@ -138,8 +129,7 @@ public void nextOfSignup(ActionEvent actionEvent) throws Exception {
FileWriter userFile = new FileWriter("users/" + usernameOfSignup.getText() + ".json");
userFile.write(new Gson().toJson(user.getUserData()));
userFile.close();
}
else {
} else {
errorOfSignup.setText(message);
errorOfSignup.setTextFill(Color.RED);
}
Expand Down Expand Up @@ -188,7 +178,7 @@ public void nextOfLogin(ActionEvent actionEvent) {
System.out.println(ApplicationManger.getServerResponse("scoreboard", "scoreboard", null));
HashMap<String, String> data2 = new HashMap<>();
data2.put("type", ChatType.SEND.toString());
data2.put("message", "this is a message");;
data2.put("message", "this is a message");
System.out.println(ApplicationManger.getServerResponse("lobby", "send", data2));
ApplicationManger.goToScene1(SceneName.MAIN_MENU, false);
}
Expand Down
1 change: 0 additions & 1 deletion Client/src/main/java/controller/ShopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
Expand Down
3 changes: 0 additions & 3 deletions Client/src/main/java/controller/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import model.Deck;
import model.UserData;
import model.cards.Card;
import model.enums.ChatType;

import java.util.ArrayList;

Expand Down Expand Up @@ -122,7 +121,5 @@ public static void deleteAccount(User user) {
}




}

11 changes: 6 additions & 5 deletions Client/src/main/java/controller/gameplay/AI_Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import java.util.stream.Collectors;

public class AI_Player {
private Deck deck = new Deck("myDeck", "AI");
private static UserData data = new UserData("AI", "AI", "@A@I@");
private final Deck deck = new Deck("myDeck", "AI");
private static final UserData data = new UserData("AI", "AI", "@A@I@");
private Player playerObject;
private Player opponent;
private PlayerBoard board;
private GameManager gameManager;
private final GameManager gameManager;

{
Integer[] cards = {31, 31, 31, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13};
Expand Down Expand Up @@ -56,7 +56,7 @@ public void playATurn() {
activateSpells();
summonMonster();
Thread.sleep(1000);
if(gameManager.getTurnNumber() != 1){
if (gameManager.getTurnNumber() != 1) {
gameManager.goToNextPhase();
doAttack();
Thread.sleep(1000);
Expand Down Expand Up @@ -216,7 +216,8 @@ private class AttackResultCalculated {
private int player2LPDecrease = 0;
private boolean destroyCard1 = false;
private boolean destroyCard2 = false;
private MonsterCard attacker, attacked;
private final MonsterCard attacker;
private final MonsterCard attacked;

public AttackResultCalculated(MonsterCard attacker, MonsterCard attacked) {
this.attacker = attacker;
Expand Down
29 changes: 15 additions & 14 deletions Client/src/main/java/controller/gameplay/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,31 @@ public static GameManager getInstance() {
return instance;
}

private Player player1, player2;
private final Player player1;
private final Player player2;
private int turnNumber, currentPlayerTurn;
private Phase currentPhase;
private GameBoard gameBoard;
private final GameBoard gameBoard;

private CardSlotAddress currentSelectedCardAddress;
private Card currentSelectedCard;

private GamePlayScene scene;
private GamePlaySceneController sceneController;
private final GamePlayScene scene;
private final GamePlaySceneController sceneController;

private Event<Card> onAnSpellActivated = new Event<>();
private Event<AttackResult> onWantAttack = new Event<>();
private Event<Card> onSummonACard = new Event<>();
private Event<Card> onFlipSummon = new Event<>();
private EventNoParam onChangeTurn = new EventNoParam();
private final Event<Card> onAnSpellActivated = new Event<>();
private final Event<AttackResult> onWantAttack = new Event<>();
private final Event<Card> onSummonACard = new Event<>();
private final Event<Card> onFlipSummon = new Event<>();
private final EventNoParam onChangeTurn = new EventNoParam();
protected Event<AttackResult> destroyAMonster = new Event<>();

private boolean isFirstSetup = false;
private final boolean isFirstSetup = false;

private boolean canAttack = true;


private boolean isAI;
private final boolean isAI;
private AI_Player ai;

public GameManager(boolean isPlayer, UserData user1, UserData user2, GamePlayScene scene, GamePlaySceneController gamePlaySceneController) {
Expand Down Expand Up @@ -583,9 +584,9 @@ public void finishGame(int winnerNumber) {
}

public class CardSlotAddress {
private boolean forOpponent;
private ZoneType zone;
private int number;
private final boolean forOpponent;
private final ZoneType zone;
private final int number;

public CardSlotAddress(boolean forOpponent, ZoneType zone, int number) {
this.forOpponent = forOpponent;
Expand Down
2 changes: 1 addition & 1 deletion Client/src/main/java/model/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.regex.Pattern;

public class Command {
private HashMap<String, String> fieldValues;
private final HashMap<String, String> fieldValues;

public Command(HashMap<String, String> fieldValues) {
this.fieldValues = fieldValues;
Expand Down
Loading

0 comments on commit a8953e9

Please sign in to comment.