Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.concurrent.ThreadLocalRandom;
- public class cheat {
- public static void main(String args[]) throws FileNotFoundException{
- final int RAND_MIN=2;
- final int RAND_MAX=14;
- int misses=0;
- int lives=6;
- int randlength= ThreadLocalRandom.current().nextInt(RAND_MIN,RAND_MAX+1);
- System.out.println(randlength);
- ArrayList<String> allWords = new ArrayList<String>();
- Scanner input = new Scanner(new File("word_list.txt"));
- System.out.println("please enter a letter or word to guess");
- Scanner user= new Scanner(System.in);
- String userinput= user.next();
- while (input.hasNext()) {
- String word = input.next();
- allWords.add(word);
- }
- System.out.println(allWords);
- while(misses<lives) {
- for (int i=0;i<allWords.size();i++) {
- String word=allWords.get(i);
- if (word.length()!=randlength) {
- allWords.remove(i);
- i--;
- }
- }
- for (int j=0;j<allWords.size();j++) {
- String word=allWords.get(j);
- if (word.contains(userinput)||word.equals(userinput)||!word.contains(userinput)&&misses<lives&&allWords.size()<1) {
- allWords.remove(j);
- misses++;
- System.out.println("Incorrect, please enter another letter of word");
- userinput=user.next();
- }
- if (allWords.size()==1) {
- System.out.println("word is"+allWords);
- }
- if (allWords.size()==1) {
- System.out.println("the word was"+allWords);
- }
- }
- //System.out.println("BEFORE"+allWords);
- //String remainingwords;
- //for (int j=0;j<allWords.size();j++) {
- //String word=allWords.get(j);
- //remainingwords=word;
- //if (word.contains(userinput)||word.equals(userinput)||!word.contains(userinput)&&misses<lives) {
- //allWords.remove(j);
- //j--;
- //misses++;
- //System.out.println("REMAINING WORDS"+allWords);
- //System.out.println("Letter or word you entered is not in the answer, please enter another letter or word");
- //userinput=user.next();
- //}
- //System.out.println("REMAINING WORDS"+allWords);
- //}
- System.out.println("AFTER"+allWords);
- //for (int j=0;j<allWords.size();j++) {
- //}
- //while (in.hasNext()) {
- //words.add(in.next());
- //if (word.length()!=randlength) {
- //}
- //}
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement