summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java')
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java69
1 files changed, 63 insertions, 6 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java b/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java
index 0628d8c..7dacee8 100644
--- a/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java
+++ b/src/de/fhswf/in/inf/java1/aufgabe7/Spiel.java
@@ -6,22 +6,79 @@ package de.fhswf.in.inf.java1.aufgabe7;
import java.util.Random;
/**
- * TODO Add comment here
+ * Simulates a shell game.
*
- * @author $Author: $
- * @version $Revision: $, $Date: $ UTC
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
*/
public class Spiel
{
private int nussPlatz = -1;
+
+ public static final int MAXHUET = 3;
+
private Random rnd = new Random();
+
+ /**
+ * Places the pea under a shell.
+ *
+ */
+ private void nussVerstecken()
+ {
+ nussPlatz = rnd.nextInt(MAXHUET);
+ }
+
+ /**
+ * Returns an empty shell, which the user didn't choose.
+ *
+ * @param ersterTipp
+ * The first choice of the player.
+ * @return An empty shell number of the remaining shells
+ */
+ private int zeigeHuetchen(int ersterTipp)
+ {
+ int erg = -1;
+ if (ersterTipp != nussPlatz)
+ {
+ erg = MAXHUET - nussPlatz - ersterTipp;
+ }
+ else
+ {
+ erg = (ersterTipp + rnd.nextInt(MAXHUET - 1)) % MAXHUET;
+ }
+ return erg;
+ }
+
+ /**
+ * Returns the shell number with the pea.
+ *
+ * @return The shell number
+ */
+ private int aufloesung()
+ {
+ return nussPlatz;
+ }
+
/**
- * TODO Add constructor comment here
+ * Simulates a complete game.
*
+ * @param spieler
+ * The player who plays.
+ * @return Boolean, if the player choose correct.
*/
- public Spiel()
+ public boolean spielDurchlauf(Spieler spieler)
{
- // TODO Auto-generated constructor stub
+ if (spieler == null)
+ {
+ throw new IllegalArgumentException("A player hast to play.");
+ }
+ 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();
}
}