Inspiration

We like playing the text message version of battleship and we wanted to create our own version.

What it does

The program allows a host player to setup a game socket and have another player connect to play battleship remotely. The boards for battleship are printed to the console and move selection is done through standard input.

How we built it

We use Java to create both the game board representations and player (server/client) sockets.

Challenges we ran into

One challenge that we ran into was passing whether a move hit or missed through the sockets, especially when this resulted in a sunken ship because once a ship is sunk, then all the adjacent spaces are marked as containing no ships. Because each player only maintains a copy of their board and a initially blank board for the opponent, we had to figure out a way to pass all of the board updates through the sockets. We did this by keeping lists of previous hits and misses for the players game board and passing that through the sockets each time an opponents move was made. Another challenge we ran into was validating ship positions in the initial setups of the boards. In the game of BattleShip, ships cannot be touching when they are placed. So, we had to check that when a ship was placed, there were no ships surrounding it. This was a challenge because we had to adjust in the case of index of out bounds errors when these ships were on the edges of the board.

Accomplishments that we're proud of

One of the things we are most proud of is that the player has the option of receiving a randomized legal playing board. Another thing that we are proud of is getting the multiplayer connections to work right.

What we learned

We learned more about socket programming and how to send data between sockets to synchronize the game boards on each player's move.

What's next for Socket Battleship

One thing that we could add is a graphical interface to show the board and allow players to select their moves.

Built With

Share this project:

Updates