Changed ints to strings on difficulty setting.

This commit is contained in:
Alexander Huddleston 2015-11-02 17:17:38 -06:00
parent 55df700301
commit e6edce2103
2 changed files with 8 additions and 9 deletions

View file

@ -272,15 +272,14 @@ public class Client {
userInput = stdIn.readLine(); userInput = stdIn.readLine();
output.println(userInput); output.println(userInput);
int diff = 0; String diff = "?";
in.read(b, 0, 256); in.read(b, 0, 256);
temp = String.valueOf(b).trim(); temp = String.valueOf(b).trim();
System.out.print(temp); System.out.print(temp);
while(diff < 1 || diff > 3) { while(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) {
userInput = stdIn.readLine(); diff = stdIn.readLine();
diff = Integer.parseInt(userInput); if(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) {
if(diff < 1 || diff > 3) { System.out.print(diff + "\nInvalid difficulty.\n" + temp);
System.out.print("Invalid difficulty.\n" + temp);
} }
} }
output.println(userInput); output.println(userInput);

View file

@ -122,7 +122,7 @@ int main(int argc, char *argv[])
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 con(info); istringstream con(info);
int choice_difficulty = 1; string choice_difficulty = "EASY";
con >> choice_difficulty; con >> choice_difficulty;
cout << "OK" << endl; cout << "OK" << endl;
bzero(info,256); bzero(info,256);
@ -159,9 +159,9 @@ int main(int argc, char *argv[])
while(e.getBoard()->getTurn() == 'X' ) while(e.getBoard()->getTurn() == 'X' )
{ {
if(choice_difficulty == 1) if(choice_difficulty == "EASY")
e.AI(3); e.AI(3);
else if(choice_difficulty == 2) else if(choice_difficulty == "MEDIUM")
e.AI(5); e.AI(5);
else else
e.AI(7); e.AI(7);