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
MostafaOjaghi committed Jul 8, 2019
2 parents 61ac1ff + bcf52d3 commit 737b9c8
Show file tree
Hide file tree
Showing 26 changed files with 382 additions and 36 deletions.
1 change: 1 addition & 0 deletions cardCapacity/hashMapCard.txt
Original file line number Diff line number Diff line change
@@ -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}}}
1 change: 1 addition & 0 deletions cardCapacity/hashMapItem.txt
Original file line number Diff line number Diff line change
@@ -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}}}
2 changes: 2 additions & 0 deletions src/ir/pas/ClientApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion src/ir/pas/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
97 changes: 97 additions & 0 deletions src/models/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,39 @@

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.SplittableRandom;

public class Shop {
private ArrayList<Card> cards = new ArrayList<>();
private ArrayList<Item> items = new ArrayList<>();

private HashMap<String, Integer> capacityToCard = new HashMap<>();
private HashMap<String, Integer> 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 {
Expand All @@ -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();
Expand Down Expand Up @@ -84,6 +155,11 @@ public ArrayList<Item> getItems() {

public void addCard(Card card) {
cards.add(card);
try {
saveCustomCard(card);
} catch (Exception e) {
e.printStackTrace();
}
}

public Card getCard(String cardName) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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());
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/models/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/models/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions src/models/net/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/models/net/RequestHandlerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/newView/GraphicalElements/battle/EndTurnButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ public void changeState() {
setEnable();
}
}

public boolean isEnable() {
return isEnable;
}
}
2 changes: 1 addition & 1 deletion src/newView/GraphicalElements/battle/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions src/newView/GraphicalElements/globalChat/GlobalChatPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 14 additions & 9 deletions src/newView/GraphicalElements/scoreBoard/ScoreBoardPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/newView/SceneMakers/BattleSceneMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public BattleSceneMaker(Stage primaryStage) {
super(primaryStage);
if (!battleBgSound.isPlaying())
battleBgSound.play();

}

@Override
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/newView/SceneMakers/CustomCardSceneMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ public void changed(ObservableValue<? extends String> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/newView/SceneMakers/InGameSceneMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class InGameSceneMaker extends SceneMaker {

public InGameSceneMaker(Stage primaryStage) {
super(primaryStage);
if (WaitingForBattleSceneMaker.waitingForBattleMusic.isPlaying())
WaitingForBattleSceneMaker.waitingForBattleMusic.stop();
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/newView/SceneMakers/MainMenuSceneMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 737b9c8

Please sign in to comment.