Starlight-30036225 / ChessTCP

FILLMELATER
0 stars 0 forks source link

Could mouse listener be moved to display class #28

Closed Starlight-30036225 closed 7 months ago

Starlight-30036225 commented 7 months ago

It seems out of place to have the mouse listener inside the game master as opposed to the board display. Moving it would encapsulate all Swing responsibilities inside one class.

I would need to make a reference to the master inside the board class, but would reduce complexity quite a bit.

Starlight-30036225 commented 7 months ago

Yes it could.

By adding a global reference to the player master class, the mouse listener now calls back to the master class on events.

` public void requestPossibleMoves(String Location) { if (!requestNewPossibles) {return;} client.sendMessage(PacketHeader.SELECT_PIECE, Location);

}

public void requestMove(String PieceLocation, String MoveLocation){

    client.sendMessage(PacketHeader.MOVE, PieceLocation + MoveLocation);   //Sends selected piece and move in 1 string
    requestNewPossibles = true;
}

`

These two new functions inside the player master class are called by the mouse listener events.

This tidies the code up, by removing a lot of references to the board and tightens encapsulation