Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //System.out.println(" |\n |\n |\n |\n__/\\__");
- Scanner scan=new Scanner(System.in);
- String[]words=new String[5];
- char help=' ';
- int player=2,score_1=0,score_2=0,i,lives=7,count=0,wrong=0, bre=0;;
- String word=" ",guess=" ",check=" ", answer=" ";
- System.out.println("WELCOME TO HANGMAN\n");
- while(count<5) {
- if (player==2)
- player--;
- else
- player++;
- System.out.println("PLAYER 1: "+score_1+"\tPLAYER 2: "+score_2);
- System.out.println("Player "+player+" enter the secret word ");
- word=scan.nextLine();
- System.out.println("\n\n\n\n\n\n\n\n");
- words[count]=word;
- String[] output=new String[word.length()];
- String[] input=new String[word.length()];
- for (i=0;i<word.length();i++)
- input[i]="_";
- for (i=0;i<word.length();i++)
- output[i]=String.valueOf(word.charAt(i));
- count++;
- lives=7;
- bre=0;
- while(true) {
- if (lives==0) {
- System.out.println("GAME OVER!\n\n\n");
- if(player==1)
- score_1++;
- else
- score_2++;
- break;
- }
- for (i=0;i<output.length;i++) {
- if (!(output[i].equals(input[i])))
- break;
- if (i==(output.length-1))
- bre++;
- }
- if (bre==1) {
- System.out.println("THAT'S THE ANSWER!\n\n\n");
- if (player==1)
- score_2++;
- else
- score_1++;
- break;
- }
- for (i=0;i<input.length;i++)
- System.out.print(input[i]+" ");
- System.out.println();
- System.out.printf("Guess a letter (%d tries left) ", lives);
- guess=scan.nextLine();
- wrong=0;
- for (i=0;i<word.length();i++) {
- help=word.charAt(i);
- check=String.valueOf(help);
- if (check.equals(guess)) {
- input[i]=check;
- wrong++;
- }
- if (i==(word.length()-1)&&wrong==0) {
- lives--;
- System.out.println("Wrong!");
- break;
- }
- if (i==(word.length()-1)&&wrong>0)
- System.out.println("Correct!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement