This project is a solution to a coding interview task. It simulates a battle arena where different types of heroes (Archers, Cavalry, and Swordsmen) fight according to specific rules. The battle continues until there is at most one hero left standing.
- ArenaBattle: The main project containing the implementation of the battle simulation.
- Controllers: Contains the API controllers.
- Models: Contains the hero classes and other data models.
- Services: Contains the business logic for the battle simulation.
- ArenaBattle.Tests: The test project containing unit tests for the application.
-
Clone the repository:
git clone https://github.com/tigyijanos/ArenaBattle.git cd ArenaBattle
-
Navigate to the main project directory:
cd ArenaBattle
-
Restore the dependencies:
dotnet restore
-
Build the project:
dotnet build
-
Run the project:
dotnet run
-
Access the API: Open your browser and navigate to
https://localhost:5001/swagger
to see the Swagger UI and test the API endpoints.
POST /api/Arena/create
: Creates a new arena with a specified number of heroes.POST /api/Arena/battle/{arenaId}
: Simulates a battle in the specified arena.
-
Navigate to the test project directory:
cd ../ArenaBattle.Tests
-
Run the tests:
dotnet test
-
Archer:
- Initial Health: 100
- Attacks: Has specific rules for attacking Cavalry, Swordsmen, and other Archers.
-
Cavalry:
- Initial Health: 150
- Attacks: Has specific rules for attacking Cavalry, Swordsmen, and Archers.
-
Swordsman:
- Initial Health: 120
- Attacks: Has specific rules for attacking Cavalry, Swordsmen, and Archers.
-
Hero Base Class:
- Abstract base class for all hero types.
- Contains properties for ID, Type, and Health.
- Methods for reducing and increasing health.
-
Derived Hero Classes:
Archer
,Cavalry
,Swordsman
- Inherit from
Hero
base class and implement type-specific logic.
-
Arena Service:
- Contains the main logic for creating arenas and simulating battles.
- Methods for resolving attacks and managing hero health.
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.