- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman.java
More file actions
Latest commit
69 lines (53 loc) · 1.27 KB
/
Copy pathhangman.java
File metadata and controls
69 lines (53 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
importjava.util.Random;
importjava.util.Scanner;
publicclassmain
{
publicstaticvoidmain (Stringargs[])
{
intlife = 10;
Scannerinput = newScanner(System.in);
Randomrandom = newRandom();
String[] wordlist = { "helloman", "affenkopf"};
Stringword = wordlist[random.nextInt(wordlist.length)];
char[] letters = word.toCharArray();
char[] encrypt = word.toCharArray();
for(inti = 0; i < encrypt.length; i++)
{
encrypt[i] = '_';
System.out.print(encrypt[i] + " ");
}
System.out.println();
for (inti = 1; i <= life; i++)
{
System.out.print("Your Letter:");
charmyinput = input.next().charAt(0);
for (intj = 0; j < letters.length; j++)
{
if(myinput == letters[j])
{
encrypt[j] = myinput;
System.out.println("Juhu gefunden");
}
else
{
}
}
for(intz = 0;z < encrypt.length; z++)
{
System.out.print(encrypt[z] + " ");
}
life--;
System.out.println("Falsche Noch "+ life + " Versuch NR" );
if (life == 0)
{
System.out.print("GAME OVER");
}
if((newString(word)).equals(newString(encrypt)))
{
System.out.println("voll gut ey");
break;
}
i++;
}
}
}