I'm trying to design a game of chess using OOP concepts that have an element of user interface. My idea is to show the number of squares / cells in which a room can travel when it is selected. Basically, I want to show the paths / directions in which he can travel / attack in a different color.
Something like the following
(
)
I have therefore designed a summary Piece
class, which, among others, has a Map
object that keeps track of all the cells to which it can move in the sense of direction, something like that
Map>
Now, let's say that a piece of the Queen's own team comes in his way to attack in the FORWARD
direction and gets on the cell that is at chessBoard(6)(4)
What better way can I inform the Queen
or any other piece looking at this particular cell of the event so that each piece can call its own method of updating and redraw its path of attack?
I was thinking of going with the Observer model where each cell will be a subject and only the pieces that will watch them will be observers. So, in any case, something happens in one of the cells monitored by a particular set of pieces, only those pieces will be notified.
But then I do not know if it's a good approach because I have to have a maximum of 32 listeners for each cell. I do not know if it will be scalable.
Are there better ways to do it?
Thank you for taking the time to read.