⭐ Let's code a HANGMAN GAME with Java! 🕺

  Рет қаралды 3,554

Bro Code

Bro Code

Күн бұрын

Пікірлер: 20
@BroCodez
@BroCodez 27 күн бұрын
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { // JAVA HANGMAN GAME String filePath = "words.txt"; // Put your file path here ArrayList words = new ArrayList(); try(BufferedReader reader = new BufferedReader(new FileReader(filePath))){ String line; while((line = reader.readLine()) != null){ words.add(line.trim()); } } catch(FileNotFoundException e){ System.out.println("Could not find file"); } catch(IOException e){ System.out.println("Something went wrong"); } Random random = new Random(); String word = words.get(random.nextInt(words.size())); Scanner scanner = new Scanner(System.in); ArrayList wordState = new ArrayList(); int wrongGuesses = 0; for(int i = 0; i < word.length(); i++){ wordState.add('_'); } System.out.println("************************"); System.out.println("Welcome to Java Hangman!"); System.out.println("************************"); while(wrongGuesses < 6){ System.out.print(getHangmanArt(wrongGuesses)); System.out.print("Word: "); for(char c : wordState){ System.out.print(c + " "); } System.out.println(); System.out.print("Guess a letter: "); char guess = scanner.next().toLowerCase().charAt(0); if(word.indexOf(guess) >= 0){ System.out.println("Correct guess!"); for(int i = 0; i < word.length(); i++){ if(word.charAt(i) == guess){ wordState.set(i, guess); } } if(!wordState.contains('_')){ System.out.print(getHangmanArt(wrongGuesses)); System.out.println("YOU WIN!"); System.out.println("The word was: " + word); break; } } else{ wrongGuesses++; System.out.println("Wrong guess!"); } } if(wrongGuesses >= 6){ System.out.print(getHangmanArt(wrongGuesses)); System.out.println("GAME OVER!"); System.out.println("The word was: " + word); } scanner.close(); } static String getHangmanArt(int wrongGuesses){ return switch(wrongGuesses){ case 0 -> """ """; case 1 -> """ o """; case 2 -> """ o | """; case 3 -> """ o /| """; case 4 -> """ o /|\\ """; case 5 -> """ o /|\\ / """; case 6 -> """ o /|\\ / \\ """; default -> ""; }; } }
@brandx1232
@brandx1232 26 күн бұрын
not working :
@funspot9520
@funspot9520 23 күн бұрын
A while loop is missing in this code
@Hnxzxvr
@Hnxzxvr 27 күн бұрын
I remember using your vids to make stuff in python I never cared about what you were saying and I never learned anything but now I’m coding in java all the time without needing tutorials Tysm dude
@fortyquinn1301
@fortyquinn1301 27 күн бұрын
Ok
@lamaXD
@lamaXD 27 күн бұрын
Best KZbinr out there
@NebaDan-ug3kp
@NebaDan-ug3kp 27 күн бұрын
the Legend is here 🎉🎉🎉🎉🎉🎉 can you make us a flutter serious .......because any body can be software engineer with out going to college just by watching your amazing videos❤❤❤🎉🎉
@Hnxzxvr
@Hnxzxvr 27 күн бұрын
Software engineer without going to collage may be a little far but he can definitely help anyone get any coding job whether you go to collage or not
@chandugupta9990
@chandugupta9990 26 күн бұрын
the constant videos he is uploading for java its looking like java playlist is coming soon!!!!!!!!
@zhadrn
@zhadrn 20 күн бұрын
5:55 what do i need to press in order for the next line to start after the arrow? mine just starts at the beginning which is why the hangman then appears wrong when i run the code.
@thelowfer1016
@thelowfer1016 27 күн бұрын
Bro, when will you update the JS course?
@MassiveKittenFire-vw1cw
@MassiveKittenFire-vw1cw 11 күн бұрын
BroCode's perfect date is a pizza dinner and the Spongebob Movie hand to god
@Seif285
@Seif285 26 күн бұрын
Thank you bro ❤
@garagebandofficial
@garagebandofficial 27 күн бұрын
please make a video explaining Dijkstra's algorithm.
@LSTIMEGO
@LSTIMEGO 26 күн бұрын
Hello teacher can you make us a lesson about Linux terminal
@maxymusgamer9900
@maxymusgamer9900 27 күн бұрын
well damn this is goated
@Kingsglory2123
@Kingsglory2123 21 күн бұрын
What about flutter and react native
@officialdreamplayz
@officialdreamplayz 27 күн бұрын
👌👍
@mmarcaroni
@mmarcaroni 27 күн бұрын
what software are you using to code? i’m using eclipse looking for the name of this one
@друг0
@друг0 22 күн бұрын
intellij
Learn DATES & TIMES with Java in 8 minutes! 📆
8:44
Bro Code
Рет қаралды 1,9 М.
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 460 М.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 255 М.
The Dark Side of .reserve()
18:50
Logan Smith
Рет қаралды 175 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 856 М.
Why Are Scientists Making Robot Insects?
21:16
Veritasium
Рет қаралды 2 МЛН
Please Master This MAGIC Python Feature... 🪄
25:10
Tech With Tim
Рет қаралды 141 М.
Learn Java GENERICS in 13 minutes! 📦
13:56
Bro Code
Рет қаралды 3,9 М.
Programming Is NOT Enough | Add these 7 skills…
13:19
Travis Media
Рет қаралды 425 М.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН