Skip to content

Commit

Permalink
-code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AHMHKashi committed Jun 26, 2021
1 parent b187725 commit 560d12f
Show file tree
Hide file tree
Showing 65 changed files with 247 additions and 257 deletions.
7 changes: 4 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import controller.User;
import controller.ApplicationManger;
import controller.User;
import model.UserData;
import model.cards.data.ReadMonsterCardsData;
import model.cards.data.ReadSpellTrapCardsData;

import java.io.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -16,7 +17,7 @@ public static void main(String[] args) {
ApplicationManger applicationManger = new ApplicationManger();
try {
firstSetup();
}catch (IOException e){
} catch (IOException e) {
System.out.println("ERROR: Couldn't load game!");
System.exit(-1);
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/controller/ApplicationManger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import view.menus.*;

import java.io.*;
import java.util.Locale;

public class ApplicationManger {
private static Scene currentScene;
private static User loggedInUser;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/controller/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import model.UserData;
import model.cards.data.CardData;
import model.cards.data.MonsterCardData;
import model.cards.data.SpellCardData;
import model.cards.data.TrapCardData;

import java.io.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;

public class DataManager {

Expand All @@ -28,7 +29,7 @@ public static void exportCard(CardData cardData) {
fileWriter.write(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(cardData));
fileWriter.close();
System.out.println("card exported successfully.");
}catch (IOException e) {
} catch (IOException e) {
System.out.println("the file isn't saved yet.");
}
}
Expand All @@ -44,7 +45,7 @@ public static void importCard(String cardName) {
JsonObject jsonObject = JsonParser.parseReader(fileReader).getAsJsonObject();
CardData cardData;
switch (jsonObject.get("cardType").toString().replaceAll("\"", "")) {
case "MONSTER" :
case "MONSTER":
cardData = new Gson().fromJson(fileData, MonsterCardData.class);
break;
case "SPELL":
Expand Down
1 change: 0 additions & 1 deletion src/main/java/controller/GamePlaySceneController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package controller;

import controller.gameplay.AI_Player;
import controller.gameplay.GameManager;
import model.Command;
import model.Deck;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/controller/ProfileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import model.Command;
import model.enums.CommandFieldType;
import model.enums.ProfileMessages;
import model.exceptions.ParseCommandException;
import view.menus.ProfileScene;

import java.util.HashMap;
import java.util.regex.Matcher;

import model.enums.ProfileMessages;

public class ProfileController {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/controller/RegisterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static int registerUser(String userInput) {
if (User.doesUsernameExists(registerCommand.getField("username")))
System.out.println("user with username " + registerCommand.getField("username") + " already exists");
else if (User.doesNicknameExists(registerCommand.getField("nickname")))
System.out.println("user with nickname "+ registerCommand.getField("nickname") +" already exists");
System.out.println("user with nickname " + registerCommand.getField("nickname") + " already exists");
else {
User user = new User(registerCommand.getField("username"), registerCommand.getField("nickname"), registerCommand.getField("password"));
System.out.println("user created successfully!");
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/controller/ShopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ public void buyCard(String cardName) {
CardData cardData = CardData.getCardByName(cardName);
if (cardData == null) {
shopScene.printMessage("there is no card with this name");
}
else if (activeUser.getUserData().getMoney() < cardData.getPrice()) {
} else if (activeUser.getUserData().getMoney() < cardData.getPrice()) {
shopScene.printMessage("you have not enough money");
shopScene.printMessage("your money is " + activeUser.getUserData().getMoney() + " card Price is " + cardData.getPrice());
}
else {
} else {
activeUser.getUserData().decreaseMoney(cardData.getPrice());
activeUser.getUserData().addCard(cardData.getCardId());
shopScene.printMessage("you bought " + cardName + " successfully.");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/controller/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public User(String username, String nickname, String password) {
allUser.add(this);
}

public User(UserData data){
public User(UserData data) {
userData = data;
allUser.add(this);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public void addDeck(Deck deck) {
userData.addDeck(deck);
}

public Deck getActiveDeck(){
public Deck getActiveDeck() {
return userData.getActiveDeck();
}

Expand All @@ -94,7 +94,7 @@ public String getUsername() {
return userData.getUsername();
}

public boolean haveThisCardFree(String cardName){
public boolean haveThisCardFree(String cardName) {
try {
return getCardsThatThereIsNotInAnyDeck().contains(Card.getCardIdByName(cardName));
} catch (Exception e) {
Expand All @@ -104,7 +104,7 @@ public boolean haveThisCardFree(String cardName){

public ArrayList<Integer> getCardsThatThereIsNotInAnyDeck() {
ArrayList<Integer> result = new ArrayList<>(userData.getMyCardsIds());
for (Deck deck : getDecks()){
for (Deck deck : getDecks()) {
deck.getMainDeckIds().forEach(result::remove);
deck.getSideDeckIds().forEach(result::remove);
}
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/controller/gameplay/AI_Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ private void setTraps() {
}
}

private void activateSpells(){
private void activateSpells() {
if (board.isSpellTrapZoneFull()) return;
ArrayList<Card> spellCards = new ArrayList<>();
spellCards.addAll(board.getHand().getAllCards().stream().filter(c -> c.getCardType() == CardType.SPELL).collect(Collectors.toList()));
ArrayList<Card> fieldCards = new ArrayList<>();
fieldCards.addAll(spellCards.stream().filter(c -> ((SpellCard)c).getData().getSpellProperty() == SpellTrapProperty.FIELD).collect(Collectors.toList()));
fieldCards.addAll(spellCards.stream().filter(c -> ((SpellCard) c).getData().getSpellProperty() == SpellTrapProperty.FIELD).collect(Collectors.toList()));
spellCards.removeAll(fieldCards);

while (!board.isSpellTrapZoneFull() && spellCards.size() > 0) {
Expand All @@ -101,7 +101,7 @@ private void activateSpells(){
}
}

if(fieldCards.size() > 0){
if (fieldCards.size() > 0) {
try {
gameManager.selectCard("--hand " + (board.getHand().getAllCards().indexOf(fieldCards.get(0)) + 1));
gameManager.activateCard();
Expand Down Expand Up @@ -139,12 +139,12 @@ private void summonMonster() {
}
}

private ArrayList<Integer> chooseTribute(int n){
private ArrayList<Integer> chooseTribute(int n) {
ArrayList<CardSlot> myMonsters = new ArrayList<>(board.getMonsterZone().stream().filter(c -> !c.isEmpty()).collect(Collectors.toList()));
myMonsters.sort(Comparator.comparing(c -> ((MonsterCard)c.getCard()).getData().getLevel()));
myMonsters.sort(Comparator.comparing(c -> ((MonsterCard) c.getCard()).getData().getLevel()));

ArrayList<Integer> result = new ArrayList<>();
for(int i=0; i<n; i++){
for (int i = 0; i < n; i++) {
result.add(board.getMonsterZone().indexOf(myMonsters.get(i)) + 1);
}

Expand All @@ -167,11 +167,11 @@ private void doAttack() {
System.out.println(a);
}*/

for(int i=0; i<attacks.size(); i++){
for (int i = 0; i < attacks.size(); i++) {
AttackResultCalculated attack = attacks.get(i);
if(attack.attacker.isAttackedThisTurn()) continue;
if(attack.attackValue() <= 0) break;
if(attack.attacked.getCardSlot().getZoneType() != ZoneType.MONSTER) continue;
if (attack.attacker.isAttackedThisTurn()) continue;
if (attack.attackValue() <= 0) break;
if (attack.attacked.getCardSlot().getZoneType() != ZoneType.MONSTER) continue;

try {
gameManager.selectCard("--monster " + (board.getMonsterZone().indexOf(attack.attacker.getCardSlot()) + 1));
Expand All @@ -181,10 +181,10 @@ private void doAttack() {
}
}

if(opponent.getPlayerBoard().numberOfMonstersInZone() == 0){
for (CardSlot cardSlot : myMonsters){
if(!cardSlot.isEmpty()){
if(!((MonsterCard)cardSlot.getCard()).isAttackedThisTurn()){
if (opponent.getPlayerBoard().numberOfMonstersInZone() == 0) {
for (CardSlot cardSlot : myMonsters) {
if (!cardSlot.isEmpty()) {
if (!((MonsterCard) cardSlot.getCard()).isAttackedThisTurn()) {
try {
gameManager.selectCard("--monster " + (board.getMonsterZone().indexOf(cardSlot) + 1));
gameManager.attackDirect();
Expand Down Expand Up @@ -238,7 +238,7 @@ public AttackResultCalculated(MonsterCard attacker, MonsterCard attacked) {
}
}

public int attackValue(){
public int attackValue() {
return player2LPDecrease - player1LPDecrease + (destroyCard2 ? 1 : 0) - (destroyCard1 ? 1 : 0);
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/controller/gameplay/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
import model.cards.Card;
import model.cards.MonsterCard;
import model.effectSystem.Effect;
import model.enums.CardStatus;
import model.enums.CommandFieldType;
import model.enums.Phase;
import model.enums.ZoneType;
import model.event.Event;
import model.event.EventNoParam;
import model.exceptions.ParseCommandException;
import model.gameplay.AttackResult;
import model.gameplay.CardSlot;
import model.gameplay.GameBoard;
import model.gameplay.Player;
import model.gameplay.*;
import model.enums.*;
import view.menus.GamePlayScene;

import java.util.ArrayList;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/model/Deck.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package model;

import controller.ApplicationManger;
import controller.DataManager;
import model.cards.Card;
import model.cards.data.CardData;

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/model/UserData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.google.gson.Gson;

import java.io.*;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class UserData {
Expand Down Expand Up @@ -41,7 +42,7 @@ public ArrayList<Deck> getDecks() {
return decks;
}

public void removeDeck(Deck deck){
public void removeDeck(Deck deck) {
decks.remove(deck);
save();
}
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/model/cards/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
import model.effectSystem.Effect;
import model.enums.CardStatus;
import model.enums.CardType;
import model.enums.ZoneType;
import model.event.Event;
import model.event.EventNoParam;
import model.gameplay.CardSlot;
import model.gameplay.Player;

import java.util.ArrayList;

public abstract class Card {
protected CardType cardType;
protected CardData cardData;
Expand All @@ -28,7 +24,7 @@ public abstract class Card {
protected EventNoParam onDestroy = new EventNoParam();


public static Card getCardByCardData(CardData data){
public static Card getCardByCardData(CardData data) {
Card card = null;

switch (data.getCardType()) {
Expand Down Expand Up @@ -107,9 +103,9 @@ public CardType getCardType() {
return cardType;
}

public void setup(Player owner){
public void setup(Player owner) {
cardOwner = owner;
for (Effect effect: cardData.getEffects()){
for (Effect effect : cardData.getEffects()) {
effect.setup();
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/model/cards/MonsterCard.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package model.cards;

import model.event.Event;
import model.cards.data.MonsterCardData;
import model.enums.CardStatus;
import model.enums.CardType;
import model.event.Event;
import model.gameplay.AttackResult;
import model.gameplay.Player;

Expand Down Expand Up @@ -60,7 +60,8 @@ public void onSummon() {
isAttackPosition = true;

}
public Event<Card> getFaceUp() {

public Event<Card> getFaceUp() {
return faceUp;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/cards/SpellCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public SpellCardData getData() {
return (SpellCardData) cardData;
}

public void activateEffect(){
for(Effect effect: cardData.getEffects()){
public void activateEffect() {
for (Effect effect : cardData.getEffects()) {
effect.activate();
}
activated = true;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/cards/TrapCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public TrapCardData getData() {
return (TrapCardData) cardData;
}

public void activateEffect(){
for(Effect effect: cardData.getEffects()){
public void activateEffect() {
for (Effect effect : cardData.getEffects()) {
effect.activate();
}
activated = true;
Expand Down
Loading

0 comments on commit 560d12f

Please sign in to comment.