refactor: change some names

This commit is contained in:
2025-05-13 13:30:43 +03:30
parent 1487b6dfac
commit 90fd825bfe
4 changed files with 7 additions and 17 deletions
@@ -7,7 +7,7 @@ import java.net.URL;
import java.util.*; import java.util.*;
import Client.utils.AnsiColor; import Client.utils.AnsiColor;
public class BattleShipClient { public class Client {
private static final String SPACING = " "; private static final String SPACING = " ";
private static final String IP_ADDRESS = "127.0.0.1"; private static final String IP_ADDRESS = "127.0.0.1";
private static final int PORT_NUMBER = 3737; private static final int PORT_NUMBER = 3737;
@@ -27,7 +27,7 @@ public class BattleShipClient {
volatile boolean otherPlayerJoined = false; volatile boolean otherPlayerJoined = false;
DataOutputStream out; DataOutputStream out;
public BattleShipClient(Socket clientSocket) { public Client(Socket clientSocket) {
this.clientSocket = clientSocket; this.clientSocket = clientSocket;
try { try {
@@ -139,7 +139,7 @@ public class BattleShipClient {
private static void playSound(String soundFileName) { private static void playSound(String soundFileName) {
try { try {
// Load the sound file from the resources folder // Load the sound file from the resources folder
URL soundFileURL = BattleShipClient.class.getClassLoader().getResource( soundFileName); URL soundFileURL = Client.class.getClassLoader().getResource( soundFileName);
if (soundFileURL == null) { if (soundFileURL == null) {
System.out.println("Sound file not found: " + soundFileName); System.out.println("Sound file not found: " + soundFileName);
@@ -3,13 +3,12 @@ package Client;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.util.Objects;
public class BattleShipClientNetworkHandler implements Runnable{ public class ClientNetworkReceiver implements Runnable{
private BattleShipClient client; private Client client;
private DataInputStream in; private DataInputStream in;
public BattleShipClientNetworkHandler(Socket clientSocket, BattleShipClient client) throws IOException { public ClientNetworkReceiver(Socket clientSocket, Client client) throws IOException {
// initialize client // initialize client
// initialize in // initialize in
} }
-3
View File
@@ -37,7 +37,6 @@ public class ClientHandler implements Runnable {
while(true) { while(true) {
// TODO: Read a UTF-encoded string from the client // TODO: Read a UTF-encoded string from the client
String request = ""; String request = "";
if (false) { //TODO: Set Username if (false) { //TODO: Set Username
int playerNumber = isFirst?0:1; int playerNumber = isFirst?0:1;
// TODO: Send player number to client // TODO: Send player number to client
@@ -47,10 +46,8 @@ public class ClientHandler implements Runnable {
//TODO: tell the clients that the other player joined //TODO: tell the clients that the other player joined
} }
else if (false) { //TODO: Handle Attack else if (false) { //TODO: Handle Attack
int row = 0;//TODO: extract row and col int row = 0;//TODO: extract row and col
int col = 0;//TODO: extract row and col int col = 0;//TODO: extract row and col
//TODO: inform enemy of the attack //TODO: inform enemy of the attack
} }
else if (false) { //TODO: Handle Hit Result else if (false) { //TODO: Handle Hit Result
@@ -2,12 +2,11 @@ package Server;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class BattleShipServer { public class Server {
private static int PORT = 3737; private static int PORT = 3737;
// TODO: Create a collection to keep track of connected clients // TODO: Create a collection to keep track of connected clients
private static ArrayList<ClientHandler> clients = new ArrayList(); private static ArrayList<ClientHandler> clients = new ArrayList();
@@ -23,13 +22,10 @@ public class BattleShipServer {
try { try {
// TODO: Create a ServerSocket to listen for incoming connections // TODO: Create a ServerSocket to listen for incoming connections
//int i = 0; //int i = 0;
while(true) { while(true) {
// TODO: Accept a client connection // TODO: Accept a client connection
// TODO: Create a ClientHandler for the connected client // TODO: Create a ClientHandler for the connected client
//TODO: uncomment this code //TODO: uncomment this code
//if(i == 0) { //if(i == 0) {
// playerOne = clientThread; // playerOne = clientThread;
@@ -40,9 +36,7 @@ public class BattleShipServer {
// playerTwo.setEnemy(playerOne); // playerTwo.setEnemy(playerOne);
//} //}
//i++; //i++;
//TODO add clientThread to clients and executor service //TODO add clientThread to clients and executor service
} }
} finally { } finally {
if (listener != null) { if (listener != null) {