Тёмный

Hangman Game in Java - Full Tutorial (Beginning to End) 

Coding with John
Подписаться 361 тыс.
Просмотров 56 тыс.
50% 1

Опубликовано:

 

11 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 68   
@megumegu724
@megumegu724 Год назад
I love how he teaches with a bit of humor. It makes learning what he's teaching fun. Thank you so much!
@AyshaFilms
@AyshaFilms 3 года назад
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!
@sohmtee8140
@sohmtee8140 2 года назад
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!
@ykalchev
@ykalchev 2 года назад
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 :)
@katiaobraztsova7582
@katiaobraztsova7582 9 месяцев назад
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!
@DragonOfTheWest412
@DragonOfTheWest412 3 года назад
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!!
@CodingWithJohn
@CodingWithJohn 3 года назад
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.
@DragonOfTheWest412
@DragonOfTheWest412 3 года назад
@@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.
@DragonOfTheWest412
@DragonOfTheWest412 3 года назад
This channel is seriously underrated.
@justinyasuumi7916
@justinyasuumi7916 3 года назад
this channel is so underrated :(
@anchs2501
@anchs2501 Год назад
Im rarely this entertained, watching you code something from scratch is really soothing. Keep it up
@kidcube7139
@kidcube7139 2 года назад
the way you coded and explained, it was really awesome. It'll be really helpful if you can make more video like this
@MTB_Bay_Area
@MTB_Bay_Area Год назад
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.
@samuvisser
@samuvisser 2 года назад
Cool video. The correctCount is not needed though, just having a boolean that changes to false if even 1 dash is printed would have been better
@rajkumarmarni
@rajkumarmarni Год назад
Hey John, I am trying to learn Java. I realized that you are one of the best Java Programmer in the world .Please keep it up with your good work.
@abbynormal9050
@abbynormal9050 Год назад
I'm taking Computer Science II with a terrible instructor and this video was a God send. Thanks!
@pendago8484
@pendago8484 6 месяцев назад
You are in my top 5 youtube teachers. Thanx.
@jonispatented
@jonispatented Год назад
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?
@varunkansal4251
@varunkansal4251 Год назад
Hey John! I love the informative video! Thank you very much for teaching me how to code the Hangman game in Java.
@violetj153
@violetj153 2 года назад
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.
@babycarrot5523
@babycarrot5523 2 года назад
that’s great debug and design example , deserve 10k likes!
@saileshrachapudi8486
@saileshrachapudi8486 Год назад
Thank you❤
@heartoutloud7498
@heartoutloud7498 2 года назад
Man you have the best coding videos arond! Great explanations AND funny! Awesome!
@ebubekirkoca
@ebubekirkoca 2 года назад
This was wonderful, I'm really really appreciated :)
@abhisaragarwal9084
@abhisaragarwal9084 2 года назад
The game is very cool thnx for the tutorial I am amazed to see how it works
@vz_and_trains
@vz_and_trains 3 года назад
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)?
@CodingWithJohn
@CodingWithJohn 3 года назад
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!
@Pacvalham
@Pacvalham 2 года назад
Another option: use a Set instead of a List, and the duplication problem wouldn't exist.
@michalcapek7281
@michalcapek7281 Год назад
Hi John! Great tutorial! I wanted to ask why you used word.size() vs. word.length() around 10:20 in the video.
@lukas582
@lukas582 Год назад
"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()
@clownshapiro5119
@clownshapiro5119 Год назад
thanks king
@katiaobraztsova7582
@katiaobraztsova7582 9 месяцев назад
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?
@morzuchowsky8923
@morzuchowsky8923 Год назад
Nice tut! :)
@yogalifeclubPL
@yogalifeclubPL Год назад
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?
@lazy8cabrera137
@lazy8cabrera137 11 месяцев назад
Recheck the code. Make sure all break; are inside the while(true) part
@gametech2331
@gametech2331 3 года назад
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"};
@CodingWithJohn
@CodingWithJohn 3 года назад
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");
@gametech2331
@gametech2331 3 года назад
@@CodingWithJohn thanks
@johnburgess6485
@johnburgess6485 Год назад
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.
@lancerowiebuan6271
@lancerowiebuan6271 3 года назад
Hey bro thank u!
@FadiQv
@FadiQv 3 года назад
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!
@CodingWithJohn
@CodingWithJohn 3 года назад
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!
@FadiQv
@FadiQv 3 года назад
@@CodingWithJohn Thank you so much, I wasnt expecting such a detailed response! That really clarifies everything. You are a godsend haha.
@CodingWithJohn
@CodingWithJohn 3 года назад
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.
@madhavganesh2342
@madhavganesh2342 2 года назад
Make full java course please
@sergeipalanichka5691
@sergeipalanichka5691 2 года назад
codingwithjohn.thinkific.com/courses/java-for-beginners
@moonlightt413
@moonlightt413 3 года назад
for the source you provided; is it okay if I remove player one completely? i mean is it still gonna work? Btw thank you :D
@CodingWithJohn
@CodingWithJohn 3 года назад
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!
@moonlightt413
@moonlightt413 3 года назад
@@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!!
@jrmerced
@jrmerced 2 года назад
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
@samcousins3204
@samcousins3204 2 года назад
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
@Pacvalham
@Pacvalham 2 года назад
I recommend making separate files for different categories.
@eneduerabe9848
@eneduerabe9848 3 года назад
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?
@eugenesmith9940
@eugenesmith9940 Год назад
Is it ok you didn't close any scanner?
@hikki4341
@hikki4341 Год назад
What to do if an error shows up when the user inputs nothing?
@alexanderouseph
@alexanderouseph 2 года назад
y didnt u use switch statement for the wrong count?
@NiChOlAs-gw7iw
@NiChOlAs-gw7iw Год назад
I love u !
@bsit1-1daronmangaoang35
@bsit1-1daronmangaoang35 3 года назад
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.
@CodingWithJohn
@CodingWithJohn 3 года назад
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!
@bsit1-1daronmangaoang35
@bsit1-1daronmangaoang35 3 года назад
@@CodingWithJohn Thank you! I am a student from Philippines and I am now learning GUI in Java 🙂
@CodingWithJohn
@CodingWithJohn 3 года назад
Nice! I haven't worked a ton with GUIs in Java myself (my job deals largely with big back-end web services), so I think that'll be cool!
@TheDarja89
@TheDarja89 11 месяцев назад
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
@noahgsolomon
@noahgsolomon 2 года назад
U A G
@teemolol3075
@teemolol3075 5 месяцев назад
What if we change all that if with: public static void drawHangman(int wrongCount) { System.out.println(" ------"); System.out.println(" | |"); String[] stages = { " O", // 1 " \\ /", // 2 " |", // 3 " / \\", // 4 "_ __", // 5 }; for (int i = 0; i < stages.length; i++) { if (i < wrongCount) { System.out.println(stages[i]); } else { System.out.println(""); } } }
@michaelsandoval3538
@michaelsandoval3538 2 года назад
lmao I can't even get passed step 1 :/ I am doomed
@michaelsandoval3538
@michaelsandoval3538 2 года назад
When I paste the path to my file it has "\" instead of "/" like the tutorial's.
@Moonlightglare
@Moonlightglare Год назад
@@michaelsandoval3538 all you have to do is change them to / and it should work for you.
Далее
Map and HashMap in Java - Full Tutorial
10:10
Просмотров 582 тыс.
Lambda Expressions in Java - Full Simple Tutorial
13:05
Arch Linux Experience - Hyprland
39:02
Просмотров 137 тыс.