Repository navigation
Expand file tree
/
Copy pathRockPaperScissors.java
More file actions
62 lines (54 loc) · 2.4 KB
/
Copy pathRockPaperScissors.java
File metadata and controls
62 lines (54 loc) · 2.4 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
import java.util.Random;
import java.util.Scanner;
public class RockPaperScissors {
public static void main(String[] args) {
// Scanner aus der Loop raus, weil Java mehrere Scanner-Objekte hasst.
Scanner sc = new Scanner(System.in);
while(true) {
// sps = SteinPapierSchere für den Player Input
String[] sps = {"Stein", "Papier", "Schere"};
// Alles was der Computer aussuchen kann. Hier einfach die Länge des Arrays vom Spielerinput gegeben.
String computerMove = sps[new Random().nextInt(sps.length)];
String playerMove;
while(true) {
System.out.println("Wählst du Stein, Papier oder Schere?");
playerMove = sc.nextLine();
if (playerMove.equals("Stein") || playerMove.equals("Papier") || playerMove.equals("Schere")) {
break;
}
System.out.println(playerMove + " ,dein Ernst? Vallah Brudi, das ist keine gültige Eingabe, try again.");
}
System.out.println("Computer sagt: " + computerMove);
if (playerMove.equals(computerMove)) {
System.out.println("Unentschieden!");
}
else if (playerMove.equals("Stein")) {
if (computerMove.equals("Papier")) {
System.out.println("Du hast verloren, hehe.");
} else if (computerMove.equals("Schere")) {
System.out.println("Oh man, du hast gewonnen.");
}
}
else if (playerMove.equals("Papier")) {
if (computerMove.equals("Schere")) {
System.out.println("Du hast verloren, hehe.");
} else if (computerMove.equals("Stein")) {
System.out.println("Oh man, du hast gewonnen.");
}
}
else if (playerMove.equals("Schere")) {
if (computerMove.equals("Stein")) {
System.out.println("Du hast verloren, hehe.");
} else if (computerMove.equals("Papier")) {
System.out.println("Oh man, du hast gewonnen.");
}
}
System.out.println("Nochmals spielen? (Ja/Nein)");
String playAgain = sc.nextLine();
if (!playAgain.equals("Ja")) {
break;
}
}
sc.close();
}
}