diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..bfbeb0d --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,3 @@ +{ + "image": "mcr.microsoft.com/devcontainers/java:21" +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..add4f4e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "vscjava.vscode-java-pack" + ] +} \ No newline at end of file diff --git a/Dice.java b/Dice.java index 5266834..fb7d021 100644 --- a/Dice.java +++ b/Dice.java @@ -3,7 +3,7 @@ public class Dice { private int id; - private int value; + protected int value; public Dice(int id) { this.id = id; diff --git a/DiceGame.java b/DiceGame.java index ea6febf..77636f2 100644 --- a/DiceGame.java +++ b/DiceGame.java @@ -43,10 +43,38 @@ public void start() { } private void move(Player player) { - dices.add(new Dice(1)); - dices.add(new Dice(2)); - dices.add(new Dice(3)); + int input; System.out.println(player.getName() + " hat aktuell " + player.getScore() + " Punkte"); + if (player.getSpecialAvailable()) { + System.out.print( + player.getName() + ", moechtest Du einmalig Spezialwuerfel verwenden (1=ja, 2=nein)?: "); + input = scanner.nextInt(); + if (input == 1) { + System.out.print( + player.getName() + + ", welche Spezialwuerfel moechtest Du verwenden (1=4-5-6-Wuerfel," + + " 2=1-2-3-Wuerfel)?: "); + input = scanner.nextInt(); + if (input == 1) { + dices.add(new HighValueDice(4)); + dices.add(new HighValueDice(5)); + dices.add(new HighValueDice(6)); + } else { + dices.add(new LowValueDice(7)); + dices.add(new LowValueDice(8)); + dices.add(new LowValueDice(9)); + } + player.setSpecialAvailable(false); + } else { + dices.add(new Dice(1)); + dices.add(new Dice(2)); + dices.add(new Dice(3)); + } + } else { + dices.add(new Dice(1)); + dices.add(new Dice(2)); + dices.add(new Dice(3)); + } System.out.print(player.getName() + ", moechtest Du wuerfeln (true, false)?: "); if (scanner.nextBoolean()) { diceCup.rollTheDices(dices); diff --git a/HighValueDice.java b/HighValueDice.java new file mode 100644 index 0000000..f28d9ac --- /dev/null +++ b/HighValueDice.java @@ -0,0 +1,13 @@ +import java.util.Random; + +public class HighValueDice extends Dice { + + public HighValueDice(int id) { + super(id); + } + + public void rollTheDice() { + Random random = new Random(); + value = random.nextInt(3) + 4; + } +} diff --git a/LowValueDice.java b/LowValueDice.java new file mode 100644 index 0000000..1af9a64 --- /dev/null +++ b/LowValueDice.java @@ -0,0 +1,13 @@ +import java.util.Random; + +public class LowValueDice extends Dice { + + public LowValueDice(int id) { + super(id); + } + + public void rollTheDice() { + Random random = new Random(); + value = random.nextInt(3) + 1; + } +} diff --git a/Player.java b/Player.java index dee3b13..5f57fb6 100644 --- a/Player.java +++ b/Player.java @@ -3,9 +3,12 @@ public class Player { private String name; private int score; private boolean isActive; + private boolean specialAvailable; public Player(String name) { this.name = name; + isActive = true; + specialAvailable = true; } public String getName() { @@ -27,4 +30,12 @@ public boolean isActive() { public void setActive(boolean isActive) { this.isActive = isActive; } + + public boolean getSpecialAvailable() { + return specialAvailable; + } + + public void setSpecialAvailable(boolean specialAvailable) { + this.specialAvailable = specialAvailable; + } }