java - Why is method not working as I thought it would? -
I am trying to create a hangman game. I have everything work like I want with the exception of a method so far. This method is called The way I work my way, it is as follows: < / P> The problem is that when I miss this method, it does not contain a new letter, but still contains the old letter I'm not sure That's what I'm doing wrong. This is the first time that I have tried to use methods within a method. Here's my method: You should do your processGuess and takes a string letter and two string arrays as parameters. The first array is an array called
spaceArray and contains underscores which match the length of the word being guessed (example: hello output
[_, _, _, _, _ ] ). The second array is called the
wordpress and includes the word that the user is guessing
guessArray )
a if word is in the word, then add the letter spaceArray to
wordArray to the correct indicator of
spaceArray
spaceArray
Public static zero main (string [] args) FileNotFoundException throws {scanner file = new scanner (new file ("C: / PhilsForzwa / Scarbelladvertiser. ")); Instructions (); String [] dictionary = banDictinarium (file); String [] randomWord = getRandomWord (dictionary); String [] underscore arrow = showpace (random word); String letter = gates (); Processes (Letters, Underscores, Random Words); } Public static zero instructions () {System.out.println ("Let's play Hellman!"); Println (); } Public static string [] Creates Dictictory (scanner inputfile) Flannnet throws foreign expansions {int wordCount = 0; While (inputFile.hasNext ()) {string word = inputFile.next (); Word count ++; } String [] scrabneDictionary = new string [wordCount]; Scanner file = new scanner (new file ("C: / Philosforjwa / ScarbellAdvertiser.")); While (file.hasNext ()) {for (int i = 0; i & lt; wordCount; i ++) {scrabbleDictionary [i] = file.next (); }} File.close (); Return Scrabble Dipson; } Public static string [] getRandomWord (string [] dict) {string word = dict [(int) (Math.random (* * dict.length)]; string [] verb = new string [word.length ()]; (Int i = 0; i & lt; wordArray.length; i ++) {wordArray [i] = word.trim (). Substring (0, 1); word = word.trim (). Substring (1 );} Return wordArray;} Public static string [] showSpaces (string [] word) {string [] spaceArray = new string [word.length]; for (int i = 0; i & lt; word.length; i ++) {spaceArray [i] = "_";} System.out.println (Arrays.toString (spaceArray)); Println (); returning location array;} public static string string Cess () {scanner estimate = new scanner (System.in); System.out.println ("seems a letter:"); letter letter = estimate Println (); //guess.close (); return letter ;} Public static void processguo (string letter, string [] space array, string [] word array {int guessCounter = 0; string [] estimatesArray = new string [spaceArray.length]; for (int i = 0; i & lt ; SpaceArray.length; I ++) {guessCounter ++; Estimates [i] = letters; String index litter = word around [i]; If (indexLetter.equalsIgnoreCase) {spaceArray [i] = letter; }} If (spaceArray.equals (wordArray)) {System.out.println ("Yes! You won in" + seems the QP + "guess!"); } Else {System.out.println (Arrays.toString (spaceArray)); GetGuesses (); Processguys (letters, space arrays, quotes); }}
processGuess method Try:
else {System.out.println (Arrays.toString (spaceArray)); String newLetter = getGuesses (); Processguys (newlater, spacres, quotes); }
Comments
Post a Comment