Description
For this extra credit, change the BattleshipGrid
class to use enumerated types.
See Enums
and Enum Types.
I am expecting that the named constants for direction, ship type/length, and the values used
in the grid (EMPTY, SHIP, HIT, MISS) be turned into enums. This will require some changes
throughout the code. If you'd like to only change one or two of these things over to enums,
partial extra credit is also possible, but you have to demonstrate an understanding of how
they work.
If you change the constants for DIRECTION_RIGHT and DIRECTION_DOWN over to an enum,
you will have to figure out how to generate a random enum value. Here's how you can start
thinking about it (this won't make much sense yet unless you've read the links about Enums).
Enumerated types in Java have a special static method, values()
, that returns
an array of all the values in an enum. Imagine you had the following enum:
enum Season { WINTER, SPRING, SUMMER, FALL }
You could have code such as:
Season[] seasons = Season.values();
Can you think of how to get a random season out of that array?