Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.util.concurrent.ThreadLocalRandom;
  4.  
  5. public class cheat {
  6.  
  7. public static void main(String args[]) throws FileNotFoundException{
  8.  
  9.  
  10. final int RAND_MIN=2;
  11. final int RAND_MAX=14;
  12. int misses=0;
  13. int lives=6;
  14. int randlength= ThreadLocalRandom.current().nextInt(RAND_MIN,RAND_MAX+1);
  15. System.out.println(randlength);
  16.  
  17.  
  18.  
  19. ArrayList<String> allWords = new ArrayList<String>();
  20. Scanner input = new Scanner(new File("word_list.txt"));
  21.  
  22.  
  23. System.out.println("please enter a letter or word to guess");
  24. Scanner user= new Scanner(System.in);
  25. String userinput= user.next();
  26.  
  27.  
  28.  
  29.  
  30.  
  31. while (input.hasNext()) {
  32. String word = input.next();
  33. allWords.add(word);
  34. }
  35. System.out.println(allWords);
  36.  
  37.  
  38. while(misses<lives) {
  39.  
  40.  
  41. for (int i=0;i<allWords.size();i++) {
  42. String word=allWords.get(i);
  43. if (word.length()!=randlength) {
  44. allWords.remove(i);
  45. i--;
  46. }
  47. }
  48. for (int j=0;j<allWords.size();j++) {
  49. String word=allWords.get(j);
  50.  
  51. if (word.contains(userinput)||word.equals(userinput)||!word.contains(userinput)&&misses<lives&&allWords.size()<1) {
  52. allWords.remove(j);
  53. misses++;
  54. System.out.println("Incorrect, please enter another letter of word");
  55. userinput=user.next();
  56. }
  57.  
  58. if (allWords.size()==1) {
  59. System.out.println("word is"+allWords);
  60. }
  61.  
  62. if (allWords.size()==1) {
  63. System.out.println("the word was"+allWords);
  64. }
  65. }
  66.  
  67. //System.out.println("BEFORE"+allWords);
  68. //String remainingwords;
  69.  
  70.  
  71.  
  72. //for (int j=0;j<allWords.size();j++) {
  73. //String word=allWords.get(j);
  74. //remainingwords=word;
  75.  
  76.  
  77. //if (word.contains(userinput)||word.equals(userinput)||!word.contains(userinput)&&misses<lives) {
  78. //allWords.remove(j);
  79. //j--;
  80. //misses++;
  81. //System.out.println("REMAINING WORDS"+allWords);
  82. //System.out.println("Letter or word you entered is not in the answer, please enter another letter or word");
  83. //userinput=user.next();
  84. //}
  85. //System.out.println("REMAINING WORDS"+allWords);
  86.  
  87. //}
  88.  
  89. System.out.println("AFTER"+allWords);
  90.  
  91. //for (int j=0;j<allWords.size();j++) {
  92.  
  93. //}
  94.  
  95.  
  96.  
  97.  
  98. //while (in.hasNext()) {
  99. //words.add(in.next());
  100.  
  101. //if (word.length()!=randlength) {
  102.  
  103.  
  104. //}
  105. //}
  106.  
  107.  
  108. //}
  109. }
  110.  
  111.  
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement