diff options
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java')
| -rw-r--r-- | src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java b/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java index 7dacee8..1954a8c 100644 --- a/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java +++ b/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java @@ -17,7 +17,7 @@ public class Spiel public static final int MAXHUET = 3; - private Random rnd = new Random(); + public static final Random RAND = new Random(); /** * Places the pea under a shell. @@ -25,7 +25,7 @@ public class Spiel */ private void nussVerstecken() { - nussPlatz = rnd.nextInt(MAXHUET); + nussPlatz = RAND.nextInt(MAXHUET); } /** @@ -37,6 +37,10 @@ public class Spiel */ private int zeigeHuetchen(int ersterTipp) { + if (ersterTipp < 0 || ersterTipp > MAXHUET) + { + throw new IllegalArgumentException("Tip liegt nicht im Bereich."); + } int erg = -1; if (ersterTipp != nussPlatz) { @@ -44,7 +48,7 @@ public class Spiel } else { - erg = (ersterTipp + rnd.nextInt(MAXHUET - 1)) % MAXHUET; + erg = (ersterTipp + RAND.nextInt(MAXHUET - 1)) % MAXHUET; } return erg; } @@ -54,9 +58,9 @@ public class Spiel * * @return The shell number */ - private int aufloesung() + private boolean aufloesung(int zweiterTipp) { - return nussPlatz; + return nussPlatz == zweiterTipp; } /** @@ -75,10 +79,8 @@ public class Spiel int tipp = -1; nussVerstecken(); tipp = spieler.ersterTipp(); - assert tipp >= 0 && tipp <= MAXHUET; tipp = spieler.zweiterTipp(zeigeHuetchen(tipp)); - assert tipp >= 0 && tipp <= MAXHUET; - return tipp == aufloesung(); + return aufloesung(tipp); } } |
