diff --git a/cardCapacity/hashMapCard.txt b/cardCapacity/hashMapCard.txt new file mode 100644 index 0000000..da98b32 --- /dev/null +++ b/cardCapacity/hashMapCard.txt @@ -0,0 +1 @@ +{"@type":"java.util.HashMap","@val":{"shahghool":{"@type":"java.lang.Integer","@val":100},"jasoose toorani":{"@type":"java.lang.Integer","@val":100},"ghollab sang dare toorani":{"@type":"java.lang.Integer","@val":100},"ezhdehaye atash andaz":{"@type":"java.lang.Integer","@val":100},"Fireball":{"@type":"java.lang.Integer","@val":100},"simorgh":{"@type":"java.lang.Integer","@val":100},"Sacrifice":{"@type":"java.lang.Integer","@val":100},"asb savare fars":{"@type":"java.lang.Integer","@val":100},"dive siah":{"@type":"java.lang.Integer","@val":100},"iraj":{"@type":"java.lang.Integer","@val":100},"Health with profit":{"@type":"java.lang.Integer","@val":100},"arash":{"@type":"java.lang.Integer","@val":100},"All Attack":{"@type":"java.lang.Integer","@val":100},"siavash":{"@type":"java.lang.Integer","@val":100},"sepah salare fars":{"@type":"java.lang.Integer","@val":100},"gorg":{"@type":"java.lang.Integer","@val":100},"Weakening":{"@type":"java.lang.Integer","@val":100},"rakhsh":{"@type":"java.lang.Integer","@val":100},"All Power":{"@type":"java.lang.Integer","@val":100},"nane sarma":{"@type":"java.lang.Integer","@val":100},"kave":{"@type":"java.lang.Integer","@val":100},"kamandare fars":{"@type":"java.lang.Integer","@val":100},"HellFire":{"@type":"java.lang.Integer","@val":100},"All Poison":{"@type":"java.lang.Integer","@val":100},"Lightening Bolt":{"@type":"java.lang.Integer","@val":100},"shamshir zane fars":{"@type":"java.lang.Integer","@val":100},"neize dare fars":{"@type":"java.lang.Integer","@val":100},"esfandiar":{"@type":"java.lang.Integer","@val":100},"neize dare toorani":{"@type":"java.lang.Integer","@val":100},"Shock":{"@type":"java.lang.Integer","@val":100},"dive sefid":{"@type":"java.lang.Integer","@val":100},"Kings Guard":{"@type":"java.lang.Integer","@val":100},"dive goraz savar":{"@type":"java.lang.Integer","@val":100},"jadoogare azam":{"@type":"java.lang.Integer","@val":100},"ghoole do sar":{"@type":"java.lang.Integer","@val":100},"mare sammi":{"@type":"java.lang.Integer","@val":100},"pahlevane fars":{"@type":"java.lang.Integer","@val":100},"ghoole tak cheshm":{"@type":"java.lang.Integer","@val":100},"rostam":{"@type":"java.lang.Integer","@val":100},"Power Up":{"@type":"java.lang.Integer","@val":100},"gen":{"@type":"java.lang.Integer","@val":100},"Empower":{"@type":"java.lang.Integer","@val":100},"ghoole sang andaz":{"@type":"java.lang.Integer","@val":100},"gorge sefid":{"@type":"java.lang.Integer","@val":100},"giv":{"@type":"java.lang.Integer","@val":100},"Area Disepel":{"@type":"java.lang.Integer","@val":100},"foolad zereh":{"@type":"java.lang.Integer","@val":100},"Total Disarm":{"@type":"java.lang.Integer","@val":100},"shahzadeye toorani":{"@type":"java.lang.Integer","@val":100},"shire darande":{"@type":"java.lang.Integer","@val":100},"goraze vahshi":{"@type":"java.lang.Integer","@val":100},"piran":{"@type":"java.lang.Integer","@val":100},"mammad":{"@type":"java.lang.Integer","@val":100},"Poison Lake":{"@type":"java.lang.Integer","@val":100},"mare ghool peykar":{"@type":"java.lang.Integer","@val":100},"jadoogar":{"@type":"java.lang.Integer","@val":100},"zahhak":{"@type":"java.lang.Integer","@val":100},"kamandare toorani":{"@type":"java.lang.Integer","@val":100},"God Strength":{"@type":"java.lang.Integer","@val":100},"gorz dare toorani":{"@type":"java.lang.Integer","@val":100},"ghoole bozorg":{"@type":"java.lang.Integer","@val":100},"arzhang div":{"@type":"java.lang.Integer","@val":100},"ashkboos":{"@type":"java.lang.Integer","@val":100},"ezhdehaye haft sar":{"@type":"java.lang.Integer","@val":100},"Dispel":{"@type":"java.lang.Integer","@val":100},"bahman":{"@type":"java.lang.Integer","@val":100},"afsane":{"@type":"java.lang.Integer","@val":100},"palang":{"@type":"java.lang.Integer","@val":100},"hero support":{"@type":"java.lang.Integer","@val":100},"All Disarm":{"@type":"java.lang.Integer","@val":100},"oghab":{"@type":"java.lang.Integer","@val":100},"Madness":{"@type":"java.lang.Integer","@val":100}}} \ No newline at end of file diff --git a/cardCapacity/hashMapItem.txt b/cardCapacity/hashMapItem.txt new file mode 100644 index 0000000..1509b2f --- /dev/null +++ b/cardCapacity/hashMapItem.txt @@ -0,0 +1 @@ +{"@type":"java.util.HashMap","@val":{"King Wisdom":{"@type":"java.lang.Integer","@val":100},"Poisonous Dagger":{"@type":"java.lang.Integer","@val":100},"namoose Separ":{"@type":"java.lang.Integer","@val":100},"Soul Eater":{"@type":"java.lang.Integer","@val":100},"taje Danaii":{"@type":"java.lang.Integer","@val":100},"kamane Damol":{"@type":"java.lang.Integer","@val":100},"Assasination Dagger":{"@type":"java.lang.Integer","@val":100},"pare simorgh":{"@type":"java.lang.Integer","@val":100},"Shock Hammer":{"@type":"java.lang.Integer","@val":100},"Terror Hood":{"@type":"java.lang.Integer","@val":100},"ghosle tamid":{"@type":"java.lang.Integer","@val":100}}} \ No newline at end of file diff --git a/src/ir/pas/ClientApp.java b/src/ir/pas/ClientApp.java index fc01398..be1b7c1 100644 --- a/src/ir/pas/ClientApp.java +++ b/src/ir/pas/ClientApp.java @@ -5,6 +5,7 @@ import models.net.Client; import models.net.requests.LoginRequest; import newView.SceneMakers.LoginSceneMaker; +import newView.SceneMakers.ReplayMatchesSceneMaker; public class ClientApp extends Application { private static Stage primaryStage; @@ -18,6 +19,7 @@ public void start(Stage primaryStage) throws Exception { ClientApp.primaryStage = primaryStage; Client.getInstance(); new LoginSceneMaker(primaryStage).set(); +// new ReplayMatchesSceneMaker(primaryStage).set(); primaryStage.show(); } diff --git a/src/ir/pas/ServerApp.java b/src/ir/pas/ServerApp.java index d894b37..16a9ebf 100644 --- a/src/ir/pas/ServerApp.java +++ b/src/ir/pas/ServerApp.java @@ -9,7 +9,8 @@ public class ServerApp extends Application { @Override public void start(Stage primaryStage) throws Exception { Server.getInstance(); - new ServerMenuSceneMaker(primaryStage); + new ServerMenuSceneMaker(primaryStage).set(); + primaryStage.show(); } public static void main(String[] args) { diff --git a/src/models/Shop.java b/src/models/Shop.java index 8a8d6c4..49215f7 100644 --- a/src/models/Shop.java +++ b/src/models/Shop.java @@ -11,19 +11,39 @@ import java.io.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.SplittableRandom; public class Shop { private ArrayList cards = new ArrayList<>(); private ArrayList items = new ArrayList<>(); + private HashMap capacityToCard = new HashMap<>(); + private HashMap capacityToItem = new HashMap<>(); + private File customCardsPath = new File("customCards"); + private File hashMapCardPath = new File("cardCapacity/hashMapCard.txt"); + private File hashMapItemPath = new File("cardCapacity/hashMapItem.txt"); + //file custom card public Shop() throws FileNotFoundException { initCustomCards(); Initializer.initShopCards(cards); Initializer.initShopUsableItems(items); + try { +// firstInitHashMapCard(); +// firstinitHashMapItem(); + loadItemCapacities(); + loadCardCapacities(); + } catch (Exception e) { + e.printStackTrace(); + } + //just for showing capacities when load he shop + loadItemCapacities(); + System.out.println(capacityToItem); + loadCardCapacities(); + System.out.println(capacityToCard); } private void initCustomCards() throws FileNotFoundException { @@ -38,6 +58,57 @@ private void initCustomCards() throws FileNotFoundException { } } + private void initHashMapCard() throws IOException { + for (Card card : cards) { + capacityToCard.put(card.getName(), card.getCapacity()); + } + + YaGson yaGson = new YaGson(); + String json = yaGson.toJson(capacityToCard); + // TODO: 7/8/2019 must be checked and test + + FileWriter writer = new FileWriter(hashMapCardPath); + + writer.write(json); + writer.close(); + } + + private void initHashMapItem() throws IOException { + // TODO: 7/8/2019 must be checked and test + + for (Item item : items) { + capacityToItem.put(item.getName(), item.getCapacity()); + } + + YaGson yaGson = new YaGson(); + String json = yaGson.toJson(capacityToItem); + + FileWriter writer = new FileWriter(hashMapItemPath); + + writer.write(json); + writer.close(); + } + + + private void loadCardCapacities() throws FileNotFoundException { + // TODO: 7/8/2019 must be checked and test + + BufferedReader reader = new BufferedReader(new FileReader(hashMapCardPath)); + capacityToCard = new YaGson().fromJson(reader, capacityToCard.getClass()); + for (Card card : cards) { + card.setCapacity(capacityToCard.get(card.getName())); + } + } + + private void loadItemCapacities() throws FileNotFoundException { + // TODO: 7/8/2019 must be checked and test + BufferedReader reader = new BufferedReader(new FileReader(hashMapItemPath)); + capacityToItem = new YaGson().fromJson(reader, capacityToItem.getClass()); + for (Item item : items) { + item.setCapacity(capacityToItem.get(item.getName())); + } + } + private boolean CustomCardIsRepeated(Card customCard) throws FileNotFoundException { File dir = customCardsPath; File[] files = dir.listFiles(); @@ -84,6 +155,11 @@ public ArrayList getItems() { public void addCard(Card card) { cards.add(card); + try { + saveCustomCard(card); + } catch (Exception e) { + e.printStackTrace(); + } } public Card getCard(String cardName) { @@ -124,11 +200,17 @@ public void buyCard(String cardName) { Card card = getCard(cardName); card.decrementCapacity(); + try { + initHashMapCard(); + } catch (IOException e) { + e.printStackTrace(); + } Card newCard = card.getCopy(true); currentAccount.decreaseMoney(newCard.getBuyPrice()); collection.addCard(newCard); + } public void sellCard(int cardID) { @@ -140,6 +222,11 @@ public void sellCard(int cardID) { collection.removeCard(card); incrementCardCapacity(card.getName()); + try { + initHashMapCard(); + } catch (IOException e) { + e.printStackTrace(); + } } public void buyItem(String itemName) { @@ -148,6 +235,11 @@ public void buyItem(String itemName) { Item item = getItem(itemName); item.decrementCapacity(); + try { + initHashMapItem(); + } catch (IOException e) { + e.printStackTrace(); + } Item newItem = item.getCopy(true); currentAccount.decreaseMoney(newItem.getBuyPrice()); @@ -163,6 +255,11 @@ public void sellItem(int itemID) { collection.removeItem(item); incrementItemCapacity(item.getName()); + try { + initHashMapItem(); + } catch (IOException e) { + e.printStackTrace(); + } } public String getType(String name) { diff --git a/src/models/card/Card.java b/src/models/card/Card.java index 4f848c6..47ede37 100644 --- a/src/models/card/Card.java +++ b/src/models/card/Card.java @@ -13,6 +13,11 @@ public abstract class Card { private String description; private int collectionID; private int gameCardID; + + public void setCapacity(int capacity) { + this.capacity = capacity; + } + private int capacity = CAPACITY; public int getCapacity() { diff --git a/src/models/item/Item.java b/src/models/item/Item.java index 42fe214..a392a1a 100644 --- a/src/models/item/Item.java +++ b/src/models/item/Item.java @@ -16,6 +16,10 @@ public abstract class Item { private int collectibleID; private int capacity = CAPACITY; + public void setCapacity(int capacity) { + this.capacity = capacity; + } + public int getCapacity() { return capacity; } diff --git a/src/models/net/Client.java b/src/models/net/Client.java index af2d32a..4259838 100644 --- a/src/models/net/Client.java +++ b/src/models/net/Client.java @@ -66,8 +66,12 @@ private void initClient() { try (InputStream inputStream = socket.getInputStream()) { JsonStreamParser parser = new JsonStreamParser(new InputStreamReader(inputStream)); while (parser.hasNext()) { - UpdatePacket packet = deserializer.fromJson(parser.next(), UpdatePacket.class); - packet.update(); + try { + UpdatePacket packet = deserializer.fromJson(parser.next(), UpdatePacket.class); + packet.update(); + } catch (Exception e) { + e.printStackTrace(); + } } socket.close(); } catch (IOException e) { diff --git a/src/models/net/RequestHandlerThread.java b/src/models/net/RequestHandlerThread.java index ab33692..87d0b3d 100644 --- a/src/models/net/RequestHandlerThread.java +++ b/src/models/net/RequestHandlerThread.java @@ -3,6 +3,7 @@ import com.gilecode.yagson.YaGson; import com.gilecode.yagson.com.google.gson.JsonStreamParser; import models.net.requests.LoginRequest; +import models.net.requests.ScoreBoardRequest; import models.net.requests.SignUpRequest; import java.io.IOException; @@ -28,7 +29,9 @@ public void run() { try { while (parser.hasNext()) { RequestPacket packet = deserializer.fromJson(parser.next(), RequestPacket.class); - if (!(packet instanceof SignUpRequest) && !(packet instanceof LoginRequest)) + if (!(packet instanceof SignUpRequest) + && !(packet instanceof LoginRequest) + && !(packet instanceof ScoreBoardRequest)) if (packet.getAuthToken() == null || !packet.getAuthToken().equals(serverSideClient.getAuthToken())) continue; System.out.println(packet); diff --git a/src/newView/GraphicalElements/battle/EndTurnButton.java b/src/newView/GraphicalElements/battle/EndTurnButton.java index d5596c6..cb2a7df 100644 --- a/src/newView/GraphicalElements/battle/EndTurnButton.java +++ b/src/newView/GraphicalElements/battle/EndTurnButton.java @@ -74,4 +74,8 @@ public void changeState() { setEnable(); } } + + public boolean isEnable() { + return isEnable; + } } diff --git a/src/newView/GraphicalElements/battle/Tile.java b/src/newView/GraphicalElements/battle/Tile.java index c5fedde..08415b2 100644 --- a/src/newView/GraphicalElements/battle/Tile.java +++ b/src/newView/GraphicalElements/battle/Tile.java @@ -161,7 +161,7 @@ public void enableColorAnimation(Color color) { KeyValue colorValue = new KeyValue(polygon.fillProperty(), color); KeyValue strokeValue = new KeyValue(polygon.strokeWidthProperty(), polygon.getStrokeWidth() * 3); Timeline timeline = AnimationMaker.makeTimeline( - Duration.millis(GAME_ACT_TIME * 0.25) + Duration.millis(GAME_ACT_TIME * 0.2) , true, 2 , colorValue, strokeValue); timeline.play(); diff --git a/src/newView/GraphicalElements/globalChat/GlobalChatPane.java b/src/newView/GraphicalElements/globalChat/GlobalChatPane.java index d07b0ff..ac6dfb0 100644 --- a/src/newView/GraphicalElements/globalChat/GlobalChatPane.java +++ b/src/newView/GraphicalElements/globalChat/GlobalChatPane.java @@ -58,11 +58,6 @@ public GlobalChatPane() { messages.setSpacing(20); messages.setPadding(new Insets(0, 10, 0, 10)); - //todo must delete - addMessage(); - addMessage(); - addMessage(); - messagesBackgroundPane.getChildren().add(messages); this.getChildren().add(back); this.getChildren().add(scroller); diff --git a/src/newView/GraphicalElements/scoreBoard/ScoreBoardPane.java b/src/newView/GraphicalElements/scoreBoard/ScoreBoardPane.java index 5d044d6..7a83c4a 100644 --- a/src/newView/GraphicalElements/scoreBoard/ScoreBoardPane.java +++ b/src/newView/GraphicalElements/scoreBoard/ScoreBoardPane.java @@ -4,6 +4,7 @@ import javafx.geometry.Insets; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; @@ -27,10 +28,6 @@ public class ScoreBoardPane extends Pane { public ScoreBoardPane() { try { - this.accountProperties.add(new AccountProperty(100, "mmd", 35, true)); - this.accountProperties.add(new AccountProperty(200, "asfa", 80, false)); - updateScoreBoard(accountProperties); - setBackground(); setBack(); background.getChildren().add(accounts); @@ -68,11 +65,19 @@ private void setAccounts() { ScaleTool.resizeRegion(accounts, 400, 400); // ScaleTool.relocate(accounts, 300, 300); for (AccountProperty accountProperty : accountProperties) { - Text account = new Text(); - account.setText(accountProperty.getAccountName() + " " + accountProperty.getScore() + - " " + accountProperty.getMoney() + " " + accountProperty.getIsOnline()); - accounts.getChildren().add(account); - account.setFill(Color.WHITE); + HBox fields = new HBox(); + Text name = new Text(accountProperty.getAccountName()); + Text score = new Text(Integer.toString(accountProperty.getScore())); + Text money = new Text(Integer.toString(accountProperty.getMoney())); + Text isOnline = new Text(accountProperty.getIsOnline()); + name.setFill(Color.NAVAJOWHITE); + score.setFill(Color.WHITE); + money.setFill(Color.WHITE); + isOnline.setFill(Color.WHITE); + + fields.getChildren().addAll(name, score, money, isOnline); + fields.setSpacing(20); + accounts.getChildren().add(fields); } } diff --git a/src/newView/SceneMakers/BattleSceneMaker.java b/src/newView/SceneMakers/BattleSceneMaker.java index cc46887..0f2a957 100644 --- a/src/newView/SceneMakers/BattleSceneMaker.java +++ b/src/newView/SceneMakers/BattleSceneMaker.java @@ -24,7 +24,6 @@ public BattleSceneMaker(Stage primaryStage) { super(primaryStage); if (!battleBgSound.isPlaying()) battleBgSound.play(); - } @Override @@ -61,7 +60,11 @@ public Scene makeScene() throws Exception { storyMode.setOnMouseClicked(event -> new GameModeSelectorSceneMaker(getPrimaryStage(), false).set()); customGame.setOnMouseClicked(event -> new GameModeSelectorSceneMaker(getPrimaryStage(), true).set()); - multiPlayer.setOnMouseClicked(event -> new WaitingForBattleSceneMaker(getPrimaryStage()).set()); + multiPlayer.setOnMouseClicked(event -> { + new WaitingForBattleSceneMaker(getPrimaryStage()).set(); + Client.getInstance().sendPacket(new MultiPlayerGameRequest()); + BattleSceneMaker.battleBgSound.stop(); + }); Text storyModeText = new Text(); storyModeText.setText("STORY MODE"); diff --git a/src/newView/SceneMakers/CustomCardSceneMaker.java b/src/newView/SceneMakers/CustomCardSceneMaker.java index cd6624d..1caaec2 100644 --- a/src/newView/SceneMakers/CustomCardSceneMaker.java +++ b/src/newView/SceneMakers/CustomCardSceneMaker.java @@ -270,7 +270,8 @@ public void changed(ObservableValue observable, String oldValu ImageView back = new ImageView(new Image(new FileInputStream("src/newView/resources/customCard/back.png"))); ScaleTool.resizeImageView(back, 85, 85); - back.setOnMouseClicked(event -> new MainMenuSceneMaker(getPrimaryStage()).set()); +// back.setOnMouseClicked(event -> new MainMenuSceneMaker(getPrimaryStage()).set()); + back.setOnMouseClicked(event -> new ServerMenuSceneMaker(getPrimaryStage()).set()); gettingBuffProperties(buff); ScaleTool.relocate(buff, 700, 300); diff --git a/src/newView/SceneMakers/InGameSceneMaker.java b/src/newView/SceneMakers/InGameSceneMaker.java index a735cbb..a352982 100644 --- a/src/newView/SceneMakers/InGameSceneMaker.java +++ b/src/newView/SceneMakers/InGameSceneMaker.java @@ -16,6 +16,8 @@ public class InGameSceneMaker extends SceneMaker { public InGameSceneMaker(Stage primaryStage) { super(primaryStage); + if (WaitingForBattleSceneMaker.waitingForBattleMusic.isPlaying()) + WaitingForBattleSceneMaker.waitingForBattleMusic.stop(); } @Override diff --git a/src/newView/SceneMakers/MainMenuSceneMaker.java b/src/newView/SceneMakers/MainMenuSceneMaker.java index 6154d43..8c92691 100644 --- a/src/newView/SceneMakers/MainMenuSceneMaker.java +++ b/src/newView/SceneMakers/MainMenuSceneMaker.java @@ -86,8 +86,8 @@ public Scene makeScene() throws IOException { Text collection = new Text("Collection"); collection.setOnMouseClicked(event -> new CollectionSceneMaker(getPrimaryStage()).set()); - Text customCard = new Text("Custom Card"); - customCard.setOnMouseClicked(event -> new CustomCardSceneMaker(getPrimaryStage()).set()); +// Text customCard = new Text("Custom Card"); +// customCard.setOnMouseClicked(event -> new CustomCardSceneMaker(getPrimaryStage()).set()); Text globalChat = new Text("Global Chat"); globalChat.setOnMouseClicked(event -> new GlobalChatSceneMaker(getPrimaryStage()).set()); @@ -114,7 +114,7 @@ public Scene makeScene() throws IOException { Text exit = new Text("Exit"); exit.setOnMouseClicked(event -> System.exit(0)); - commandsBox.getChildren().addAll(battle, shop, collection, customCard, globalChat, replayMatches + commandsBox.getChildren().addAll(battle, shop, collection, globalChat, replayMatches , scoreBoard, save, logout, exit); commandsBox.getChildren().forEach(node -> { if (node instanceof Text) { diff --git a/src/newView/SceneMakers/ReplayMatchesSceneMaker.java b/src/newView/SceneMakers/ReplayMatchesSceneMaker.java index 4f6923d..57b41b5 100644 --- a/src/newView/SceneMakers/ReplayMatchesSceneMaker.java +++ b/src/newView/SceneMakers/ReplayMatchesSceneMaker.java @@ -1,9 +1,7 @@ package newView.SceneMakers; -import com.sun.deploy.util.SyncAccess; import javafx.geometry.Insets; import javafx.scene.Scene; -import javafx.scene.control.ScrollPane; import javafx.scene.effect.Glow; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -15,7 +13,6 @@ import javafx.stage.Stage; import models.MatchDetail; import models.net.Client; -import models.net.requests.gameRequests.RefuseRequest; import models.net.requests.watchRequests.LiveWatchRequest; import models.net.requests.watchRequests.ReplayWatchRequest; import newView.GraphicalElements.BackgroundMaker; @@ -28,8 +25,8 @@ public class ReplayMatchesSceneMaker extends SceneMaker { - private static ArrayList finishedMatchDetails; - private static ArrayList liveMatchDetails; + private static ArrayList finishedMatchDetails = new ArrayList<>(); + private static ArrayList liveMatchDetails = new ArrayList<>(); private static int archiveCounter; private static int onlineCounter; @@ -185,4 +182,6 @@ public static void updateArchivedMatchDetailes(ArrayList matchDetai } + + } diff --git a/src/newView/SceneMakers/ScoreBoardSceneMaker.java b/src/newView/SceneMakers/ScoreBoardSceneMaker.java index d7cc0e4..3c217ce 100644 --- a/src/newView/SceneMakers/ScoreBoardSceneMaker.java +++ b/src/newView/SceneMakers/ScoreBoardSceneMaker.java @@ -1,5 +1,6 @@ package newView.SceneMakers; +import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -29,12 +30,16 @@ public Scene makeScene() throws Exception { ImageView back = new ImageView(new Image(new FileInputStream("src/newView/resources/scoreBoard/back.png"))); ScaleTool.resizeImageView(back, 85, 85); - back.setOnMouseClicked(event -> new MainMenuSceneMaker(getPrimaryStage()).set()); + setBackOnMouseClick(back); pane.getChildren().add(scoreBoardPane); pane.getChildren().add(back); return new MyScene(pane); } + protected void setBackOnMouseClick(Node back) { + back.setOnMouseClicked(event -> new MainMenuSceneMaker(getPrimaryStage()).set()); + } + public static ScoreBoardPane getScoreBoardPane() { return scoreBoardPane; } diff --git a/src/newView/SceneMakers/ServerMenuSceneMaker.java b/src/newView/SceneMakers/ServerMenuSceneMaker.java index 6387f07..ed73141 100644 --- a/src/newView/SceneMakers/ServerMenuSceneMaker.java +++ b/src/newView/SceneMakers/ServerMenuSceneMaker.java @@ -1,7 +1,12 @@ package newView.SceneMakers; import javafx.scene.Scene; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; import javafx.stage.Stage; +import newView.GraphicalElements.MyScene; +import newView.GraphicalElements.ScaleTool; public class ServerMenuSceneMaker extends SceneMaker { @@ -11,6 +16,33 @@ public ServerMenuSceneMaker(Stage primaryStage) { @Override public Scene makeScene() throws Exception { - return null; + Pane root = new Pane(); + + Text server = new Text("SERVER"); + server.setStyle("-fx-text-fill: black ; -fx-font-size: 350"); + ScaleTool.relocate(server, 70, 400); + + VBox vBox = new VBox(); + + Text shop = new Text("Shop"); + shop.setStyle("-fx-text-fill: black"); + shop.setOnMouseClicked(event -> new ServerShopSceneMaker(getPrimaryStage()).set()); + + Text scoreBoard = new Text("ScoreBoard"); + shop.setStyle("-fx-text-fill: black"); + scoreBoard.setOnMouseClicked(event -> new ServerScoreBoardSceneMaker(getPrimaryStage()).set()); + + Text customCard = new Text("Custom Card"); + customCard.setStyle("-fx-text-fill: black"); + customCard.setOnMouseClicked(event -> new CustomCardSceneMaker(getPrimaryStage()).set()); + + + vBox.getChildren().addAll(shop, customCard, scoreBoard); + ScaleTool.relocate(vBox, 100, 100); + root.getChildren().add(server); + root.getChildren().add(vBox); + + return new MyScene(root); } + } diff --git a/src/newView/SceneMakers/ServerScoreBoardSceneMaker.java b/src/newView/SceneMakers/ServerScoreBoardSceneMaker.java new file mode 100644 index 0000000..3375281 --- /dev/null +++ b/src/newView/SceneMakers/ServerScoreBoardSceneMaker.java @@ -0,0 +1,20 @@ +package newView.SceneMakers; + +import javafx.scene.Node; +import javafx.scene.Scene; +import javafx.scene.layout.Pane; +import javafx.stage.Stage; +import newView.GraphicalElements.MyScene; + +public class ServerScoreBoardSceneMaker extends ScoreBoardSceneMaker { + + + public ServerScoreBoardSceneMaker(Stage primaryStage) { + super(primaryStage); + } + + @Override + protected void setBackOnMouseClick(Node back) { + back.setOnMouseClicked(event -> new ServerMenuSceneMaker(getPrimaryStage()).set()); + } +} \ No newline at end of file diff --git a/src/newView/SceneMakers/ServerShopSceneMaker.java b/src/newView/SceneMakers/ServerShopSceneMaker.java new file mode 100644 index 0000000..75d58e8 --- /dev/null +++ b/src/newView/SceneMakers/ServerShopSceneMaker.java @@ -0,0 +1,83 @@ +package newView.SceneMakers; + +import javafx.application.Platform; +import javafx.scene.Scene; +import javafx.scene.control.ScrollPane; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.text.Text; +import javafx.stage.Stage; +import models.GameContents; +import models.Shop; +import models.card.Card; +import models.card.Hero; +import models.card.Minion; +import models.card.SpellCard; +import models.item.Item; +import newView.GraphicalElements.MyScene; +import newView.GraphicalElements.ScaleTool; + +import java.util.ArrayList; + +public class ServerShopSceneMaker extends SceneMaker { + private VBox vBox = new VBox(); + private Shop shop = GameContents.getShop(); + private ScrollPane scrollPane = new ScrollPane(); + + public ServerShopSceneMaker(Stage primaryStage) { + super(primaryStage); + } + + @Override + public Scene makeScene() throws Exception { + Pane root = new Pane(); + scrollPane.setContent(vBox); + scrollPane.setMaxHeight(600); + scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); + scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); + ScaleTool.relocate(scrollPane, 20, 50); + scrollPane.setStyle("-fx-background-color: white"); + + vBox.setSpacing(10); + show(); + Text back = new Text("BACK"); + back.setStyle("-fx-font-size: 20"); + back.setFill(Color.BLACK); + back.setOnMouseClicked(event -> new ServerMenuSceneMaker(getPrimaryStage()).set()); + ScaleTool.relocate(back, 20, 20); + + root.getChildren().addAll(back, scrollPane); + return new MyScene(root); + } + + + private void show() { + Platform.runLater(new Runnable() { + @Override + public void run() { + ArrayList cards = new ArrayList(); + cards.addAll(shop.getCards()); + cards.addAll(shop.getItems()); + + for (Object object : cards) { + Text cardText = new Text(); + if (object instanceof Hero) { + cardText.setText(((Card) object).getName() + " Hero " + ((Card) object).getCapacity()); + } else if (object instanceof Minion) { + cardText.setText(((Minion) object).getName() + " MINION " + ((Minion) object).getCapacity()); + } else if (object instanceof SpellCard) { + cardText.setText(((SpellCard) object).getName() + " SPELL " + ((SpellCard) object).getCapacity()); + } else if (object instanceof Item) { + cardText.setText(((Item) object).getName() + " ITEM " + ((Item) object).getCapacity()); + } + cardText.setFill(Color.BLACK); + cardText.setStyle("-fx-font-size: 20"); + vBox.getChildren().add(cardText); + } + } + }); + + } +} + diff --git a/src/newView/SceneMakers/WaitingForBattleSceneMaker.java b/src/newView/SceneMakers/WaitingForBattleSceneMaker.java index 3de6f78..d501a30 100644 --- a/src/newView/SceneMakers/WaitingForBattleSceneMaker.java +++ b/src/newView/SceneMakers/WaitingForBattleSceneMaker.java @@ -5,24 +5,29 @@ import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.Pane; +import javafx.scene.media.AudioClip; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.stage.Stage; import models.net.Client; -import models.net.requests.gameRequests.MultiPlayerGameRequest; import models.net.requests.gameRequests.RefuseRequest; import newView.GraphicalElements.BackgroundMaker; import newView.GraphicalElements.MyScene; import newView.GraphicalElements.ScaleTool; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Random; public class WaitingForBattleSceneMaker extends SceneMaker { + private static File audioPath = new File("src/newView/resources/sounds/waitingForBattle/3. 50 Cent In Da Club (2003) (www.htbeats.mihanblog.com).mp3"); + public static AudioClip waitingForBattleMusic = new AudioClip(audioPath.toURI().toString()); + + public WaitingForBattleSceneMaker(Stage primaryStage) { super(primaryStage); - Client.getInstance().sendPacket(new MultiPlayerGameRequest()); + waitingForBattleMusic.play(); } private double x = 0; @@ -49,7 +54,8 @@ private ImageView setBackImageView() throws FileNotFoundException { ImageView back = new ImageView(new Image(new FileInputStream("src/newView/resources/waitingForBattleMenu/back.png"))); ScaleTool.resizeImageView(back, 85, 85); back.setOnMouseClicked(event -> { - Client.getInstance().sendPacket(new RefuseRequest()); + waitingForBattleMusic.stop(); + Client.getInstance().sendPacket(new RefuseRequest()); new MainMenuSceneMaker(getPrimaryStage()).set(); }); return back; @@ -61,7 +67,6 @@ private ImageView setHeroImageView(Pane pane) throws FileNotFoundException { ScaleTool.relocate(randomHeroImage, -2000 + 80, -1500); ScaleTool.homothety(randomHeroImage, 0.21); - pane.addEventHandler(MouseEvent.MOUSE_MOVED, event -> { if (event.getX() < x) { randomHeroImage.setX(randomHeroImage.getX() + 0.12); diff --git a/src/newView/battleView/GameGraphicData.java b/src/newView/battleView/GameGraphicData.java index 81bc311..af4e108 100644 --- a/src/newView/battleView/GameGraphicData.java +++ b/src/newView/battleView/GameGraphicData.java @@ -1,6 +1,7 @@ package newView.battleView; import javafx.application.Platform; +import javafx.scene.control.ProgressBar; import javafx.scene.layout.Pane; import models.item.Item; import models.net.Client; @@ -22,6 +23,7 @@ public class GameGraphicData { private static CollectiblesHBox collectiblesHBox; private static GraveyardPane graveyardPane; private static CardInfo cardInfo; + private static ProgressBar bar = null; private static SelectType selectType = null; private static boolean spectator; @@ -30,6 +32,8 @@ public class GameGraphicData { private static HandElement selectedHandElement; private static CollectibleElement selectedCollectibleElement; + private static int turnID = 0; + private static GameGraphicListener listener = new GameGraphicListener(); static { @@ -118,6 +122,20 @@ public static TilesPane getTilesPane() { return tilesPane; } + public static void setBar(ProgressBar bar) { + removeBar(); + if (bar != null) { + tilesPane.getChildren().add(bar); + } + GameGraphicData.bar = bar; + } + + private static void removeBar() { + if (GameGraphicData.bar != null) { + tilesPane.getChildren().remove(GameGraphicData.bar); + } + } + public static PlayerInfoPane[] getInfoPanes() { return infoPanes; } @@ -150,6 +168,18 @@ public static boolean isOnLeft() { return onLeft; } + public static boolean isMyTurn() { + return turnButton.isEnable(); + } + + public static int getTurnID() { + return turnID; + } + + public static void incrementTurnID() { + turnID++; + } + public static void addCollectibles(ArrayList items) { for (Item item : items) { collectiblesHBox.addElement(new CollectibleElement(item)); diff --git a/src/newView/battleView/gameActs/TurnChangeAct.java b/src/newView/battleView/gameActs/TurnChangeAct.java index 2ccb9ba..0256fe4 100644 --- a/src/newView/battleView/gameActs/TurnChangeAct.java +++ b/src/newView/battleView/gameActs/TurnChangeAct.java @@ -1,9 +1,13 @@ package newView.battleView.gameActs; +import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; +import javafx.scene.control.ProgressBar; import javafx.scene.text.Text; import javafx.util.Duration; +import models.net.Client; +import models.net.requests.battleRequests.EndTurnRequest; import newView.AnimationMaker; import newView.GraphicalElements.ScaleTool; import newView.GraphicalElements.battle.TilesPane; @@ -41,6 +45,46 @@ private void makeAnimation() { timeline.setOnFinished(event -> tilesPane.getChildren().remove(text)); + GameGraphicData.incrementTurnID(); GameGraphicData.getTurnButton().changeState(); + GameGraphicData.setBar(null); + + setTurnTimeBar(); + } + + public static void setTurnTimeBar() { + if (GameGraphicData.isMyTurn() && !GameGraphicData.isSpectator()) { + int myTurnID = GameGraphicData.getTurnID(); + + ProgressBar bar = new ProgressBar(0); + bar.setPrefSize(TILE_LENGTH * NUMBER_OF_COLUMNS, 15); + ScaleTool.relocate(bar, 0, TILE_LENGTH * NUMBER_OF_ROWS + 30); + + double timeToWait = 40; + + Timeline task = new Timeline( + new KeyFrame( + Duration.seconds(timeToWait * 3 / 4), + new KeyValue(bar.progressProperty(), 1) + ) + ); + + Timeline timeLimiter = AnimationMaker.makeTimeline(Duration.seconds(timeToWait / 4) + , false, 1); + timeLimiter.play(); + + timeLimiter.setOnFinished(event -> { + if (myTurnID == GameGraphicData.getTurnID()) { + GameGraphicData.setBar(bar); + task.play(); + + task.setOnFinished(event1 -> { + if (myTurnID == GameGraphicData.getTurnID()) { + Client.getInstance().sendPacket(new EndTurnRequest()); + } + }); + } + }); + } } } diff --git a/src/newView/resources/sounds/waitingForBattle/3. 50 Cent In Da Club (2003) (www.htbeats.mihanblog.com).mp3 b/src/newView/resources/sounds/waitingForBattle/3. 50 Cent In Da Club (2003) (www.htbeats.mihanblog.com).mp3 new file mode 100644 index 0000000..501ce58 Binary files /dev/null and b/src/newView/resources/sounds/waitingForBattle/3. 50 Cent In Da Club (2003) (www.htbeats.mihanblog.com).mp3 differ