OOP Modeling Question
This is a question for you OO/design pattern gurus.
I'm writing a Battleship game that two players can play over a TCP/IP network. Using the model-view-controller design pattern, my model is obviously the game board with the ships on it. So I have a GameBoard class, and an abstract class for Ship with concrete classes AircraftCarrier, Battleship, Submarine, Cruiser, and Destroyer all inheriting from Ship. The GameBoard aggregates the Ships. When the player attacks a position on the game board, someone must keep track of whether the result is a hit or a miss.
Should the each Ship or the GameBoard (or both, or neither) be responsible for keeping track of the hits and misses? I go back and forth. It makes sense for the GameBoard to keep track of the misses, since that info is unrelated to a Ship. That sort of implies that the Model would also keep track of the hits. However, a Ship should be able to tell you if it is sunken which implies that the Ship should keep track of its hits. But, if the Ship keeps track of its hits then the Ship must somehow correlate an <x,y> position on the GameBoard with the points on the Ship, which doesn't seem like a good separation of responsibilities.
Any suggestions on a good way to set this up? Any design patterns out there to help solve this problem?
|