Skip to content

MostafaTahboub/Spy-Game

Repository files navigation

Guessing Game API

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.


Features

  1. 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).
  2. 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).
  3. User Management:

    • Users have a score that 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).
  4. Game Lifecycle:

    • Join, leave, and manage game statuses.
    • Secure game access with game passwords.
  5. Authentication and Authorization:

    • Role-based access control:
      • Admin: Manage games.
      • Player: Play and interact with the game.
  6. API Documentation:

    • Automatically generated Swagger UI for API exploration.

Technologies Used

  • 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.

Setup and Installation

Prerequisites

  • Java 17+
  • Maven
  • PostgreSQL installed locally or Docker
  • Docker (optional but recommended)

Steps

  1. Clone the Repository
    git clone https://github.com/yourusername/guessing-game-api.git
    cd guessing-game-api
    
  2. 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
  1. Update Configuration Edit the application.properties file:
spring.datasource.url=jdbc:postgresql://localhost:5432/guessing_game
spring.datasource.username=postgres
spring.datasource.password=yourpassword
  1. Run the Application
mvn spring-boot:run

Endpoints

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

Run with Docker

  1. Build Docker Image
docker build -t guessing-game-api .
  1. Run Docker Container
docker run -p 8080:8080 guessing-game-api

Testing

Run the test suite using Maven:

mvn test

Contributing

Contributions are welcome! Please open an issue or submit a pull request with your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •