This project implements a grid‑based simulation where an autonomous agent moves, collects jewels, fights guardians, and navigates a randomly generated environment.
It was developed as part of the Object-Oriented Programming coursework at Sorbonne Université.
The project demonstrates full mastery of Java OOP: classes, inheritance, exceptions, collections, simulation loops, and interaction between multiple objects on a grid.
The simulation consists of:
- A 2D grid (
Grille) containing:- Joyaux (jewels) with different values
- Gardiens (guardians) with hit points
- An Agent5 that can:
- Move in 4 directions
- Collect jewels
- Fight guardians
- Maintain a bag (
sac) of collected items
- A Simulation class that:
- Randomly populates the grid
- Moves the agent for a chosen number of steps
- Handles interactions (pickup, combat)
- Displays the state of the grid at each step
- A full set of custom exceptions ensuring correctness:
CoordonneesIncorrectesExceptionCaseNonPleineExceptionDeplacementIncorrectException
- Holds agent position
(x, y) - Contains a bag (
ArrayList<Joyau>) - Movement system (
seDeplacer) - Jewel collection
- Guardian combat
- Computes total fortune collected
- Abstract representation of any object on the grid
(jewel or guardian) - Stores:
- ID
- Type
- Quantity
- Position
(x, y)
- Extends
Contenu - Holds a jewel type (diamant, rubis, opale)
- Holds jewel value
- Extends
Contenu - Has hit points (
pointDeVie) - Loses HP during combat
Raised when attempting to interact with an empty grid cell.
Raised when coordinates are outside the grid.
Raised when the agent attempts an invalid movement.
- Initializes the grid with:
- Probability of jewel (
PJOY = 0.8) - Probability of combat strength addition (
PFORCE = 0.3)
- Probability of jewel (
- Places m random objects in the grid
- Places the agent randomly
- Performs
nbEtapessimulation steps:- Chooses a valid direction
- Moves the agent
- Handles interactions
- Displays the grid and agent state
Runs a full simulation and can redirect output to a file.
Compile all Java files:
javac *.javaRun the test simulation:
java TestSimulationTo redirect output to a file:
java TestSimulation output.txt