This repository contains a Battleship game implemented in Java with a client-server architecture. The game allows two players to engage in an exciting naval battle through the Windows terminal.
The project is divided into two main parts: the client and the server. Here is a brief description of each of the key classes:
The Client
class is responsible for running the game for each of the two players involved in the match. When executed, it creates a socket that connects to the server through port 8888 and initializes a ClientThread
. The ClientThread
is responsible for displaying messages and the game's state in the player's terminal.
The Server
class manages the server and accepts connection requests from clients. It initiates the ServerThread
, which displays relevant information about the server's state and clients. Additionally, it receives keyboard input to start the GameThread
once it receives the word "start." The GameThread
houses and manages all the game logic at the thread management level, allowing each player to initially position their fleet and managing turns to ensure the game's proper operation.
All game logic is located in the Game
class, which is initialized by the Server
class. Some of the key actions performed by this class include:
- Assigning the initial position of ships, ensuring it is valid and collision-free.
- Launching and receiving attacks, calculating the state of the ships.
- Managing the winner of the match.
- Clone this repository to your local machine.
- Run the server using
java -jar Server.jar
. - Next, run two instances of the client, each using
java -jar Client.jar
. - Follow the instructions in the terminal to play the match. I tried to make it the easiest and friendliest way possible for the player to understand.
Contributions are welcome! If you want to enhance this project, feel free to fork it and submit pull requests.
This project is under the GNU General Public License v3.0. Check the LICENSE file for more details.
[Adrián Cervera]
- Java Socket Documentation - Information about Java's Socket class.
- Git Tutorial - Learn more about Git and GitHub.