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