I coded this within an hour. It was so much fun and i learned A LOT! Best way to learn coding is to follow tutorials like these, thank you so much John!
One thing I love about you is that there's never a dull moment in your tutorials. Your sense of humor is really amazing and I had fun watching this tutorial. I also leant a LOT! Thank you so much!
Thanks a lot John. You describes everything so calm, short and clear. It is all in the right order and after watching almost every single one of your videos I can say that you are one of the best Java guides out there. Thanks again and keep going man :)
I just watched this at work (while doing a mecanichal task of course) and I can't wait to get home to write it. Your tutorials are so fun and useful! Please, keep them coming!
I tutor and teach programming classes at a college. I get so many cool ideas off you for my intro to objects class. I also use you as a supplemental resource for students. You truly are amazing!!
That's awesome, thanks so much for sharing the videos with them! Let me know if there's some topic you find students struggle with consistently, and I can see if I can put out a useful video or two about it.
@@CodingWithJohn The majority of the students we get in for tutoring are for our intro to programming class which is taught in Java. So it’s mostly people who are extremely lost on how to even get started. The students can explain to me perfectly in English what the program has to do. As soon as they have to turn the English into Java they get lost. So I break it down and go through the assignment with them and ask if we need user input, what variables do we need and so on. I also get a huge surge of students in for help when that intro class gets to loops and methods. Especially methods though.
I suggest mapping the word one time and using the map to reconstruct the word as the user is guessing the letters. In the above algorithm the program is passing on the word over and over again for each letter that the user is selecting. furthermore, each letter has to be reposition, and the state of the contracted word is never saved. Hence, for each letter we are making a pass on the word and the constructed word. this can be resolved by using HashMap where the ArrayList contains the index of the letter. The constructed word can be saved in a char[] currentState. since it is an object it can be passed to any function and updated for the record.
16:57 Couldn't we make that a boolean isCorrect = true; instead of an int correctCount, and then just have it return isCorrect at the end of the method, and put isCorrect = false; in the else block, right after the println("-");? Wouldn't that do the same thing but better?
I am really thankful to you. The code works really well and very well explained and clear which made it easy for me to understand. Thank you very much Mr. John.
This is a great video, and the code works really well! Is there a way to add in what letters the player has already guessed (whether they were right or wrong)?
Yes there absolutely is: The playerGuesses list variable will contain all the letters the player has guessed so far. So you can just display it as-is if you want each turn before the player guesses again. Right now though it will contain duplicates if the player guesses the same letter twice, so if you want to be fancy you can check if the list already contains the character they guess before you add it again. Or you could also sort those letters into alphabetical order, just to display them in a nicer way. I'll leave both of those things as small exercises to the viewers. Thanks for watching!
"words" is a list - you can get the amount of objects in a list using .size() on the other hand "word" is a string - you can get the amout of characters in a string using .length()
John, when at 27:20 you said you can't pass wrongCount to the method because it's not how Java works, is it possible that you forgot to mention that this would be for "int worngCount", but then you changed it to "Integer" and since Integer is non-primitive (pass-by-reference) it does work?
Hi John! Your tutorial is very cool! I am trying to follow all the steps however encountered some problems with breaks - intellij is telling me "Break outside switch or loop" (hence the exception). what to do now?
Do you know how to replace your Scanner scanner = new Scanner(new File("C:/Users/Home/Desktop/words_alpha.txt")); with private static String[] words = {"car", "potato", "cat", "horse", "apple", "boat"};
Absolutely! You can replace pretty much everything in the "if (players.equals("1")) {" block with just this: List words = Arrays.asList("car", "potato", "cat", "horse", "apple", "boat");
Hey John. I am currently enrolled in a bootcamp and looking for good books on coding. Is Effective Java still relevant in your opinion? I was concerned that it might be too old of a book.
Excellent video John! I'm actually going to be developing a similar game for a project so this is very useful. I had a question though, I would like to use fewer words in the text file(100). I want to make sure that during one gameplay, the player does not get repeated words. Would it be possible to delete the word from the array list once it's used? When would be the best time to delete the word, before or after the program is completed? Really appreciate the video, your explanation is very beginner friendly!
Awesome, glad it was helpful! There's absolutely a way to do that. You'll have to restructure things a bit though, but it's not tough. The whole one-player version would have to be in a loop (where you ask the player if they want to play again, and if they say no, exit the loop, otherwise do the loop again. The "words" ArrayList will have to be declared outside of that loop so you can remove items from it inside the loop. You can remove the word from the "words" list with the following command (pretty simple!), and it doesn't really matter if you remove it right after you get the random word, or at the end of the loop, since already have the variable holding onto the selected word. words.remove(word); So the structure/pseudocode for that would be something like: ArrayList words = getArrayListFromFile; while (true){ word = random word from words ArrayList; words.remove(word); play the game with the current word; println("Do you want to play again? (Y/N") String playAgain = scanner.nextLine(); if(!"y".equalsIgnoreCase(playAgain)){ break; } } If they say "Y" to play again, it will grab the random word from the list with any words already used removed. If they end the program and start it up again, it will start with the full list again of course, from the file. Thanks for watching, and for the question!
No prob, I enjoy responding to subscriber's questions and comments! If the channel gets huge that may get tougher to respond to every one but for now it's certainly doable.
Yep - you'll have to do those modifications correctly of course, but you can absolutely take out the whole choice of one or two players, and all the file input code and everything and get it to be just the two player only with very little work. And thanks for watching!
@@CodingWithJohn Gotcha:D, I have one more question. what do you suggest(array?) for you know how you make mistakes I want that to appear on output for example the actual word is cyber but then I make first mistake w, then b and then o.... the output should be like MISTAKES: w b o. Appreciate your help!!
This is very helpful.. I have a question, how can I add a scoring in this game? And can i put a categories in words like animals, fruits and countries? Pls answer and thank you so much
in coding, you can do whatever you want! just code it. he will never tell you always how to code what you want, but if you can imagine it, you can make it yourself always
Hey could u explain to me how this works? bcs when i print(playerGuesses) it all has invidual index like if my guesses were: q,r,w,e,r,y q = [0] w =[1] itp; and how it finds same index in String and put char there if playerGuesses has diffrent indexes?
In 1 player mode, how about if the player wants to play again? for example after the program is finished you will print System.out.print("Do you want to play again (Yes/no)?");...... how do you put it in the program and start playing again.
Good question! Basically you can surround your code with a while(true) loop, then at the end of the game, prompt the player for the input as you mention, the break out the loop if they choose not to play again. I have this exact functionality you're looking for in my Rock Paper Scissors program (ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-DyqMglmrido.html). You should be able to take the code logic from there, and use it for this Hangman game as well. It'll be good practice to figure out incorporating that into this game. Thanks for watching!
Interesting video, good and funny explanations. But only one thing i have to ccomment / have question, the head is floating on her own ( cause i saw no neck :DDDDD ) #necklesshangman