summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2014-11-12 15:29:01 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2014-11-12 15:29:01 +0100
commit0a17d5dd687ced4dd501097e6d15376ccbb8b281 (patch)
treebf378b0ed3842690bf43e2cedd298d68834b55f1 /src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java
parent5a90d8002fc97a027c3d4afd48dc479b5f0b5441 (diff)
downloadJava1-0a17d5dd687ced4dd501097e6d15376ccbb8b281.tar.gz
Java1-0a17d5dd687ced4dd501097e6d15376ccbb8b281.zip
Assignment No.7 after correction
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java')
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java18
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);
}
}