Inspiration

Over a month back, I had a project in computer programming where we were to make a game that utilized a 2D grid. I chose to do chess, but alas, I was not able to finish the project in time. This was my first hackathon and so I wasn't really prepared to do anything groundbreaking. So, I decided to give that old, dusty project another shot with a different game.

What it does

This is quite a simple project and thus merely emulates the classic board game of Battleship. The initial UI is a website with a login page, with then links to a download to the .zip file containing the game.

Note: When unzipping the folder, the jar file for the game is in out/artifacts.

How I built it

I used the processing library in order to create the drawings. I created a GameBoard class that modified a 2D array of characters representing what was at each grid space and a Player class that had two GameBoards, one for the ships and one to keep track of hits and misses. Finally, the BattleShip class put it all together with the GUI.

Challenges I ran into

One major challenge was figuring out how to get the computer to randomly place the ships correctly without any major bugs (and by major I mean stuff like infinite loops). Later, there was the challenge of checking that the player's ships were placed correctly as well. Eventually, I just decided to let the player place the ships wherever they want and hope they follow the rules. If they don't... nothing's going to happen. But please follow the rules.

Accomplishments that I'm proud of

I am proud of the fact that I actually managed to complete this game, after my failure to complete my last related project, after around 10 hours of relentlessly coding. Often I take a lot longer to do things, mainly because I take lots of breaks and spread the work out over multiple days. I will say, though, that I felt more productive yesterday than I have in a long time.

What I learned

When I arrived at this hackathon, I had no idea what was in store or how a hackathon even worked, hence my lack of preparation with a more innovative idea. Today I got a good sense of what a hackathon entails and the kinds of things that people build. So, next time I'll probably know to come with an idea as well as my laptop and sleeping bag.

What's next for Battleship

There are many things that I could have made better with this game. For one thing, there is only a one player mode. (I don't know how to implement networking in Java yet, so I decided against including a 2P mode.) Also, the computer guesses randomly, and it could be better. And yes, there is that issue about how the player's ships aren't checked. But even after fixing all those issues, there'll still be another way to make it better.

Built With

Share this project:

Updates