Fixing issues.
This commit is contained in:
parent
5cfb44a1dd
commit
f5ba309a6e
2 changed files with 70 additions and 93 deletions
33
Client.java
33
Client.java
|
@ -308,8 +308,7 @@ public class Client {
|
|||
frame.pack();
|
||||
frame.setMinimumSize(frame.getSize());
|
||||
frame.setVisible(true);
|
||||
//userInput = stdIn.readLine();
|
||||
<<<<<<< HEAD
|
||||
//userInput = stdIn.readLine();
|
||||
int gameMode = 0;
|
||||
userInput = JOptionPane.showInputDialog(frame, temp);
|
||||
gameMode = Integer.parseInt(userInput);
|
||||
|
@ -317,22 +316,12 @@ public class Client {
|
|||
userInput = JOptionPane.showInputDialog(frame, temp);
|
||||
output.println(userInput);
|
||||
}
|
||||
gameMode = Integer.parseInt(userInput);
|
||||
=======
|
||||
userInput = JOptionPane.showInputDialog(frame, temp);
|
||||
//while(!userInput.contains("1") || !userInput.contains("2")) {
|
||||
// userInput = JOptionPane.showInputDialog(frame, temp);
|
||||
//}
|
||||
>>>>>>> b517b06bc614e18b2c6252c12fcfdc1eb71fd38f
|
||||
gameMode = Integer.parseInt(userInput);
|
||||
output.println(userInput);
|
||||
|
||||
String diff = "?";
|
||||
in.read(b, 0, 256);
|
||||
temp = String.valueOf(b).trim();
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
//System.out.print(temp);
|
||||
>>>>>>> b517b06bc614e18b2c6252c12fcfdc1eb71fd38f
|
||||
temp = String.valueOf(b).trim();
|
||||
while(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) {
|
||||
diff = JOptionPane.showInputDialog(frame, temp);//diff = stdIn.readLine();
|
||||
diff = diff.toUpperCase();
|
||||
|
@ -341,8 +330,7 @@ public class Client {
|
|||
}
|
||||
}
|
||||
output.println(userInput);
|
||||
String out = "";
|
||||
<<<<<<< HEAD
|
||||
String out = "";
|
||||
if(gameMode == 1)
|
||||
{
|
||||
while(!end) {
|
||||
|
@ -372,18 +360,7 @@ public class Client {
|
|||
boardoutput = "";
|
||||
System.out.println("Invalid move.");
|
||||
}
|
||||
}
|
||||
=======
|
||||
|
||||
while(!end) {
|
||||
char[] buffer = new char[256];
|
||||
in.read(buffer, 0, 256);
|
||||
for(int i = 0; i < buffer.length; ++i) {
|
||||
if(Arrays.equals(Arrays.copyOfRange(buffer, i, i+9), go)) {
|
||||
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
|
||||
JOptionPane.showMessageDialog(null, "\nGAME OVER\n");
|
||||
end = true;
|
||||
>>>>>>> b517b06bc614e18b2c6252c12fcfdc1eb71fd38f
|
||||
}
|
||||
}
|
||||
System.out.println(out);
|
||||
output.println(out);
|
||||
|
|
130
Server.cpp
130
Server.cpp
|
@ -95,79 +95,79 @@ int main(int argc, char *argv[])
|
|||
bzero(info,256);
|
||||
|
||||
while(true) {
|
||||
|
||||
if(choice == 1)
|
||||
|
||||
if(choice == 1)
|
||||
{
|
||||
while(gameOver != true)
|
||||
{
|
||||
while(gameOver != true)
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
|
||||
while(e.getBoard()->getTurn() == 'O' && !e.getBoard()->isValid())
|
||||
{
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
e.getBoard()->displayBoard();//Display the board on the server
|
||||
string boardState = e.getBoard()->boardToString();
|
||||
final_move = e.getBoard()->boardToString();
|
||||
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
cout<<"\nWaiting for client: ";
|
||||
n = read(newsockfd,buffer,255);
|
||||
move = buffer;
|
||||
bzero(buffer,256);
|
||||
//cout << move << "\n\n";
|
||||
//move = tempParse(move);
|
||||
parse(move,(*e.getBoard()));
|
||||
|
||||
while(e.getBoard()->getTurn() == 'O' && !e.getBoard()->isValid())
|
||||
{
|
||||
e.getBoard()->displayBoard();//Display the board on the server
|
||||
string boardState = e.getBoard()->boardToString();
|
||||
final_move = e.getBoard()->boardToString();
|
||||
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
cout<<"\nWaiting for client: ";
|
||||
n = read(newsockfd,buffer,255);
|
||||
move = buffer;
|
||||
bzero(buffer,256);
|
||||
//cout << move << "\n\n";
|
||||
//move = tempParse(move);
|
||||
parse(move,(*e.getBoard()));
|
||||
|
||||
if(e.getBoard()->isValid()) {
|
||||
e.getBoard()->changeTurns();
|
||||
e.getBoard()->setValidFalse();
|
||||
}
|
||||
if(e.getBoard()->isValid()) {
|
||||
e.getBoard()->changeTurns();
|
||||
e.getBoard()->setValidFalse();
|
||||
}
|
||||
|
||||
if(e.getBoard()->isValid())
|
||||
cout << e.getBoard()->getTurn();
|
||||
|
||||
while(e.getBoard()->getTurn() == 'X' )
|
||||
{
|
||||
if(choice_difficulty == "EASY")
|
||||
e.AI(3);
|
||||
else if(choice_difficulty == "MEDIUM")
|
||||
e.AI(5);
|
||||
else
|
||||
e.AI(7);
|
||||
}
|
||||
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
e.getBoard()->setValidFalse();
|
||||
e.getBoard()->snapshot(record, *e.getBoard());
|
||||
}
|
||||
}
|
||||
|
||||
if(choice == 2)
|
||||
{
|
||||
while (gameOver != true) {
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
|
||||
while(e.getBoard()->getTurn() == 'O') {
|
||||
e.getBoard()->displayBoard();//Display the board on the server
|
||||
string boardState = e.getBoard()->boardToString();
|
||||
final_move = e.getBoard()->boardToString();
|
||||
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
|
||||
if(e.getBoard()->isValid())
|
||||
cout << e.getBoard()->getTurn();
|
||||
|
||||
while(e.getBoard()->getTurn() == 'X' )
|
||||
{
|
||||
if(choice_difficulty == "EASY")
|
||||
e.AI(3);
|
||||
else if(choice_difficulty == "MEDIUM")
|
||||
e.AI(5);
|
||||
else
|
||||
e.AI(7);
|
||||
}
|
||||
|
||||
e.getBoard()->displayBoard();
|
||||
sleep(1);
|
||||
|
||||
while(e.getBoard()->getTurn() == 'X' ) {
|
||||
e.getBoard()->displayBoard();//Display the board on the server
|
||||
string boardState = e.getBoard()->boardToString();
|
||||
final_move = e.getBoard()->boardToString();
|
||||
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
e.AI(7);
|
||||
}
|
||||
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
}
|
||||
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
e.getBoard()->setValidFalse();
|
||||
e.getBoard()->snapshot(record, *e.getBoard());
|
||||
}
|
||||
}
|
||||
|
||||
if(choice == 2)
|
||||
{
|
||||
while (gameOver != true) {
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
|
||||
while(e.getBoard()->getTurn() == 'O') {
|
||||
e.getBoard()->displayBoard();//Display the board on the server
|
||||
string boardState = e.getBoard()->boardToString();
|
||||
final_move = e.getBoard()->boardToString();
|
||||
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
e.AI(7);
|
||||
}
|
||||
|
||||
e.getBoard()->displayBoard();
|
||||
sleep(1);
|
||||
|
||||
while(e.getBoard()->getTurn() == 'X' ) {
|
||||
e.getBoard()->displayBoard();//Display the board on the server
|
||||
string boardState = e.getBoard()->boardToString();
|
||||
final_move = e.getBoard()->boardToString();
|
||||
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
e.AI(7);
|
||||
}
|
||||
|
||||
gameOver = e.getBoard()->isGameOver();
|
||||
}
|
||||
}
|
||||
|
||||
final_move = e.getBoard()->boardToString();
|
||||
string game_over = "\n\nGAME OVER!!!\n";
|
||||
|
|
Reference in a new issue