Skip to content

Commit

Permalink
import and export deck
Browse files Browse the repository at this point in the history
  • Loading branch information
alikmr committed Jun 26, 2019
1 parent 8df2b5e commit 9510168
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
65 changes: 35 additions & 30 deletions src/Modules/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,52 @@ public static Card searchCard(Player player, int cardID) {
return null;
}

public static int exportDeck(Player player, Deck deckk) {
public static int exportDeck(Player player, String deckName) {
for (Deck deck : player.getAllDecks())
if (deck.getName().equals(deckk.getName())) {
if (deck.getName().equals(deckName)) {
CardBuilder.createJsonFileFromTheObject(deck);
return 1;
}
return 0;
}

public static int importDeck(Player player, String deckName) {
File folder = new File(".\\.\\decks\\");
File[] listOfFiles = folder.listFiles();
Deck deck = null;
for (File file : listOfFiles)
if (file.getName().contains(deckName)) {
try {
deck = CardBuilder.loadADeckFromJsonFile(deckName);
} catch (Exception e) {
System.out.println("shit");
return 0;
}
break;
}
if (deck == null)
return 0;

for (Card card : deck.getCards()) {
Boolean flag = true;
for (Card playerCard : player.getCollection())
if (playerCard.getName().equals(card.getName())) {
flag = false;
try {
File folder = new File("././decks/");
File[] listOfFiles = folder.listFiles();
Deck deck = null;
for (File file : listOfFiles)
if (file.getName().contains(deckName)) {
try {
deck = CardBuilder.loadADeckFromJsonFile(deckName);
} catch (Exception e) {
System.out.println("shit");
return 0;
}
break;
}
if (flag)
return -1;
if (deck == null)
return 0;

for (Card card : deck.getCards()) {
Boolean flag = true;
for (Card playerCard : player.getCollection())
if (playerCard.getName().equals(card.getName())) {
flag = false;
break;
}
if (flag)
return -1;
}
deck.setCards(new ArrayList<>());
deck.getCards().addAll(deck.getUnits());
deck.getCards().addAll(deck.getSpells());
deck.getCards().addAll(deck.getItems());
player.getAllDecks().add(deck);
return 1;
}catch (Exception e){
System.out.println("there is not a deck with this name");
}
deck.setCards(new ArrayList<>());
deck.getCards().addAll(deck.getUnits());
deck.getCards().addAll(deck.getSpells());
deck.getCards().addAll(deck.getItems());
player.getAllDecks().add(deck);
return 1;
}
}
20 changes: 16 additions & 4 deletions src/View/Viewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import Controller.*;
import Modules.*;
import Modules.Cell;
import Modules.Collection;
import com.sun.org.apache.xpath.internal.operations.Bool;
import javafx.animation.Animation;
import javafx.animation.PathTransition;
Expand Down Expand Up @@ -540,8 +541,19 @@ public void graphicShowCollection(){
importDeck.setTextFill(Color.rgb(116, 185, 255));
importDeck.setStyle("-fx-border-color: rgb(116, 185, 255);-fx-border-style: solid;-fx-border-width: 2px;-fx-padding: 2px 5px;-fx-border-radius: 5px;");

TextField importName = new TextField();
importName.setPromptText("imoprt name");
importName.relocate(26,664);
importName.setStyle("-fx-min-width: 105px;-fx-border-style: solid;-fx-border-width: 1px;-fx-border-color: #666;-fx-max-width: 105px;-fx-min-height: 37px;-fx-font-weight: bold;-fx-background-color: rgba(0,0,0,1);-fx-text-fill: white");

TextField exportName = new TextField();
exportName.setPromptText("export name");
exportName.relocate(122,664);
exportName.setStyle("-fx-min-width: 105px;-fx-border-style: solid;-fx-border-width: 1px;-fx-border-color: #666;-fx-max-width: 105px;-fx-min-height: 37px;-fx-font-weight: bold;-fx-background-color: rgba(0,0,0,1);-fx-text-fill: white");


Label exportDeck = new Label("Export Deck");
exportDeck.relocate(115,642);
exportDeck.relocate(125,642);
exportDeck.setTextFill(Color.rgb(85, 239, 196));
exportDeck.setStyle("-fx-border-color: rgb(85, 239, 196);-fx-border-style: solid;-fx-border-width: 2px;-fx-padding: 2px 5px;-fx-border-radius: 5px;");
exportDeck.setVisible(false);
Expand Down Expand Up @@ -569,7 +581,7 @@ public void graphicShowCollection(){
importDeck.setStyle("-fx-background-color: transparent;-fx-border-color: rgb(116, 185, 255);-fx-border-style: solid;-fx-border-width: 2px;-fx-padding: 2px 5px;-fx-border-radius: 5px;-fx-background-radius: 5px;");
});
importDeck.setOnMouseClicked(mouseEvent -> {
// Ali Do Here
Collection.importDeck(controller.getCurrentPlayer(),importName.getText());
});
exportDeck.setOnMouseEntered(mouseEvent -> {
exportDeck.setTextFill(Color.WHITE);
Expand All @@ -580,7 +592,7 @@ public void graphicShowCollection(){
exportDeck.setStyle("-fx-background-color: transparent;-fx-border-color: rgb(85, 239, 196);-fx-border-style: solid;-fx-border-width: 2px;-fx-padding: 2px 5px;-fx-border-radius: 5px;-fx-background-radius: 5px;");
});
exportDeck.setOnMouseClicked(mouseEvent -> {
// Ali Do Here
Collection.exportDeck(controller.getCurrentPlayer(), exportName.getText());
});
removeDeck.setOnMouseEntered(mouseEvent -> {
removeDeck.setTextFill(Color.BLACK);
Expand Down Expand Up @@ -693,7 +705,7 @@ public void graphicShowCollection(){
image = new Image(new FileInputStream("img/collectionBg.png"));
ImageView imageView = new ImageView(image);
imageView.setPreserveRatio(true);
group.getChildren().addAll(imageView,money,createDeckBtn,back,inputBox,scrollPane1,scrollPane2,deckSelector,importDeck,exportDeck,mainDeck,removeDeck);
group.getChildren().addAll(imageView,money,importName,exportName,createDeckBtn,back,inputBox,scrollPane1,scrollPane2,deckSelector,importDeck,exportDeck,mainDeck,removeDeck);
}
catch (Exception e){
System.err.println("Error While Showing Shop !");
Expand Down

0 comments on commit 9510168

Please sign in to comment.