worked on riddle class
This commit is contained in:
@@ -16,7 +16,8 @@ import java.util.Scanner;
|
||||
*/
|
||||
class CommandWords {
|
||||
// a constant array that holds all valid command words
|
||||
private static HashMap<String, String> m_words = new HashMap<String, String>();;
|
||||
private static HashMap<String, String> m_words = new HashMap<String, String>();
|
||||
private static HashMap<String, String> m_synonyms = new HashMap<String, String>();
|
||||
/**
|
||||
* Constructor - initialise the command words.
|
||||
*/
|
||||
@@ -33,6 +34,18 @@ class CommandWords {
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Scanner in = new Scanner(new File("data/synonyms.dat"));
|
||||
while(in.hasNext()){
|
||||
String text = in.nextLine();
|
||||
String[] textarr = text.split(",");
|
||||
m_synonyms.put(textarr[0], textarr[1].substring(1));
|
||||
}
|
||||
in.close();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,6 +84,14 @@ class CommandWords {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRiddler(String aString) {
|
||||
try {
|
||||
return m_words.get(aString).equals("riddler");
|
||||
}catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Print all valid commands to System.out.
|
||||
*/
|
||||
@@ -82,4 +103,18 @@ class CommandWords {
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public static String replaceSynonym(String word) {
|
||||
try {
|
||||
String words = m_synonyms.get(word);
|
||||
if(words == null)
|
||||
throw new Exception();
|
||||
else
|
||||
return words;
|
||||
} catch(Exception e) {
|
||||
return word;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user