Reputation: 373
The project was a co-op game, which used client-server architecture to communicate over the network.
Most of the logic was conducted in the Player class, Game class and the Board class.
The game and board handling where everything on the board was, and holding meta data about the current game.
My logic to check if the player was able to move or not was in the players class, ie. The player knows if it can move in a certain direction or not, this required player to hold the board as a field.
My Question being, Is this an ok design?, If not why not and where would a better place to have the logic be?
Thank you for your answers!
Sorry my last question was a bit broad and opinion orientated, hopefully this one is less so, please tell me if this one is poorly written as well
Upvotes: 0
Views: 57
Reputation:
A player is likely tied to a specific board or playing area. You could design it either way: the player knows the board and can query it to see if a move is permissible, or you could query the board if one of its pieces can move.
I think going through the player makes more sense: it knows its own limitations. For example, in chess, the playing piece knows what type it is and if it can move one space, multiple, diagonally, etc. so from that perspective your design works fine.
You would also not ask a player if it can move on board B when it is located on board A.
You could always look at open source games to see how others have done this: OGRE is an open source engine with links to several implementations (including some well-known games).
Upvotes: 1