Skip to content

Simple language for local multiplayer Battleship with different graphical user interfaces. Made for AP Computer Science A in junior year of high school.

Notifications You must be signed in to change notification settings

alexphanna/open-battleship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 

Repository files navigation

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 to convert from boolean and (row, column) to bytes.

Value Bytes
false 0
true 1
(0, 0) {0, 0}

Basic Implementation

Receiving

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

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

About

Simple language for local multiplayer Battleship with different graphical user interfaces. Made for AP Computer Science A in junior year of high school.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages