I am trying to make a 2-player game; where one player plays after the next. I have used socket programming in the code; so that, when the client (player 1) clicks on the window, the co-ordinates are sent to the server (player 2) and vice-versa. (For now, both player screen are displayed on the same host.)
So, here's the issue: Suppose I click somewhere on the client's screen - lets call it click 1. The co-ordinates of click 1 are correctly sent to the server. Now suppose I click again on the client's screen (call it click 2) - ideally nothing should happen since it's not player 1's turn - and for now, it doesn't. So far, so good. Now, suppose I click on the server's screen (call it click 3) - click 3's co-ordinates are sent to the client correctly. However, now, without clicking anywhere at all, the client sends click 2's co-ordinates to the server!! I don't want the last part to happen - i.e. when it's not someone's turn to play, all the mouse clicks on that screen should be ignored.
I can't figure this out!! I am using removeMouseListener right after a click is done (provided its the right person's turn), and I am not calling the addMouseListener until after co-ordinates are received. So, why is this happening?!! I am not very good at jav coding, so even if it is a very dumb error, please be patient and let me know!! I've already spent hours trying to debug this, to no avail!!