Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexphanna/open-battleship
Simple language for local multiplayer Battleship with different graphical user interfaces. Made for AP Computer Science A in junior year of high school.
https://github.com/alexphanna/open-battleship
Last synced: about 1 month ago
JSON representation
Simple language for local multiplayer Battleship with different graphical user interfaces. Made for AP Computer Science A in junior year of high school.
- Host: GitHub
- URL: https://github.com/alexphanna/open-battleship
- Owner: alexphanna
- Created: 2023-02-17T05:33:42.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-18T19:22:35.000Z (over 1 year ago)
- Last Synced: 2024-11-08T02:42:51.105Z (3 months ago)
- Language: Java
- Homepage:
- Size: 29.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Open-Battleship
## Requirements
- Ships may be placed beside each other, but may NOT overlap
- Each player has five ships (2, 3, 3, 4, 5)
- Each player takes one shot per turn (no streaks)## How it works
After arranging their ships, player 1 sends their targeted square (e.g.: A4, C6, F2) encoded in bytes to the opponent and waits to recieve a response. Player 2 recieves their targeted sqaure and sends back a boolean of whether a ship is on the targeted square encoded in bytes. The same steps happen again, but the order swaps and the player 2 sends their targeted square to player 1. Use [Convert.java](https://github.com/alexphanna/Open-Battleship/blob/main/Convert.java) to convert from boolean and (row, column) to bytes.| Value | Bytes |
| ------ | ------ |
| false | 0 |
| true | 1 |
| (0, 0) | {0, 0} |## Basic Implementation
### Receiving```java
DatagramSocket socket = new DatagramSocket(PORT);
byte[] buffer = new byte[512];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);
System.out.println(new String(buffer, 0, buffer.length));
```### Sending
```java
DatagramSocket socket = new DatagramSocket();
String str = "hello world";
byte[] buffer = str.getBytes();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, ADDRESS, PORT);
socket.send(packet);
```
## Contributions
- [Alex Hanna](https://github.com/alexphanna)
- [Brayden Hanna](https://github.com/braydenphanna)
- [Edward Akselrud](https://github.com/Efaks)
- [Matt Romano](https://github.com/MatthewDRomano)