Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza1082 committed Jun 25, 2019
2 parents c452276 + da9c0fd commit 011b9b8
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 182 deletions.
34 changes: 1 addition & 33 deletions src/controller/AccountController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,6 @@ public static AccountController getInstance() {
accountController.setDaemon(true);
return accountController;
}
// void main(Account account) {
// AccountRequest request;
// this.account = account;
// view.showMainMenu();
// request = new AccountRequest();
// request.getNewCommand();
// switch (request.getType()) {
// case ENTER_COLLECTION:
// enterCollection();
// break;
// case ENTER_SHOP:
// enterShop();
// break;
// case ENTER_BATTLE:
// enterBattle(request);
// break;
// case EXIT:
// System.exit(0);
// break;
// case HELP:
// help();
// break;
// case LOGOUT:
//
// break;
// case SAVE:
// save();
// case SHOW_MATCH_HISTORY:
// account.showHistory();
// }
//
// }

//------------------------------------------------------------Battle
public void enterBattle(AccountRequest request) {
Expand Down Expand Up @@ -214,7 +182,7 @@ private Account[] getAccounts(Account[] accounts) {
}

public void enterCollection() {
CollectionController.getInstance().main(this.account.getCollection());
CollectionController.getInstance().setCollection(this.account.getCollection());
}

public void enterShop() {
Expand Down
81 changes: 23 additions & 58 deletions src/controller/CollectionController.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,26 @@
package controller;

import com.google.gson.Gson;
import models.*;
import models.Enums.ErrorType;
import view.CollectionRequest;
import view.View;

class CollectionController {
import java.io.FileWriter;
import java.io.IOException;

public class CollectionController {
private static CollectionController collectionController = new CollectionController();
private Collection collection;
private View view = View.getInstance();

private CollectionController() {
}

static CollectionController getInstance() {
public static CollectionController getInstance() {
return collectionController;
}

void main(Collection collection) {
CollectionRequest request;
this.collection = collection;
boolean isFinish = false;
do {
request = new CollectionRequest();
request.getNewCommand();
switch (request.getType()) {
case EXIT:
isFinish = true;
break;
case SHOW_COLLECTION_ITEMS_AND_CARDS:
showCollectionItemsAndCards();
break;
case SEARCH_CARD_IN_COLLECTION:
search(request);
break;
case SAVE:
save();
break;
case CREATE_DECK:
createDeck(request);
break;
case DELETE_DECK:
deleteDeck(request);
break;
case ADD_CARD_TO_DECK:
addCardToDeck(request);
break;
case REMOVE_CARD_FROM_DECK:
removeCardFromDeck(request);
break;
case VALIDATE:
validateDeck(request);
break;
case SELECT_DECK:
selectMainDeck(request);
break;
case SHOW_ALL_DECKS:
showAllDecks();
break;
case SHOW_DECK:
showDeck(request);
break;
case HELP:
help();
break;
}
}
while (!isFinish);
}

private void showCollectionItemsAndCards() {
view.printCollectionItems(collection.getCollectionCards(), false);
}
Expand Down Expand Up @@ -175,11 +127,24 @@ private void showDeck(CollectionRequest request) {

}

public void help() {
view.printCollectionMenuHelp(collection.toString());
private void save() {
}

public void setCollection(Collection collection) {
this.collection = collection;
}

private void save() {
public void exportDeck(String deckName) {
Deck deck = collection.getDeck(deckName);
Gson gson = new Gson();
try {
FileWriter fileWriter = new FileWriter("deck.json");
fileWriter.write(gson.toJson(deck));
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}
}
37 changes: 1 addition & 36 deletions src/controller/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,6 @@ private GameController() {
public static GameController getInstance() {
return gameController;
}
// public void main() {
// GameRequest request;
// boolean isFinish = false;
// do {
// view.printStartMenu(); /*show menu*/
// request = new GameRequest();
// request.getNewCommand();
// switch (request.getType()) {
// case LOGIN:
// login(request);
// break;
// case CREATE_ACCOUNT:
// createAccount(request);
// break;
// case HELP:
// help();
// break;
// case SHOW_LEADERBOARD:
// showLeaderboard();
// break;
// case EXIT:
// isFinish = true;
// }
// }
// while (!isFinish);
// }

private boolean login() {
Account account = Game.getAccount(username);
Expand Down Expand Up @@ -79,16 +53,7 @@ private void createAccount() {

private void showMessage(ErrorType errorType) {
labelText = errorType.getMessage();
System.out.println(errorType.getMessage());
}
//
// private void showLeaderboard() {
// view.printLeaderboard(game.getSortedAccounts());
// }
//
// private void help() {
// view.printGameMenuHelp(game.toString());
// }

@Override
public void run() {
Expand Down Expand Up @@ -122,4 +87,4 @@ public String getLabelText() {
return labelText;
}

}
}
67 changes: 36 additions & 31 deletions src/controller/ShopController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package controller;

import controller.fxmlControllers.ShopFxmlController;
import models.Enums.ErrorType;
import models.Shop;
import view.ShopRequest;
import view.View;

import static models.Enums.ErrorType.CARD_NOT_FOUND_IN_SHOP;
import static models.Enums.ErrorType.NO_ERROR;

public class ShopController {
private static ShopController shopController = new ShopController();
private Shop shop = Shop.getInstance();
private View view = View.getInstance();
private ShopFxmlController shopFxmlController;

private ShopController() {
}
Expand Down Expand Up @@ -61,6 +62,10 @@ public static ShopController getInstance() {
// view.printShopCards(shop.getCards());
// }

public void setShopFxmlController(ShopFxmlController shopFxmlController) {
this.shopFxmlController = shopFxmlController;
}

private void sellCard(ShopRequest request) {
int cardID = request.getCardID();
boolean isDone = shop.sell(cardID);
Expand All @@ -70,44 +75,44 @@ private void sellCard(ShopRequest request) {
view.unSuccessfulSellMessage();
}

private void buyCard(ShopRequest request) {
ErrorType error;
String cardName = request.getCardName();
if (shop.getCard(cardName) != null) {
error = shop.buy(cardName);
} else {
error = CARD_NOT_FOUND_IN_SHOP;
}
public void buyCard(String cardName) {
cardName = cardName.split("\n")[0];
ErrorType error = shop.buy(cardName);
if (error != NO_ERROR) {
view.printError(error);
shopFxmlController.message.setText(error.getMessage());
} else {
view.successfulBuyMessage();
shopFxmlController.message.setText("you bought \n" + cardName);
}
shopFxmlController.money.setText(String.valueOf(shop.getAccount().getMoney()));
}
// private void searchInShop(ShopRequest request) {
// String cardName = request.getCardName();
// if (shop.searchInShop(cardName)) {
// view.printCardWasFound();
// } else {
// view.printError(CARD_NOT_FOUND_IN_SHOP);
// }
//// private void searchInShop(ShopRequest request) {
//// String cardName = request.getCardName();
//// if (shop.searchInShop(cardName)) {
//// view.printCardWasFound();
//// } else {
//// view.printError(CARD_NOT_FOUND_IN_SHOP);
//// }
//// }
//// private void searchInCollection(ShopRequest request) {
//// String cardName = request.getCardName();
//// int state = shop.searchInCollection(cardName);
//// if (state != -1) {
//// view.printCardInCollection(cardName, state);
//// } else {
//// view.printNoCardWithThisName(cardName);
//// }
//// }
//
// private void showCollectionCards() {
// view.printCollectionItems(shop.getCards(), true);
// }
// private void searchInCollection(ShopRequest request) {
// String cardName = request.getCardName();
// int state = shop.searchInCollection(cardName);
// if (state != -1) {
// view.printCardInCollection(cardName, state);
// } else {
// view.printNoCardWithThisName(cardName);
// }
// }

private void showCollectionCards() {
view.printCollectionItems(shop.getCards(), true);
}

public Shop getShop() {
return shop;
}

public ShopFxmlController getShopFxmlController() {
return shopFxmlController;
}

}
7 changes: 4 additions & 3 deletions src/controller/fxmlControllers/CardInShopController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package controller.fxmlControllers;

import controller.ShopController;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import models.Shop;

import java.net.URL;
import java.util.ResourceBundle;
Expand All @@ -19,11 +20,11 @@ public class CardInShopController implements Initializable {
public Label HP;
public Label name;
public ImageView imageView;
public CheckBox checkBox;

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {

ShopController shopController = ShopController.getInstance();
pane.setOnMouseClicked(mouseEvent -> shopController.buyCard(name.getText()));
}
}

3 changes: 3 additions & 0 deletions src/controller/fxmlControllers/ShopFxmlController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ public class ShopFxmlController implements Initializable {

public Button back;
public FlowPane pane;
public Label money;
public Label message;
private ShopController shopController = ShopController.getInstance();

@Override
public void initialize(URL location, ResourceBundle resources) {
shopController.setShopFxmlController(this);
back.setOnAction(actionEvent -> Game.getInstance().loadPage(back, "/view/fxmls/mainMenu.fxml"));
craftGraphics();
}
Expand Down
5 changes: 3 additions & 2 deletions src/models/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ String getPassword() {
return password;
}

int getMoney() {
public int getMoney() {
return money;
}

Expand Down Expand Up @@ -90,4 +90,5 @@ public ArrayList<MatchHistory> getHistories() {
return histories;
}

}

}
Loading

0 comments on commit 011b9b8

Please sign in to comment.