From 7a776cd0305ab34d17e0f97e2ab5be37a49f10dd Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 20 Oct 2015 14:28:56 -0500 Subject: [PATCH] Fixed client-side issues with de-syncing, can now choose game type for server to handle --- Client.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Client.cpp b/Client.cpp index a4901c4..73bb121 100644 --- a/Client.cpp +++ b/Client.cpp @@ -45,9 +45,27 @@ int main(int argc, char *argv[]) if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); + //Client has successfully joined char buffer[256]; char info[256]; + cout<<"WELCOME\n"; + + cout<<"1. Play against AI?\n"; + cout<<"2. Play against a human?\n"; + cout<<"Enter choice: \n"; + + string choice; + cin >> choice; + + //Check for a valid option + cout << "OK!\n" << endl; + + //Writes off the choice to the server + + n = write(sockfd, choice.c_str(), choice.length()); //Sends an input to the server + + while(true) { bzero(buffer,256); //resets the input stream @@ -57,16 +75,17 @@ int main(int argc, char *argv[]) printf("Please enter a move: "); bzero(buffer,256); //resets input stream fgets(buffer,255,stdin); //Enter a move - n = write(sockfd,buffer,strlen(buffer)); //Sends an input to the server - + n = write(sockfd,buffer,strlen(buffer)); //Sends an inputted move to the server bzero(info,256); //resets input stream - n = read(sockfd,info,255); + + n = read(sockfd,info,255); //Reads from server if move was valid string ref = info; if(ref == "Game_Over") { cout << "GAME OVER!!!" << endl; break; } - else if() + else + continue; } close(sockfd);