You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Decompose monolithic Game class into multiple specialized classes
to adhere to the Single Responsibility Principle. This improves
modularity, testability, and maintainability.
Changes include:
- **GameWindow.java**: New class to manage the main JFrame, application
setup, and includes the `main` method. Replaces GUI setup aspects
of the original Game class.
- **GameManager.java**: New class responsible for all game logic,
state management (score, game over, entity states), game loop timers,
and collision detection. Extracts core game mechanics from the
original Game class.
- **GamePanel.java**: Refactored from `DrawPanel`. Now solely responsible
for rendering all game elements (dinosaur, cacti, environment,
UI text) based on data from GameManager. Drawing methods moved
here from the original Game class.
- **Dinosaur.java**: New entity class to manage the state and behavior
(e.g., jump logic) of the player's dinosaur.
- **Cactus.java**: New entity class (replaces inner class `MyGraph`) to
manage the state and properties of cactus obstacles.
- **InputHandler.java**: New class dedicated to processing keyboard inputs
and translating them into game actions for GameManager. Replaces
KeyListener implementation in the original Game class and input
action in DrawPanel.
- Removed direct drawing, game logic, and input handling responsibilities
from the original Game class structure. The `Game.unit` constant
is temporarily kept but should ideally move to a Constants class or
relevant configuration.
This refactoring makes each component of the game more focused,
easier to understand, test in isolation, and modify without
impacting unrelated parts of the system.
0 commit comments