Fixed client-side issues with de-syncing, can now choose game type for server to handle
This commit is contained in:
parent
e72e408cdc
commit
7a776cd030
1 changed files with 23 additions and 4 deletions
27
Client.cpp
27
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);
|
||||
|
|
Reference in a new issue