EDIT: I forgot this was C# - please translate whatever I wrote to appropriate C#.
The general approach/idea should still be viable in C# though.
Another approach, although it requires more imagination perhaps.
Instead of representing the board as a two-dimensional array or table or whatever, you can just note the maximum coordinates and assume the minimum would be (0,0). Then your ship will just keep track of which points that it occupies. Orienting the ship vertically or horizontally is a matter of randomly choosing a starting point and iterating upwards in whatever direction it's going. The math isn't that complicated to work out.
Then, you can query each ship if it was hit or not at a specific point.
You'd have to add more methods to that class of course, to manage and query any hits it has taken or check if it's still alive or sunk.
The way I like to think of this is "If the ship had some intelligence in it, what kind of things could I ask it to do, and what kind of questions could ask of it?"
The answer might be along the lines of:
- I should be able to tell a ship to orient itself randomly (horizontal, vertical, or diagonal) starting from a given point that would put it within the bounds of a grid that has a maximum coordinate of (MAX_X, MAX_Y).
- I should be able to check if the ship is hit at a particular coordinate
- I should be able to check if the ship is still afloat or sunk
Then I choose a method that would most appropriately represent that kind of interaction. For example, to check if a ship is hit at a particular coordinate, I might decide to have this interaction with it:
Deciding on how I interact with an object like Ship is called "designing the object's API" or Application Programming Interface. A well-designed API makes the code easier to understand and easier to work with and fits will with an intuitive mental model of the problem and solution.