public void NewGameState(string gameStateString) { // Convert the string to our DTO format. GameStateDTO gameState = ConvertJSONtoDTO(gameStateString); // Check if this is the first game-state event received. If so, set // up the terrain and don't do it ever again. if (gameStateEventCount == 1) { TerrainGenerator terrainGenerator = new TerrainGenerator(); int width = terrainGenerator.CalculateWidthFromGameState(gameState); int height = terrainGenerator.CalculateHeightFromGameState(gameState); TerrainDTO terrainDTO = new TerrainDTO(width, height); terrainGenerator.GenerateTerrainMMO(terrainDTO); OverlayGenerator overlayGenerator = new OverlayGenerator(terrainFolder: terrainGenerator.terrainFolder); overlayGenerator.GenerateGridForTerrain(terrainDTO); // Generate the obstacles only on initial game creation. Don't duplicate. ObstacleDTO[] obstacles = gameState.obstacles; obstacleManager.UpdateFeatures(obstacles); } RenderGameState(gameState); gameStateEventCount++; }
public void TestCalculateWidthFromGameState() { int southWestX = -20; int northEastX = 10; GameStateDTO gameState = new GameStateDTO(); gameState.southWestCorner = new Location(southWestX, 0); gameState.northEastCorner = new Location(northEastX, 0); // Row with x=0 is expected too. Assert.AreEqual(31, generator.CalculateWidthFromGameState(gameState)); }