From e72e408cdca80a53dcd77154ff779a0f765dfeb7 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 20 Oct 2015 14:28:05 -0500 Subject: [PATCH] Fixed some issues with de-syncing, client now chooses game type --- Server.cpp | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/Server.cpp b/Server.cpp index 3f57f01..3630ebc 100644 --- a/Server.cpp +++ b/Server.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -64,15 +65,15 @@ int main(int argc, char *argv[]) //After all the server setup crap is done, we start the board - cout<<"WELCOME\n"; + // cout<<"WELCOME\n"; - cout<<"1. Play against AI?\n"; - cout<<"2. Play against a human?\n"; - cout<<"Enter choice: \n"; + // cout<<"1. Play against AI?\n"; + // cout<<"2. Play against a human?\n"; + // cout<<"Enter choice: \n"; - int choice; - cin >> choice; - cout << "OK" << endl; + + // cin >> choice; + // cout << "OK" << endl; Board b; string move; @@ -83,6 +84,13 @@ int main(int argc, char *argv[]) b.snapshot(record,b); char buffer[256]; char info[256]; + int choice; + + //Waiting for client to select game type + n = read(newsockfd,info,255); + istringstream convert(info); + convert >> choice; //Sets choice equal to 1 or 2, based on clients input + bzero(info,256); //Resets info back to normal, "choice" now contains client's value while(true) { @@ -99,18 +107,29 @@ int main(int argc, char *argv[]) n = read(newsockfd,buffer,255); move = buffer; b.interpret(move,b); + + gameOver = b.isGameOver(); + if(gameOver == true) { + string endGame = "Game_Over"; + write(newsockfd, endGame.c_str(), endGame.length()); //Display the board to the client (line by line) + break; + } + else { + string continueGame = "Continue_Game"; + write(newsockfd, continueGame.c_str(), continueGame.length()); //Display the board to the client (line by line) + } } - gameOver = b.isGameOver(); - if(gameOver == true) { - string endGame = "Game_Over"; - write(newsockfd, endGame.c_str(), endGame.length()); //Display the board to the client (line by line) - break; - } - else { - string continueGame = "Continue_Game"; - write(newsockfd, continueGame.c_str(), continueGame.length()); //Display the board to the client (line by line) - } + //gameOver = b.isGameOver(); + // if(gameOver == true) { + // string endGame = "Game_Over"; + // write(newsockfd, endGame.c_str(), endGame.length()); //Display the board to the client (line by line) + // break; + // } + // else { + // string continueGame = "Continue_Game"; + // write(newsockfd, continueGame.c_str(), continueGame.length()); //Display the board to the client (line by line) + // } vector possibleMoves = b.viewPossibleMoves(); if(choice == 1)