Fixed some issues with de-syncing, client now chooses game type

This commit is contained in:
Brandon Jackson 2015-10-20 14:28:05 -05:00
parent 16097a4303
commit e72e408cdc

View file

@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <unistd.h>
#include <iostream>
#include <sys/types.h>
@ -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,7 +107,6 @@ int main(int argc, char *argv[])
n = read(newsockfd,buffer,255);
move = buffer;
b.interpret(move,b);
}
gameOver = b.isGameOver();
if(gameOver == true) {
@ -111,6 +118,18 @@ int main(int argc, char *argv[])
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<moves> possibleMoves = b.viewPossibleMoves();
if(choice == 1)