A classic game of Battleships designed to be played by two people using two Arduino RP2040 devices and a central server. This project implements the traditional Battleships game in a modern, electronic format using Arduino RP2040 microcontrollers. Players can enjoy the classic naval combat strategy game with a digital twist, making it more interactive and engaging.

- Two-player gameplay using Arduino RP2040 devices
- Central server communication for game coordination
- Classic Battleships gameplay mechanics
- Written in C++ for Arduino platform
- Real-time gameplay with WebSocket communication
- Secure and reliable game state management
- 2x Arduino RP2040 boards
- Development environment with Arduino IDE
- Python 3.x for server component
- Network connectivity between devices
- Required Arduino libraries (list to be added)
- Central server setup capability

- VCC -> 5V
- GND -> GND
- CLK -> D13
- MISO -> D12
- MOSI -> D11
- CS -> D10
- DC -> D9
- VCC -> 3.3V
- GND -> GND
- X -> A1
- Y -> A0
- VCC -> 3.3V
- GND -> GND
- BTN -> D3
-
Clone the repository:
git clone https://github.com/imgmaterial/Arduino_BattleShips.git
-
Open the Arduino project:
- Launch Arduino IDE
- Open the project folder
- Install required dependencies through Arduino Library Manager
-
Configure Network Settings:
- Update WiFi credentials
- Set server IP address
- Configure any additional network parameters
-
Upload to Devices:
- Connect Arduino RP2040 boards
- Select appropriate board and port
- Upload the code to both devices
- Install Python requirements
- Configure network settings
- Launch server application
- Python 3.x
- websockets library (
pip install websockets) - Network connectivity between devices
- Install the required Python package:
pip install websockets
- Configure the server IP:
# In server.py, modify the IP address to match your network setup async with serve(handler, "YOUR_IP_ADDRESS", YOUR_PORT) as server:
- Run the server:
python server.py
The server implements the following message protocols:
- REGISTER:
REGISTER:player_name- Registers a new player with the server
- GRID:
GRID:grid_data:player_id- Sends the player's ship placement grid
- BOATS:
BOATS:data1:data2:data3:player_id- Communicates boat destruction status
- ATTACK:
ATTACK:player_id:x:y- Sends attack coordinates
- Server Responses:
GAMESTART: Game initiationTURN:state: Turn indicatorATTACKRESULT:x:y:result: Attack outcomeDEFENCE:x:y:result: Incoming attack notificationGAMEEND:player_id: Victory announcement
- Player Registration
- Ship Placement Phase
- Active Gameplay
- Game End
- Power on both Arduino RP2040 devices
- Start the Python server
- Wait for both devices to connect
- Follow on-screen instructions for ship placement
- Players take turns selecting attack coordinates
- System provides feedback on hits and misses
- Game continues until all ships of one player are sunk
- Victory is announced to both players
This project is licensed under the MIT License - see the LICENSE file for details.
