Battleships Game Flutter is a mobile application developed using Flutter that allows users to register, log in, and play the classic game of Battleships against both human and computer opponents. The application integrates with a RESTful API for user authentication and game management.
- User Authentication: Register and log in with persistent session tokens.
- Game Management: List ongoing and completed games, start new games with human or AI opponents, and delete games.
- Gameplay: Place ships on a 5x5 grid, play turns, and see real-time updates of game status and results.
To get started with the Battleships Game Flutter application, follow the instructions below.
- Flutter installed on your local machine.
- Access to the Battleships RESTful API.
-
Clone the repository:
git clone https://github.com/Mahmood-Anaam/Battleships-Game-Flutter.git cd Battleships-Game-Flutter
-
Install dependencies:
flutter pub get
-
Configure the API:
- Add your API base URL in the necessary configuration files.
To run the app on an emulator or physical device, use the following command:
flutter run
http
: For making HTTP requests to the RESTful API.shared_preferences
: For storing session tokens and user preferences.provider
: For state management.
The Battleships REST API service can be accessed at the base URL http://165.227.117.48
. All routes that require body content accept JSON data, and all responses are JSON objects. Here are some key endpoints:
-
Register:
POST /register
- Request body:
{ "username": "your_username", "password": "your_password" }
- Response:
{ "message": "User created", "access_token": "token" }
- Request body:
-
Login:
POST /login
- Request body:
{ "username": "your_username", "password": "your_password" }
- Response:
{ "message": "Logged in", "access_token": "token" }
- Request body:
-
List Games:
GET /games
- Response:
{ "games": [ ... ] }
- Response:
-
Start Game:
POST /games
- Request body:
{ "ships": ["A1", "A2", "A3", "A4", "A5"], "ai": "random" }
- Response:
{ "id": "game_id", "player": 1, "matched": true }
- Request body:
-
Game Details:
GET /games/{game_id}
- Response:
{ "id": "game_id", "status": 0, "position": 1, "turn": 1, "player1": "user1", "player2": "user2", "ships": ["A1"], "wrecks": ["A2"], "shots": ["A3"], "sunk": ["A4"] }
- Response:
-
Play Shot:
PUT /games/{game_id}
- Request body:
{ "shot": "B2" }
- Response:
{ "message": "Shot played", "sunk_ship": true, "won": false }
- Request body:
-
Delete Game:
DELETE /games/{game_id}
- Response:
{ "message": "Game deleted" }
- Response:
The application is available for download in APK format for Android devices at the following link: Download APK