Skip to content

Commit

Permalink
feat: removed placed cards before every get
Browse files Browse the repository at this point in the history
  • Loading branch information
Artewald committed Apr 17, 2024
1 parent 0c6ada2 commit c55f13b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/src/com/softwarearchitecture/game_client/GameClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.util.Optional;
import java.util.UUID;

import com.softwarearchitecture.ecs.ComponentManager;
import com.softwarearchitecture.ecs.ECSManager;
import com.softwarearchitecture.ecs.Entity;
import com.softwarearchitecture.ecs.components.PlacedCardComponent;
import com.softwarearchitecture.game_client.states.Menu;
import com.softwarearchitecture.game_client.states.ScreenManager;
import com.softwarearchitecture.game_server.GameState;
Expand Down Expand Up @@ -32,20 +35,29 @@ public void update() {
gameId = screenManager.getGameId();
Optional<GameState> game = defaultControllers.clientMessagingController.requestGameState(gameId);
if (game.isPresent()) {
removePlacedCardsFromScreen();
game.get();
screenManager.lateActivateCurrentState();
// System.out.println("[CLIENT] Requested game gotten: " + game.get());
}
}
if (defaultControllers.gameServer.getGameId() != null) {
gameId = defaultControllers.gameServer.getGameId();
Optional<GameState> game = defaultControllers.clientMessagingController.requestGameState(gameId);
if (game.isPresent()) {
removePlacedCardsFromScreen();
game.get();
screenManager.lateActivateCurrentState();
// System.out.println("[CLIENT] Requested game gotten: " + game.get());
}
}
// System.out.println("[CLIENT] Entities " + ECSManager.getInstance().getEntities().size());
}

private void removePlacedCardsFromScreen() {
ComponentManager<PlacedCardComponent> placedCardManager = ECSManager.getInstance().getOrDefaultComponentManager(PlacedCardComponent.class);
for (Entity entity : ECSManager.getInstance().getEntities()) {
if (placedCardManager.getComponent(entity).isPresent()) {
ECSManager.getInstance().removeEntity(entity);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void run(String mapName) {

// Main gameplay loop
boolean gamesOver = false;

while (!gamesOver) {

float deltatime = 1.0f;
Expand Down

0 comments on commit c55f13b

Please sign in to comment.