Added support for easy deployment to offsite server
This commit is contained in:
@@ -34,16 +34,16 @@ public class TicTacToe_Server {
|
||||
board = this.convertToNumbers(gameState);
|
||||
}
|
||||
|
||||
public int makeClientMove(String input) {
|
||||
public boolean makeClientMove(String input) {
|
||||
int column = Double.valueOf(input.split("\\|")[0]).intValue() / 300;
|
||||
int row = Double.valueOf(input.split("\\|")[1]).intValue() / 300;
|
||||
int index = column * 3 + row;
|
||||
|
||||
if (isLegalMove(column, row)) {
|
||||
makeMoveOnBoard(index, 0);
|
||||
return 200;
|
||||
return true;
|
||||
} else {
|
||||
return 404;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,22 +81,22 @@ public class MultiPlayerServer {
|
||||
}
|
||||
|
||||
public void ticTacToe_gameloop() {
|
||||
for (Socket client : clients.values()) {
|
||||
try {
|
||||
while (!client.isClosed()) {
|
||||
String message = instreams.get(client).readUTF();
|
||||
serverLogger.printLog(message, clientNames.get(client), LogType.Message);
|
||||
outstreams.get(client).writeInt(200);
|
||||
outstreams.get(client).flush();
|
||||
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
||||
this.gameFlow(message, client);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
while(clients.size() == 2) {
|
||||
for (Socket client : clients.values()) {
|
||||
try {
|
||||
client.close();
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
String message = instreams.get(client).readUTF();
|
||||
serverLogger.printLog(message, clientNames.get(client), LogType.Message);
|
||||
outstreams.get(client).writeInt(200);
|
||||
outstreams.get(client).flush();
|
||||
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
||||
this.gameFlow(message, client);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
client.close();
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,8 +121,8 @@ public class MultiPlayerServer {
|
||||
outstreams.get(client).writeInt(200);
|
||||
outstreams.get(client).flush();
|
||||
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
||||
int verificationCode = ticTacToe_server.makeClientMove(position);
|
||||
if (verificationCode == 200) {
|
||||
boolean isAllowed = ticTacToe_server.makeClientMove(position);
|
||||
if (isAllowed) {
|
||||
String gameState = ticTacToe_server.getGameState();
|
||||
outstreams.get(client).writeUTF(gameState);
|
||||
outstreams.get(client).flush();
|
||||
|
||||
@@ -121,8 +121,8 @@ public class SinglePlayerServer {
|
||||
outstreams.get(client).writeInt(200);
|
||||
outstreams.get(client).flush();
|
||||
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
||||
int verificationCode = ticTacToe_server.makeClientMove(position);
|
||||
if (verificationCode == 200) {
|
||||
boolean moveAllowed = ticTacToe_server.makeClientMove(position);
|
||||
if (moveAllowed) {
|
||||
String gameState = ticTacToe_server.getGameState();
|
||||
outstreams.get(client).writeUTF(gameState);
|
||||
outstreams.get(client).flush();
|
||||
|
||||
Reference in New Issue
Block a user