Error checking for difficulty selection.
This commit is contained in:
parent
f809b8c015
commit
ffeebacf82
2 changed files with 20 additions and 13 deletions
13
Client.java
13
Client.java
|
@ -272,6 +272,19 @@ public class Client {
|
||||||
userInput = stdIn.readLine();
|
userInput = stdIn.readLine();
|
||||||
output.println(userInput);
|
output.println(userInput);
|
||||||
|
|
||||||
|
int diff = 0;
|
||||||
|
in.read(b, 0, 256);
|
||||||
|
temp = String.valueOf(b).trim();
|
||||||
|
System.out.print(temp);
|
||||||
|
while(diff < 1 || diff > 3) {
|
||||||
|
userInput = stdIn.readLine();
|
||||||
|
diff = Integer.parseInt(userInput);
|
||||||
|
if(diff < 1 || diff > 3) {
|
||||||
|
System.out.print("Invalid difficulty.\n" + temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.println(userInput);
|
||||||
|
|
||||||
while(!end) {
|
while(!end) {
|
||||||
char[] buffer = new char[256];
|
char[] buffer = new char[256];
|
||||||
in.read(buffer, 0, 256);
|
in.read(buffer, 0, 256);
|
||||||
|
|
20
Server.cpp
20
Server.cpp
|
@ -118,18 +118,15 @@ int main(int argc, char *argv[])
|
||||||
cout << "OK" << endl;
|
cout << "OK" << endl;
|
||||||
bzero(info,256); //Resets info back to normal
|
bzero(info,256); //Resets info back to normal
|
||||||
|
|
||||||
/*//Becca- once your AI code is working, use this code:
|
string difficulty_select = "Choose Difficulty\n1. Easy\n2. Medium\n3. Hard\nEnter choice: \n";
|
||||||
|
|
||||||
string difficulty_select = "Choose Difficulty\n1. Easy\n2. Medium\n4. Hard\nEnter choice: \n";
|
|
||||||
write(newsockfd, difficulty_select.c_str(), difficulty_select.length());
|
write(newsockfd, difficulty_select.c_str(), difficulty_select.length());
|
||||||
n = read(newsockfd,info,255);
|
n = read(newsockfd,info,255);
|
||||||
istringstream convert(info);
|
istringstream con(info);
|
||||||
convert >> choice_difficulty;
|
int choice_difficulty = 1;
|
||||||
|
con >> choice_difficulty;
|
||||||
cout << "OK" << endl;
|
cout << "OK" << endl;
|
||||||
bzero(info,256);
|
bzero(info,256);
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
while(gameOver != true)
|
while(gameOver != true)
|
||||||
|
@ -162,15 +159,12 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while(e.getBoard()->getTurn() == 'X' )
|
while(e.getBoard()->getTurn() == 'X' )
|
||||||
{
|
{
|
||||||
e.easyAI();
|
|
||||||
/*Becca- once you finish your AI, uncomment this out and remove the line directly above this
|
|
||||||
if(choice_difficulty == 1)
|
if(choice_difficulty == 1)
|
||||||
easyAI();
|
e.AI(3);
|
||||||
else if(choice_difficulty == 2)
|
else if(choice_difficulty == 2)
|
||||||
mediumAI();
|
e.AI(5);
|
||||||
else
|
else
|
||||||
hardAI();
|
e.AI(7);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gameOver = e.getBoard()->isGameOver();
|
gameOver = e.getBoard()->isGameOver();
|
||||||
|
|
Reference in a new issue