Skip to content

odCat/Battleships

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battleships

This is a CLI battleships game written in Java.

How to play

The computer will pick random positions for three battleships on a grid
of 7x7 square. Each battleship will occupy three adjacent squares set
up in a line.

You will be asked for coordinates for the artillery barrage until all the
enemy battleships are destroyed and sunk. To sink a battleship hit it three
times in each square it occupies on the grid.

Good luck!

Why

As I was starting again with Java after a few years I picked up a very
old edition of Head First Java. The book was written after the Dot-com
bubble, that is probably why one of the first projects is a game that
sinks Dot-coms...

I took this project on, but created a classic battleship sinking game
with my own implementation and testing.

What was learned and practiced

  • How to incorporate Maven into the project and use it to compile,
    build and test

    A problem I encountered with Maven was that it was not building the
    project correctly and it was not running my tests. After investigations,
    I found the problem. On Debian, the default Maven package was version
    3.6.3, and this version was not working well with set up I made.
    To solve this issue I installed manually the latest version (3.9.9)

  • How to use JUnit;

    After setting up Maven I could use JUnit and run automated tests with it.
    So, I transferred my old custom tests to JUnit 5

  • How to use TDD

  • How to use the Math.random() method to generate random numbers

  • How to override the equals method (of the Field class) to make the contains
    work in the context of the project

  • How to use delegation to check hits (BattleshpsGame -> Fleet -> Battleship)

About

A CLI implementation of the battleships game

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages