Code the Hangman Game in Java

Поделиться
HTML-код
  • Опубликовано: 17 июн 2020
  • In this video, I will teach you how to make a hangman game in java.
    Thanks for watching the video and please leave a like and subscribe!
    *****************************************
    The link to the dictionary text file:
    www.gwicks.net/dictionaries.htm
    Download the text version for English
    unzip it and the text file is inside the folder
    *****************************************
    The Function Code:
    public static void drawHangman(int l) {
    if(l == 6) {
    System.out.println("|----------");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    }
    else if(l == 5) {
    System.out.println("|----------");
    System.out.println("| O");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    }
    else if(l == 4) {
    System.out.println("|----------");
    System.out.println("| O");
    System.out.println("| |");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    }
    else if(l == 3) {
    System.out.println("|----------");
    System.out.println("| O");
    System.out.println("| -|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    }
    else if(l == 2) {
    System.out.println("|----------");
    System.out.println("| O");
    System.out.println("| -|-");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    }
    else if(l == 1) {
    System.out.println("|----------");
    System.out.println("| O");
    System.out.println("| -|-");
    System.out.println("| /");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    }
    else{
    System.out.println("|----------");
    System.out.println("| O");
    System.out.println("| -|-");
    System.out.println("| /|");
    System.out.println("|");
    System.out.println("|");
    System.out.println("|");
    }
    }

Комментарии • 44

  • @safwanmalik3139
    @safwanmalik3139 3 года назад +3

    hey great video, just wanted to know if there is a way I can let users get the whole word and still have the commands you wrote for checking valid input. thanks !

    • @CodingWithTim
      @CodingWithTim  3 года назад +1

      What you can do is add code at the end of the while loop that asks the user for input and then uses an if statement to check If the input is the same as the hidden_text. If they are the same then set finish = true

  • @nikolcenalevski5164
    @nikolcenalevski5164 2 года назад +1

    this is really helpful for beginners like me ! thank you for sharing !!!

  • @MusicGenerationJ
    @MusicGenerationJ 3 года назад

    Exactly what I was looking for! But in my case I just want to code the program so that I can choose the word myself.
    However you got my subscription.

  • @_keita424
    @_keita424 2 года назад

    Thank you so much! I learned a lot from your video. I subscribed to your channel to get updated for your new videos :)

  • @holasanja6618
    @holasanja6618 2 года назад +1

    great video man but i am having trouble pasting in my dictionary into the SRC.... nothing happens when I right click the src and press paste
    it may be because i am using IntelliJ and not eclipse. Any thoughts or advice?

  • @pouriaghasemi3423
    @pouriaghasemi3423 3 года назад

    great video bro, learned alot!!

  • @danyel6774
    @danyel6774 2 года назад +1

    thank you, helped a lot!

  • @carlosdaniel7969
    @carlosdaniel7969 2 года назад

    Ty man, u helped me a lot

  • @kabashii1109
    @kabashii1109 3 года назад

    Ty bro, u helped me for my application hehe

  • @Defense89
    @Defense89 3 года назад

    omg your the best very nice video ithelped me understand at last how this work , now i have a request can you do one with fxml and methods accepting parameters?

  • @MadaraUchihaa7
    @MadaraUchihaa7 3 года назад +1

    Amazing video learned a lot. Quick Question what would be the best method to test short programs like hangman Junit or TDD?

    • @CodingWithTim
      @CodingWithTim  3 года назад +1

      I would just test myself if the program is short enough.

  • @makaihlya
    @makaihlya 3 года назад

    Thank you so much bro

  • @steve.d1614
    @steve.d1614 3 года назад +1

    Hey, could you suggest how I could add a warning counter so that if the user types a number or more than 1 letter they get a warning and 3 warnings would result in a life lost

    • @CodingWithTim
      @CodingWithTim  3 года назад +1

      so check their input every time they enter it. For the life lost I think you can create a variable to count how many times u warn them and when it reaches 3 you subtract their life.

    • @steve.d1614
      @steve.d1614 3 года назад

      @@CodingWithTim ty, would this be inside the same while loop that runs when input Is a number or >1 letter, and if so how would I get it to exit the while loop when lives are 0 as the loop runs while input is number and > 1 letter

    • @kushpatel8968
      @kushpatel8968 11 месяцев назад

      @@steve.d1614 www.youtube.com/@kushpatelj86/featured

  • @sincerelyliza
    @sincerelyliza 2 года назад

    hello! great video but if i wanted to know the whole word at the end how would i do that?

  • @olliebb1735
    @olliebb1735 3 года назад

    hey I know you did this video over a year ago but while(letter.length() ! = 1 || Character.isDigit(letter.charAt(0))) { this line of code is saying int cannot be converted to Boolean, wondering if you can help me out thanks

    • @olliebb1735
      @olliebb1735 3 года назад

      I really don’t understand what I’ve done wrong

    • @CodingWithTim
      @CodingWithTim  3 года назад

      it should be letter.length() != 1 instead of ! =
      There shouldn't be a space between ! and =.

    • @olliebb1735
      @olliebb1735 3 года назад

      @@CodingWithTim thank you so much!

    • @kushpatel8968
      @kushpatel8968 11 месяцев назад

      @@olliebb1735 www.youtube.com/@kushpatelj86/featured

    • @kushpatel8968
      @kushpatel8968 11 месяцев назад

      @@olliebb1735 www.youtube.com/@kushpatelj86/featured

  • @AlawiDenGhosty
    @AlawiDenGhosty 3 года назад

    String letter = input.next();
    //checks for valid input
    while(letter.length() != 1 || Character.isDigit(letter.charAt(0))); {
    System.out.println("Error Input - Try Again");
    letter = input.next();
    this while loop doesnt work properly for me, it always says an error if i put in 1 character and if i put 2+ the code would just break.

    • @CodingWithTim
      @CodingWithTim  3 года назад

      Did you put a closing bracket for the while loop?

    • @AlawiDenGhosty
      @AlawiDenGhosty 3 года назад

      @@CodingWithTim ye i did

    • @jonispatented
      @jonispatented Год назад

      After ' charAt(0))) ' get rid of your semicolon. It doesn't belong there.

    • @kushpatel8968
      @kushpatel8968 11 месяцев назад

      @@jonispatented www.youtube.com/@kushpatelj86/featured

    • @kushpatel8968
      @kushpatel8968 11 месяцев назад

      @@AlawiDenGhosty www.youtube.com/@kushpatelj86/featured

  • @jobayerrahman9955
    @jobayerrahman9955 3 года назад

    Thanks brooooooooooo.

  • @lassemadsen7382
    @lassemadsen7382 3 года назад

    How could i do this if i want a string of self typed words?

    • @CodingWithTim
      @CodingWithTim  3 года назад

      So instead of adding words from a text file, you can add it yourself. To do that, simply create an empty ArrayList of String and manually add String into the list. You can make your list that way instead.
      ***example code****
      ArrayList my_list = new ArrayList();
      my_list.add("hello");
      my_list.add("world");
      my_list.add("apple");
      ***example code****
      I manually added three words into my_list. You can follow that format for as many words as you want.

    • @lassemadsen7382
      @lassemadsen7382 3 года назад

      @@CodingWithTim could i then simply delete the “file dictionary” lines and input the array list or would I also have to delete the “word arraylist” ?

    • @CodingWithTim
      @CodingWithTim  3 года назад

      @@lassemadsen7382 sure delete the word arraylist along with the file dictionary.

    • @lassemadsen7382
      @lassemadsen7382 3 года назад

      @@CodingWithTim this might be too much to ask but could I possibly dm you somewhere and show you my code because something has gone completely wrong ..

    • @CodingWithTim
      @CodingWithTim  3 года назад

      @@lassemadsen7382Sure, I can definitely do what I can to help. Here is my email address: timtanthetitan@gmail.com
      If you have trouble with the errors, it would be helpful for me if you could send me the code and error messages through email.

  • @rtester40
    @rtester40 3 года назад

    something wrong with the dictionary link it just opens and closes nothing downloads

    • @CodingWithTim
      @CodingWithTim  3 года назад

      I updated the description, use the new instruction to download the text file

  • @shalenmathew980
    @shalenmathew980 2 года назад

    god bless u

  •  2 года назад +1

    There are bunch of things to improve in your code, Tim. From the code-quality standpoint

  • @AMRMICX2
    @AMRMICX2 3 года назад

    ahhhhh you look so cute