How kerema14/traffic-control-simulator works
Project Type and Purpose
• This is a desktop Java game built with JavaFX (JDK 21).
• It simulates traffic control on a grid of roads, includes a built-in level editor, and loads/saves predefined levels.
• Key functionality: render interactive UI panes, manage game state, parse plain-text level files, and orchestrate vehicle and traffic-light behaviors.
File Structure Analysis
• Top-level directories:
• bin: compiled classes (TrafficControlSimulator) and level resources (bin/levels/*.txt).
• lib: external JavaFX JARs for UI, graphics, media, etc.
• src: application source under package TrafficControlSimulator and raw level files (src/levels/).
• src/TrafficControlSimulator:
• Main.java – app entry point, JavaFX Application subclass.
• Game.java – central game loop and state manager.
• LevelParser.java – reads and interprets level#.txt into game objects.
• EditorPane.java / LevelPane.java – JavaFX UI controllers for the editor and play modes.
• Domain classes: Building, RoadTile, TrafficLight, Vehicle.
Insights from README
• Confirms JavaFX usage and level designer feature.
a. Main Components
• User Interface Layer (JavaFX):
– Main Window (Main.java → primaryStage)
– EditorPane
– LevelPane
• Application Core:
– Game Engine (Game.java)
– Domain Model (Building, RoadTile, TrafficLight, Vehicle)
• Persistence / I/O:
– LevelParser (reads/writes *.txt)
– File System (src/levels & bin/levels)
• External Dependencies:
– JavaFX libraries (lib/javafx-*.jar)
b. Relationships & Data Flows
• Main initializes JavaFX, loads UI panes.
• UI panes invoke Game to load or edit a level.
• Game calls LevelParser → reads level file → returns domain objects.
• Game populates Domain Model → notifies UI for rendering.
• User actions in EditorPane generate events → passed to Game → update Domain Model → UI refresh.
• Game loop triggers AI/movement logic on Vehicle/TrafficLight → updates UI.
c. Architectural Patterns & Principles
• MVC-like separation: UI controllers (EditorPane/LevelPane) vs. Game logic vs. Domain entities.
• Single process, layered architecture: UI → Core → Persistence → File system.
• Clear separation of concerns: parsing, state management, rendering, and domain behaviors.
d. Key Technologies & Frameworks
• Java 21
• JavaFX (Controls, FXML, Graphics, Media)
• Plain-text level definitions