Skip to content

Commit 69dc6a3

Browse files
committed
technology tree
1 parent 668d3a0 commit 69dc6a3

File tree

7 files changed

+34
-3
lines changed

7 files changed

+34
-3
lines changed

Client/src/main/java/Client/enums/QueryRequests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public enum QueryRequests {
130130
GET_CIVILIZATION_TRADES,
131131
ACCEPT_TRADE,
132132
EDIT_MESSAGE,
133-
DELETE_MESSAGE
133+
DELETE_MESSAGE,
134+
//
135+
GET_TECHNOLOGY_STATUS,
134136

135137
}

Client/src/main/java/Client/enums/QueryResponses.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ public enum QueryResponses {
3434
NOT_ENOUGH_GOLD,
3535
NO_CITIZEN_EXISTS,
3636
SELECT_TILE_IN_CITY,
37+
//
38+
TECHNOLOGY_WAS_STUDIED,
39+
TECHNOLOGY_IS_BEING_STUDIED,
40+
TECHNOLOGY_HAS_NOT_BEEN_STUDIED,
41+
3742

3843
}

Client/src/main/java/Client/enums/Technologies.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import Client.application.App;
44
import Client.controllers.ClientSocketController;
5+
import Client.models.network.Response;
6+
import com.google.gson.Gson;
57
import javafx.scene.Cursor;
68
import javafx.scene.Group;
79
import javafx.scene.image.Image;
@@ -105,7 +107,13 @@ public static Technologies generateRandom() {
105107

106108
public Group getTechnologyGroup(int x, int y) {
107109
Group group = new Group();
108-
Rectangle nameRectangle = new Rectangle(230, 27, Color.CADETBLUE);
110+
Response response = ClientSocketController.sendRequestAndGetResponse(QueryRequests.GET_TECHNOLOGY_STATUS, new HashMap<>(){{put("technology", new Gson().toJson(this));}});
111+
Rectangle nameRectangle = null;
112+
switch (Objects.requireNonNull(response).getQueryResponse()) {
113+
case TECHNOLOGY_WAS_STUDIED -> nameRectangle = new Rectangle(230, 27, Color.GREEN);
114+
case TECHNOLOGY_IS_BEING_STUDIED -> nameRectangle = new Rectangle(230, 27, Color.GOLD);
115+
case TECHNOLOGY_HAS_NOT_BEEN_STUDIED -> nameRectangle = new Rectangle(230, 27, Color.CADETBLUE);
116+
}
109117
nameRectangle.setLayoutX(x);
110118
nameRectangle.setLayoutY(y - nameRectangle.getHeight());
111119
Rectangle turnsRectangle = new Rectangle(145, 27, Color.rgb(238, 128, 0));

Server/src/main/java/Server/enums/QueryRequests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,7 @@ public enum QueryRequests {
130130
GET_CIVILIZATION_TRADES,
131131
ACCEPT_TRADE,
132132
EDIT_MESSAGE,
133-
DELETE_MESSAGE
133+
DELETE_MESSAGE,
134+
//
135+
GET_TECHNOLOGY_STATUS,
134136
}

Server/src/main/java/Server/enums/QueryResponses.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ public enum QueryResponses {
3434
NOT_ENOUGH_GOLD,
3535
NO_CITIZEN_EXISTS,
3636
SELECT_TILE_IN_CITY,
37+
//
38+
TECHNOLOGY_WAS_STUDIED,
39+
TECHNOLOGY_IS_BEING_STUDIED,
40+
TECHNOLOGY_HAS_NOT_BEEN_STUDIED,
3741
}

Server/src/main/java/Server/models/Civilization.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,10 @@ public City getCityByName(String name) {
303303
}
304304
return null;
305305
}
306+
307+
public QueryResponses getTechnologyStatus(Technologies technology) {
308+
if (this.technologies.get(technology) <= 0) return QueryResponses.TECHNOLOGY_WAS_STUDIED;
309+
else if (this.currentTechnology.equals(technology)) return QueryResponses.TECHNOLOGY_IS_BEING_STUDIED;
310+
else return QueryResponses.TECHNOLOGY_HAS_NOT_BEEN_STUDIED;
311+
}
306312
}

Server/src/main/java/Server/models/network/ServerSocketHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ public Response handleRequest(Request request) throws IOException {
690690
Civilization civilization = WorldController.getWorld().getCivilizationByName(WorldController.getWorld().getCurrentCivilizationName());
691691
WorldController.setSelectedCity(civilization.getCityByName(request.getParams().get("cityName")));
692692
}
693+
case GET_TECHNOLOGY_STATUS -> {
694+
Civilization civilization = WorldController.getWorld().getCivilizationByName(WorldController.getWorld().getCurrentCivilizationName());
695+
return new Response(civilization.getTechnologyStatus(new Gson().fromJson(request.getParams().get("technology"), Technologies.class)), new HashMap<>());
696+
}
693697
}
694698
return new Response(QueryResponses.OK, new HashMap<>());
695699
}

0 commit comments

Comments
 (0)