Skip to content

Commit

Permalink
a little bug left
Browse files Browse the repository at this point in the history
  • Loading branch information
pariyahr committed Jul 26, 2022
1 parent cfe5787 commit f2c47b4
Show file tree
Hide file tree
Showing 1,029 changed files with 1,199 additions and 77,532 deletions.
1 change: 0 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,065 changes: 1,037 additions & 28 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Client/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions Client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@
<artifactId>xstream</artifactId>
<version>1.4.19</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>civilization</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

</dependencies>

Expand Down
1 change: 1 addition & 0 deletions Client/src/main/java/com/example/project/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public static void main(String[] args) {
MenuChanger.main(args);
} else System.out.println("try later please");
}

}
31 changes: 27 additions & 4 deletions Client/src/main/java/com/example/project/models/Game.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.example.project.models;

import com.example.project.views.PlayGamePage;
import javafx.scene.control.ChoiceBox;

import java.util.ArrayList;

public class Game {
private static Game instance;
private static boolean isYourTurn;

public static void setNull() {
instance = null;
Expand All @@ -20,18 +22,26 @@ public static Game getInstance() {
private GameMap gameMap; // ok
private int turn; // ok
private Player thisTurnPlayer; // player
private Player allOfGameThisTurnPlayer;

public Game() {
}

public static boolean isIsYourTurn() {
return isYourTurn;
}

public static void setIsYourTurn(boolean isYourTurn) {
Game.isYourTurn = isYourTurn;
}

public void startGame(ArrayList<User> users) {
players = new ArrayList<>();
for (User user : users) {
Player player = new Player(user);
players.add(player);
}
gameMap = new GameMap(players);
thisTurnPlayer = players.get(0);
}

public ArrayList<Player> getPlayers() {
Expand Down Expand Up @@ -68,9 +78,14 @@ public void setThisTurnPlayer(Player thisTurnPlayer) {

public void nextTurn() {
thisTurnPlayer.endTurn(gameMap, false);
int index = players.indexOf(thisTurnPlayer);
index = (index + 1) % players.size();
thisTurnPlayer = players.get(index);
int index = players.indexOf(allOfGameThisTurnPlayer);
index++;
if (index == players.size())
index = 0;
allOfGameThisTurnPlayer = players.get(index);
GameNetworkData.sendGame();
isYourTurn = false;
PlayGamePage.getInstance().setOnMap(false);
}

public void removePlayer(Player player) {
Expand Down Expand Up @@ -99,4 +114,12 @@ public Player getWinner() {
return player;
}
}

public Player getAllOfGameThisTurnPlayer() {
return allOfGameThisTurnPlayer;
}

public void setAllOfGameThisTurnPlayer(Player allOfGameThisTurnPlayer) {
this.allOfGameThisTurnPlayer = allOfGameThisTurnPlayer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public int getIndexJ(Tile tile) {
}

public ArrayList<Tile> getUnitInSightTiles(Tile tile) {
if (tile == null) return new ArrayList<>();
boolean isOnBlock = (tile.getMode().getTileName() == TileModeEnum.MOUNTAIN) ||
tile.hasFeature(TileFeatureEnum.FOREST) || tile.getMode().getTileName() == TileModeEnum.HILL;
int iCoordinate = this.getIndexI(tile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class GameNetworkData {
private GameMap gameMap;
private int turn;
private Player thisTurnPlayer;
private Player allOfGameThisTurnPlayer;

private GameNetworkData() {
}
Expand All @@ -32,6 +33,7 @@ public static GameNetworkData getInstance() {
data.gameMap = Game.getInstance().getGameMap();
data.turn = Game.getInstance().getTurn();
data.thisTurnPlayer = Game.getInstance().getThisTurnPlayer();
data.allOfGameThisTurnPlayer = Game.getInstance().getAllOfGameThisTurnPlayer();
return data;
}

Expand All @@ -43,19 +45,22 @@ public void setToGameDataBase() {
Game.getInstance().setPlayers(players);
Game.getInstance().setGameMap(gameMap);
Game.getInstance().setTurn(turn);
Game.getInstance().setAllOfGameThisTurnPlayer(allOfGameThisTurnPlayer);
for (Player player : Game.getInstance().getPlayers())
if (player.getUser().equals(DataBase.getInstance().getLoggedInUser()))
Game.getInstance().setThisTurnPlayer(player);
Game.setIsYourTurn(Game.getInstance().getThisTurnPlayer() ==
Game.getInstance().getAllOfGameThisTurnPlayer());
}


public static void sendGame() {
XStream xStream = new XStream();
String data = xStream.toXML(GameNetworkData.getInstance());
int length = data.length();
for (int i = 0; i < 30; i++) {
for (int i = 0; i < 50; i++) {
Request request = new Request(RequestEnum.SEND_DATA,
data.substring((i * length) / 30, ((i + 1) * length) / 30));
data.substring((i * length) / 50, ((i + 1) * length) / 50));
Network.getInstance().sendRequestWithoutResponse(request);
}
}
Expand All @@ -64,7 +69,22 @@ public static void getGame() {
Request request = new Request(RequestEnum.GET_DATA);
Network.getInstance().sendRequestWithoutResponse(request);
StringBuilder xmlBuilder = new StringBuilder("");
for (int i = 0; i < 30; i++) {
for (int i = 0; i < 50; i++) {
xmlBuilder.append(Network.getInstance().getResponse().getData());
}
String xml = xmlBuilder.toString();
XStream xStream = new XStream();
xStream.addPermission(AnyTypePermission.ANY);
if (xml.length() != 0) {
GameNetworkData game = (GameNetworkData) xStream.fromXML(xml);
game.setToGameDataBase();
}
}

public static void getAllOfGame(Response response) {
StringBuilder xmlBuilder = new StringBuilder("");
xmlBuilder.append(response.getData());
for (int i = 0; i < 49; i++) {
xmlBuilder.append(Network.getInstance().getResponse().getData());
}
String xml = xmlBuilder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public enum RequestEnum {
INVITATION_REJECTED,
SEND_DATA,
GET_DATA,
GO_TO_GAME_MENU;
GO_TO_GAME_MENU, START_GAME;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class TileMode {
//////////////////////

/////////////////////
private transient ArrayList<TileFeatureEnum> possibleFeature;
private transient ArrayList<TileResourceEnum> possibleResources;
private ArrayList<TileFeatureEnum> possibleFeature;
private ArrayList<TileResourceEnum> possibleResources;

public TileMode(TileModeEnum tileName) {
setTileName(tileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ private void updateEverything() {
}

public void startGame(MouseEvent mouseEvent) {
timeline.stop();
GameNetworkData.getGame();
PlayGamePage.getInstance().setUp();
System.out.println(103);
MenuChanger.changeMenu("Game");
System.out.println(105);
}

public void back(MouseEvent mouseEvent) throws IOException {
Expand Down
25 changes: 14 additions & 11 deletions Client/src/main/java/com/example/project/views/MainMenuPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class MainMenuPage {
private Label notificationMessage;
private String labelMessage = null;
private boolean gameStarted = false;
private boolean popUpShowed = false;

private Timeline timeline;

Expand All @@ -36,6 +37,12 @@ public void initialize() {

public void updateMessageLabel() {
timeline = new Timeline(new KeyFrame(Duration.millis(100), actionEvent -> {
if (gameStarted && !popUpShowed) {
synchronized (this) {
popUpShowed = true;
}
new PopupMessage(Alert.AlertType.INFORMATION, "you can join the game now");
}
if (labelMessage != null) {
synchronized (this) {
notificationMessage.setText(labelMessage);
Expand All @@ -61,20 +68,15 @@ public void run() {
timeline.stop();
return;
} else {
StringBuilder xml = new StringBuilder("");
xml.append(response.getData());
for (int i = 0; i < 29; i++)
xml.append(Network.getInstance().getResponse().getData());
XStream xStream = new XStream();
xStream.addPermission(AnyTypePermission.ANY);
if (xml.length() != 0) {
GameNetworkData game = (GameNetworkData) xStream.fromXML(xml.toString());
game.setToGameDataBase();
}
System.out.println(71 + "main menu");
GameNetworkData.getAllOfGame(response);
PlayGamePage.getInstance().setUp();
synchronized (MainMenuPage.this) {
popUpShowed = false;
}
gameStarted = true;
new PopupMessage(Alert.AlertType.INFORMATION, "you can join the game now");
timeline.stop();
System.out.println(79 + "main menu");
return;
}
}
Expand All @@ -85,6 +87,7 @@ public void run() {

public void startGame(MouseEvent mouseEvent) {
if (gameStarted) {
Network.getInstance().sendRequestWithoutResponse(new Request(RequestEnum.START_GAME));
timeline.stop();
MenuChanger.changeMenu("Game");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.stage.Stage;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class MenuChanger extends Application {
Expand Down
42 changes: 37 additions & 5 deletions Client/src/main/java/com/example/project/views/PlayGamePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import com.example.project.controllers.GameControllers.GameMenuCommandController;
import com.example.project.controllers.GameControllers.PlayGameMenuController;
import com.example.project.models.MainGameSaver;
import com.example.project.models.Game;
import com.example.project.models.Player;
import com.example.project.models.*;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
Expand All @@ -31,7 +30,7 @@ public class PlayGamePage {
private GameMenuCommandController gameMenuCommandController;
private PlayGameMenuController playGameMenuController;
private boolean isMouseOnTile = true;
private boolean isOnMap = true;
private boolean isOnMap = Game.isIsYourTurn();
private Pane instanceGameMapPane;

public boolean isOnMap() {
Expand Down Expand Up @@ -142,9 +141,33 @@ public static PlayGamePage getInstance() {
private VBox settingsVBox;
@FXML
private CheckBox autoSaveSetting;
private Thread updateMapThread;

private Pane waitingPane;


private void updateNetworkMap() {
updateMapThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
Response response = Network.getInstance().getResponse();
if (response.getOutput() == Output.GAME_DATA) {
GameNetworkData.getAllOfGame(response);
getInstance().isOnMap = Game.isIsYourTurn();
} else return;
}
}
});
updateMapThread.start();
}

public void initialize() {
waitingPane = new Pane();
waitingPane.setPrefHeight(800);
waitingPane.setPrefWidth(1530);

updateNetworkMap();
settingsVBox.setVisible(false);
getInstance().instanceGameMapPane = this.mapPane;
infoVBox.setBackground(new Background(new BackgroundFill(Color.DARKGREY, new CornerRadii(20), null)));
Expand Down Expand Up @@ -206,13 +229,15 @@ private void update() {
Timeline timeline = new Timeline(new KeyFrame(Duration.millis(500), actionEvent -> {
try {
if (getInstance().isOnMap) {
mapPane.setEffect(null);
ShowMapFXController.getInstance().showMap();
ShowPanelFXController.getInstance().updateStatusBar();
ShowPanelFXController.getInstance().updateResearchBar();
UnitCommandFxController.getInstance().update();
Game.getInstance().updatePlayers();
endGame();
}
} else if (!Game.isIsYourTurn())
showWaitingForTurn();
} catch (MalformedURLException e) {
e.printStackTrace();
}
Expand All @@ -221,6 +246,13 @@ private void update() {
timeline.play();
}

private void showWaitingForTurn() {
if (!mapPane.getChildren().contains(waitingPane)) {
mapPane.getChildren().add(waitingPane);
mapPane.setEffect(new GaussianBlur(20));
}
}

public void moveMap(KeyEvent keyEvent) {
if (keyEvent.getCode().getName().equals("Left"))
ShowMapFXController.getInstance().moveLeft();
Expand Down
Binary file modified Client/target/classes/com/example/project/models/Game.class
Binary file not shown.
Binary file modified Client/target/classes/com/example/project/models/GameMap.class
Binary file not shown.
Binary file not shown.
Binary file modified Client/target/classes/com/example/project/models/RequestEnum.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Client/target/classes/com/example/project/views/MainMenuPage.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Client/target/classes/com/example/project/views/PlayGamePage.class
Binary file not shown.
Loading

0 comments on commit f2c47b4

Please sign in to comment.