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 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

The way I work my way, it is as follows: < / P>

  1. Create an array that stores all inferred characters ( guessArray )
  2. Create a counter that tracks the number of estimates (< Code> estimator quality )
  3. Repeat through the word for each loop for the loop and this From Mr. compare characters user guessed.
    a if word is in the word, then add the letter spaceArray to wordArray to the correct indicator of spaceArray
  4. Compare A If equals, say something, they live in X number of estimates - b is not equal to
    1. print spaceArray
    2. Call the method that allows the user Call to imagine the next letter
    3. Call this method so that the new estimate letter is processed.

      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:

        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); }}    

      You should do your processGuess method Try:

        else {System.out.println (Arrays.toString (spaceArray)); String newLetter = getGuesses (); Processguys (newlater, spacres, quotes); }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -