Fixed client-side issues with de-syncing, can now choose game type for server to handle

This commit is contained in:
Brandon Jackson 2015-10-20 14:28:56 -05:00
parent e72e408cdc
commit 7a776cd030

View file

@ -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);