Class GameHandler
java.lang.Object
com.alessiocascini.battleship.server.GameHandler
- All Implemented Interfaces:
Runnable
Manages the gameplay logic for an individual turn. This class handles the communication between
the two players, tracks whose turn it is, and monitors the number of sunken ships to determine
the game outcome. Since multiple instances run in different threads, it uses static fields to
maintain a shared game state.
- Author:
- Alessio Cascini
-
Constructor Summary
ConstructorsConstructorDescriptionGameHandler(Socket clientSocket) Constructs a GameHandler for the connected client. -
Method Summary
-
Constructor Details
-
GameHandler
Constructs a GameHandler for the connected client.- Parameters:
clientSocket- The socket connection to the player
-
-
Method Details
-
run
public void run()Main game loop logic for a single turn request: 1. Verifies if it is the player's turn. 2. Processes the move through the Server logic. 3. Updates the win/loss state if a ship is sunk. 4. Waits and notifies the player of the opponent's subsequent move.
-