Welcome to the Guessing Game API! This is a backend service for a number guessing game where players can play either against each other or against an AI. It includes features like scoring, hints, multiple game modes, and AI interactions.
-
Game Modes:
- Normal Mode: Players guess a 4-digit secret code.
- Extreme Mode: Players guess a 6-digit secret code (unlocked at a specific score threshold).
-
AI Integration:
- Play against an AI in reverse mode, where the AI guesses and the player provides feedback.
- Hints are generated by AI for players (with score deductions).
-
User Management:
- Users have a
scorethat increases with wins:- +5 for Normal Mode wins.
- +10 for Extreme Mode wins.
- Users lose 5 points for:
- Leaving a game.
- Using AI-generated hints (max 3 per game).
- Users have a
-
Game Lifecycle:
- Join, leave, and manage game statuses.
- Secure game access with game passwords.
-
Authentication and Authorization:
- Role-based access control:
- Admin: Manage games.
- Player: Play and interact with the game.
- Role-based access control:
-
API Documentation:
- Automatically generated Swagger UI for API exploration.
- Spring Boot: Backend framework for building RESTful APIs.
- Spring Security: Authentication and authorization.
- JWT: Secure token-based authentication.
- Spring Data JPA: Database interaction.
- PostgreSQL: Database management.
- Springdoc OpenAPI: Auto-generated Swagger documentation.
- OpenAI API: AI-powered game interactions.
- Docker: Containerization for running services.
- AWS EC2: Hosting the application on a virtual machine.
- AWS ECR: Storing Docker images.
- Java 17+
- Maven
- PostgreSQL installed locally or Docker
- Docker (optional but recommended)
- Clone the Repository
git clone https://github.com/yourusername/guessing-game-api.git cd guessing-game-api - Setup Database
- option 1: Run PostgreSQL locally.
- option 2: Use Docker:
docker run --name guessing-game-db -e POSTGRES_DB=guessing_game -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=yourpassword -p 5432:5432 -d postgres- Update Configuration Edit the application.properties file:
spring.datasource.url=jdbc:postgresql://localhost:5432/guessing_game
spring.datasource.username=postgres
spring.datasource.password=yourpassword
- Run the Application
mvn spring-boot:run
Authentication
- POST /login - Login and get JWT token.
- POST /login - Login and get JWT token. Game Management
- POST /game/create - Create a new game.
- POST /game/join - Join an existing game.
- POST /game/leave - Leave the game.
- DELETE /game/{id} - Delete a game.
Guessing
- POST /guess/play - Make a guess in the game.
- POST /guess/ai - Play against the AI in reverse mode.
AI Integration
- POST /ai/hint - Request a hint from the AI (deducts 5 points).
- GET /ai/guess - Get a guess from the AI for reverse mode.
Scoring System
- Win (Normal Mode): +5 points
- Win (Extreme Mode): +10 points
- Use a Hint: -5 points (max 3 hints per game)
- Leave a Game: -5 points
- Build Docker Image
docker build -t guessing-game-api .
- Run Docker Container
docker run -p 8080:8080 guessing-game-api
Run the test suite using Maven:
mvn test
Contributions are welcome! Please open an issue or submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.