Initial commit, works and randomized

This commit is contained in:
blzimme000 2022-03-07 13:04:13 -06:00
commit c66446a336
9 changed files with 111 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Project exclude paths
/out/

3
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

1
.idea/description.html Normal file
View file

@ -0,0 +1 @@
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>

6
.idea/encodings.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

12
.idea/misc.xml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" default="true" project-jdk-name="16" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Wordle.iml" filepath="$PROJECT_DIR$/Wordle.iml" />
</modules>
</component>
</project>

View file

@ -0,0 +1,3 @@
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>

11
Wordle.iml Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

65
src/com/company/Main.java Normal file
View file

@ -0,0 +1,65 @@
package com.company;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static void main (String str[]) throws IOException {
Scanner scan = new Scanner (System.in);
boolean gameNotOver = true;
ArrayList<String> words = new ArrayList<>();
try {
File wordList = new File("/home/benzimm07/IdeaProjects/Wordle Solver/src/com/company/smallWordleArray.csv");
Scanner reader = new Scanner(wordList);
reader.useDelimiter(",");
while (reader.hasNext()){
words.add(reader.next());
}
} catch (FileNotFoundException e){
System.out.println("The file was not found.");
e.printStackTrace();
}
String answer = words.get((int) (Math.random()*2315));
while (gameNotOver)
{
boolean fiveLetter = true;
String guess = "";
while (fiveLetter){
System.out.println("Guess the five letter word!");
guess = scan.nextLine();
if (guess.length() < 5)
System.out.println("Sorry, your word is not long enough!");
else if (guess.length() > 5)
System.out.println("Sorry, your word is too long!");
else
fiveLetter = false;
}
String guessLower = guess.toLowerCase();
System.out.println("Your guess is: " + guessLower);
String[] characters = {"-", "-", "-", "-", "-"};
boolean match = true;
for (int i = 0; i < 5; i++)
{
if (answer.substring(i, i + 1).equals(guessLower.substring(i, i + 1)))
characters[i] = answer.substring(i, i + 1);
else if (answer.indexOf(guessLower.substring(i, i + 1)) != -1)
{
characters[i] = "(" + guessLower.substring(i, i + 1) + ")";
match = false;
}
else
match = false;
}
if (match == true)
gameNotOver = false;
System.out.println(characters[0] + characters[1] + characters[2] + characters[3] + characters[4]);
}
}
}