From c164daed53574babb26796b05682432709e2c5c1 Mon Sep 17 00:00:00 2001 From: mithe24 Date: Wed, 7 May 2025 17:11:58 +0200 Subject: Feature/json parser (#18) * chore(model/json-parser): Added maven dependency * chore(model): Removed old test JSON file * refactor(model/GameState): List better then map, entities should be able to overlap * feat(Pacman): Added GameState builder to initiate GameState with given paramters. Added a short example JSON-file, more key-value pairs needs to be added as the game progresses. Likewise the builder won't parse for any other key-value pair automatically. --- .../main/java/com/gr15/pacman/controller/GameApp.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'pacman/controller/src/main/java/com/gr15') diff --git a/pacman/controller/src/main/java/com/gr15/pacman/controller/GameApp.java b/pacman/controller/src/main/java/com/gr15/pacman/controller/GameApp.java index 1c8bc75..ffd4493 100644 --- a/pacman/controller/src/main/java/com/gr15/pacman/controller/GameApp.java +++ b/pacman/controller/src/main/java/com/gr15/pacman/controller/GameApp.java @@ -1,7 +1,9 @@ package com.gr15.pacman.controller; +import java.io.InputStream; + import com.gr15.pacman.model.GameState; -import com.gr15.pacman.model.JsonParser; +import com.gr15.pacman.model.GameStateBuilder; import com.gr15.pacman.view.GameView; import javafx.application.Application; @@ -23,14 +25,13 @@ public class GameApp primaryStage.setResizable(false); primaryStage.setFullScreen(true); - try { - gameState = JsonParser.getGameState("test"); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Failed to load game state: " + e.getMessage()); - } - - gameView = new GameView(gameState, 8, 5); + InputStream inputStream = this.getClass() + .getResourceAsStream("/testGameState.json"); + GameState gameState = GameStateBuilder.fromJson(inputStream); + inputStream.close(); + int tileWidth = gameState.getBoard().getWidth(); + int tileHeight = gameState.getBoard().getHeight(); + gameView = new GameView(gameState,tileWidth, tileHeight); primaryStage.setScene(gameView); gameController = new GameController(gameState, gameView); -- cgit v1.2.3-70-g09d2