Fixed some issues with de-syncing, client now chooses game type
This commit is contained in:
parent
16097a4303
commit
e72e408cdc
1 changed files with 36 additions and 17 deletions
35
Server.cpp
35
Server.cpp
|
@ -3,6 +3,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/types.h>
|
#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
|
//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<<"1. Play against AI?\n";
|
||||||
cout<<"2. Play against a human?\n";
|
// cout<<"2. Play against a human?\n";
|
||||||
cout<<"Enter choice: \n";
|
// cout<<"Enter choice: \n";
|
||||||
|
|
||||||
int choice;
|
|
||||||
cin >> choice;
|
// cin >> choice;
|
||||||
cout << "OK" << endl;
|
// cout << "OK" << endl;
|
||||||
|
|
||||||
Board b;
|
Board b;
|
||||||
string move;
|
string move;
|
||||||
|
@ -83,6 +84,13 @@ int main(int argc, char *argv[])
|
||||||
b.snapshot(record,b);
|
b.snapshot(record,b);
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
char info[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) {
|
while(true) {
|
||||||
|
|
||||||
|
@ -99,7 +107,6 @@ int main(int argc, char *argv[])
|
||||||
n = read(newsockfd,buffer,255);
|
n = read(newsockfd,buffer,255);
|
||||||
move = buffer;
|
move = buffer;
|
||||||
b.interpret(move,b);
|
b.interpret(move,b);
|
||||||
}
|
|
||||||
|
|
||||||
gameOver = b.isGameOver();
|
gameOver = b.isGameOver();
|
||||||
if(gameOver == true) {
|
if(gameOver == true) {
|
||||||
|
@ -111,6 +118,18 @@ int main(int argc, char *argv[])
|
||||||
string continueGame = "Continue_Game";
|
string continueGame = "Continue_Game";
|
||||||
write(newsockfd, continueGame.c_str(), continueGame.length()); //Display the board to the client (line by line)
|
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();
|
vector<moves> possibleMoves = b.viewPossibleMoves();
|
||||||
if(choice == 1)
|
if(choice == 1)
|
||||||
|
|
Reference in a new issue