From e6edce2103e8f239361dbcfbe0ee4e5091cadd65 Mon Sep 17 00:00:00 2001 From: Alexander Huddleston Date: Mon, 2 Nov 2015 17:17:38 -0600 Subject: [PATCH] Changed ints to strings on difficulty setting. --- Client.java | 11 +++++------ Server.cpp | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Client.java b/Client.java index a22160c..3f76014 100755 --- a/Client.java +++ b/Client.java @@ -272,15 +272,14 @@ public class Client { userInput = stdIn.readLine(); output.println(userInput); - int diff = 0; + String diff = "?"; 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); + while(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) { + diff = stdIn.readLine(); + if(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) { + System.out.print(diff + "\nInvalid difficulty.\n" + temp); } } output.println(userInput); diff --git a/Server.cpp b/Server.cpp index bf84d43..b0c01f2 100644 --- a/Server.cpp +++ b/Server.cpp @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) write(newsockfd, difficulty_select.c_str(), difficulty_select.length()); n = read(newsockfd,info,255); istringstream con(info); - int choice_difficulty = 1; + string choice_difficulty = "EASY"; con >> choice_difficulty; cout << "OK" << endl; bzero(info,256); @@ -159,9 +159,9 @@ int main(int argc, char *argv[]) while(e.getBoard()->getTurn() == 'X' ) { - if(choice_difficulty == 1) + if(choice_difficulty == "EASY") e.AI(3); - else if(choice_difficulty == 2) + else if(choice_difficulty == "MEDIUM") e.AI(5); else e.AI(7);