Skip to content

Commit af11735

Browse files
committed
incorporated SoundEx to GuessRealGame and some cleanup work
1 parent 21add31 commit af11735

File tree

10 files changed

+170
-70
lines changed

10 files changed

+170
-70
lines changed

.idea/workspace.xml

Lines changed: 138 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
255 Bytes
Binary file not shown.
-171 Bytes
Binary file not shown.

src/Game.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@
66
import java.io.*;
77

88
public class Game {
9+
10+
/*---------------------printAlpha variables----------------------*/
911
private char[] alpha;
12+
13+
/*-------------------randomAlphabet variables----------------------*/
1014
private char randAlpha;
11-
private char[] upperAndLower;
12-
private long elapsedTime;
15+
16+
/*---------------------randWord variables-------------------------*/
1317
private String[] randomStrings;
18+
19+
/*---------------------readFile variables-------------------------*/
1420
private String randomStringWord;
21+
22+
/*--------------------userInput variables------------------------*/
1523
private String strUpper;
1624
private String strLower;
17-
25+
private char[] upperAndLower;
26+
private long elapsedTime;
27+
/*-----------------------------methods--------------------------------*/
1828
public void readyGame(){ // wait for user to press key to start
1929
System.out.println("Press the Enter key to start the game");
2030
try
@@ -63,7 +73,7 @@ public void randomWord(int numberOfWords, char array[])
6373

6474
public void readFile(){
6575
Random random = new Random();
66-
try{ // might not be needed delim
76+
try{
6777
BufferedReader inFile1 = new BufferedReader(new FileReader("Dictionary.txt"));
6878
List<String> temps = new ArrayList<String>();
6979

src/GuessGibberishWord.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void WordGuessGib(int numGames){
2525
System.out.println("TOO SLOW!!! You answered in: " + elapsedTime / 1000 + " seconds\n");
2626
} else if (strLower.equals(randWord[0]) || strUpper.equals(randWord[0])) {
2727
// NOTE: have to use .equals instead of == since == will see if it refers to the same object and not the same value
28+
// double equals basically checks to see if the two Objects are the same reference
2829
System.out.println("CORRECT! You answered in: " + elapsedTime / 1000 + " seconds\n");
2930
} else {
3031
System.out.println("WRONG! The correct choice is: " + randWord[0] + "\n");

src/GuessLetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void letterGame(int numGames)
2121
elapsedTime = phoneticGame.getElapsedTime();
2222
if (elapsedTime >= 3000) { // waits for specified time in ms (1000ms = 1s)
2323
System.out.println("TOO SLOW!!! You answered in: " + elapsedTime / 1000 + " seconds\n");
24-
} else if (upperAndLower[0] == randAlpha || upperAndLower[1] == randAlpha) {
24+
} else if (upperAndLower[0] == randAlpha || upperAndLower[1] == randAlpha) { // this works but to be safe .equals would be better
2525
System.out.println("CORRECT! You answered in: " + elapsedTime / 1000 + " seconds\n");
2626
} else {
2727
System.out.println("WRONG! The correct choice is: " + randAlpha + "\n");

src/GuessRealWord.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ public void WordGuessReal(int numGames){
2525
// NOTE: have to use .equals instead of == since == will see if it refers to the same object and not the same value
2626
System.out.println("CORRECT! You answered in: " + elapsedTime / 1000 + " seconds\n");
2727
} else {
28-
LevenshteinDistance correction = new LevenshteinDistance();
28+
LevenshteinDistance correction = new LevenshteinDistance(); SoundEx correctionImproved = new SoundEx();
29+
2930
correction.LD(strLower, randWord);
30-
if(correction.getFinalCost() <= 1){ // if you are one letter off
31+
correctionImproved.Encode(strLower);
32+
String c1 = correctionImproved.getCode();
33+
34+
correctionImproved.Encode(randWord);
35+
String c2 = correctionImproved.getCode();
36+
37+
if(correction.getFinalCost() <= 1 || c1.equals(c2)){ // if you are one letter off
3138
System.out.println("Did you mean: " + randWord + "\n");
3239
}else{
3340
System.out.println("WRONG! \n");

src/Main.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ public static void main(String[] args) {
88
// GuessGibberishWord game2 = new GuessGibberishWord();
99
// game2.WordGuessGib(5);
1010
/*------------------------------runs real word guessing game----------------------------------*/
11-
// GuessRealWord game3 = new GuessRealWord();
12-
// game3.WordGuessReal(2);
13-
SoundEx test = new SoundEx();
14-
test.Encode("Lee");
15-
System.out.println(test.getCode());
16-
17-
18-
11+
GuessRealWord game3 = new GuessRealWord();
12+
game3.WordGuessReal(2);
13+
/*------------------------------tests SoundEx Encoding----------------------------------*/
14+
// SoundEx test = new SoundEx();
15+
// test.Encode("Lee");
16+
// System.out.println(test.getCode());
17+
1918
} // end main
2019

2120
} // end main class

0 commit comments

Comments
 (0)