Added Special Dice, changed reroll number from 6 to 4
This commit is contained in:
parent
d2e803bf16
commit
ef96ad87cc
|
@ -1,40 +1,168 @@
|
|||
package nl.minkema.leendert;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Arc;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Ellipse;
|
||||
import javafx.scene.shape.Line;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author J0QUE
|
||||
* @version 1.0
|
||||
* @author Tripsas
|
||||
* @version 2.0
|
||||
*/
|
||||
public class Dice extends ImageView {
|
||||
|
||||
|
||||
private Image[] rolls = {new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Dice-1.svg/1024px-Dice-1.svg.png"),
|
||||
new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/3/34/Dice-2.svg/1024px-Dice-2.svg.png"),
|
||||
new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Dice-3.svg/1024px-Dice-3.svg.png"),
|
||||
new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/Dice-4.svg/1024px-Dice-4.svg.png"),
|
||||
new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/d/dc/Dice-5.svg/1024px-Dice-5.svg.png"),
|
||||
new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Dice-6a.svg/1024px-Dice-6a.svg.png")};
|
||||
public class Dice extends Group {
|
||||
|
||||
private final Random r;
|
||||
private Group ladybah = new Group();
|
||||
private Group dotPattern1 = new Group();
|
||||
private Group dotPattern2 = new Group();
|
||||
private Group dotPattern3 = new Group();
|
||||
private Group dotPattern5 = new Group();
|
||||
private Group dotPattern6 = new Group();
|
||||
private Group klaver = new Group();
|
||||
|
||||
public Dice(int x, int y) {
|
||||
this.r = new Random(System.currentTimeMillis());
|
||||
this.setFitHeight(100);
|
||||
this.setPreserveRatio(true);
|
||||
this.setTranslateX(x);
|
||||
this.setTranslateY(y);
|
||||
|
||||
this.setX(x);
|
||||
this.setY(y);
|
||||
Ellipse mainEll = new Ellipse(50, 50, 40, 50);
|
||||
mainEll.setFill(Color.DARKRED);
|
||||
Ellipse headEll1 = new Ellipse(34, 11, 6, 4);
|
||||
headEll1.setFill(Color.WHITE);
|
||||
Ellipse headEll2 = new Ellipse(66, 11, 6, 4);
|
||||
headEll2.setFill(Color.WHITE);
|
||||
Ellipse headEll3 = new Ellipse(44, 5, 3, 2);
|
||||
headEll3.setFill(Color.WHITE);
|
||||
Ellipse headEll4 = new Ellipse(56, 5, 3, 2);
|
||||
headEll4.setFill(Color.WHITE);
|
||||
Arc arc = new Arc(50, 20, 30, 20, 10, 160);
|
||||
Line lineBack = new Line(50, 20, 50, 100);
|
||||
Line lineHead1 = new Line(44, 0, 38, -3);
|
||||
Line lineHead2 = new Line(56, 0, 62, -3);
|
||||
this.ladybah.getChildren().add(mainEll);
|
||||
this.ladybah.getChildren().add(arc);
|
||||
this.ladybah.getChildren().add(lineBack);
|
||||
this.ladybah.getChildren().add(headEll1);
|
||||
this.ladybah.getChildren().add(headEll2);
|
||||
this.ladybah.getChildren().add(headEll3);
|
||||
this.ladybah.getChildren().add(headEll4);
|
||||
this.ladybah.getChildren().add(lineHead1);
|
||||
this.ladybah.getChildren().add(lineHead2);
|
||||
|
||||
Circle circle1 = new Circle(50, 50, 15);
|
||||
this.dotPattern1.getChildren().add(circle1);
|
||||
Circle circle2 = new Circle(33, 50, 10);
|
||||
Circle circle3 = new Circle(67, 65, 8);
|
||||
this.dotPattern2.getChildren().add(circle2);
|
||||
this.dotPattern2.getChildren().add(circle3);
|
||||
Circle circle4 = new Circle(50, 30, 7);
|
||||
Circle circle5 = new Circle(30, 50, 10);
|
||||
Circle circle6 = new Circle(60, 70, 12);
|
||||
this.dotPattern3.getChildren().add(circle4);
|
||||
this.dotPattern3.getChildren().add(circle5);
|
||||
this.dotPattern3.getChildren().add(circle6);
|
||||
Circle circle7 = new Circle(45, 30, 5);
|
||||
Circle circle8 = new Circle(67, 38, 10);
|
||||
Circle circle9 = new Circle(37, 68, 14);
|
||||
Circle circle10 = new Circle(68, 77, 9);
|
||||
Circle circle11 = new Circle(30, 40, 8);
|
||||
this.dotPattern5.getChildren().add(circle7);
|
||||
this.dotPattern5.getChildren().add(circle8);
|
||||
this.dotPattern5.getChildren().add(circle9);
|
||||
this.dotPattern5.getChildren().add(circle10);
|
||||
this.dotPattern5.getChildren().add(circle11);
|
||||
Circle circle12 = new Circle(63, 33, 9);
|
||||
Circle circle13 = new Circle(35, 32, 8);
|
||||
Circle circle14 = new Circle(72, 55, 11);
|
||||
Circle circle15 = new Circle(26, 53, 9);
|
||||
Circle circle16 = new Circle(60, 74, 8);
|
||||
Circle circle17 = new Circle(35, 78, 10);
|
||||
this.dotPattern6.getChildren().add(circle12);
|
||||
this.dotPattern6.getChildren().add(circle13);
|
||||
this.dotPattern6.getChildren().add(circle14);
|
||||
this.dotPattern6.getChildren().add(circle15);
|
||||
this.dotPattern6.getChildren().add(circle16);
|
||||
this.dotPattern6.getChildren().add(circle17);
|
||||
|
||||
Ellipse klaverLeaf1 = new Ellipse(25, 50, 25, 15);
|
||||
klaverLeaf1.setFill(Color.GREEN);
|
||||
Ellipse klaverLeaf2 = new Ellipse(75, 50, 25, 15);
|
||||
klaverLeaf2.setFill(Color.GREEN);
|
||||
Ellipse klaverLeaf3 = new Ellipse(50, 25, 15, 25);
|
||||
klaverLeaf3.setFill(Color.GREEN);
|
||||
Ellipse klaverLeaf4 = new Ellipse(50, 75, 15, 25);
|
||||
klaverLeaf4.setFill(Color.GREEN);
|
||||
|
||||
Arc klaverArcStam = new Arc(50, 100, 25, 50, 90, 160);
|
||||
klaverArcStam.setStroke(Color.GREEN);
|
||||
klaverArcStam.setStrokeWidth(3);
|
||||
klaverArcStam.setFill(Color.TRANSPARENT);
|
||||
|
||||
Arc klaverArc1 = new Arc(25, 50, 24, 4, 0, 180);
|
||||
klaverArc1.setStroke(Color.DARKGREEN);
|
||||
klaverArc1.setStrokeWidth(3);
|
||||
klaverArc1.setFill(Color.TRANSPARENT);
|
||||
|
||||
Arc klaverArc2 = new Arc(75, 50, 24, 4, 0, 180);
|
||||
klaverArc2.setStroke(Color.DARKGREEN);
|
||||
klaverArc2.setStrokeWidth(3);
|
||||
klaverArc2.setFill(Color.TRANSPARENT);
|
||||
|
||||
Arc klaverArc3 = new Arc(50, 25, 4, 24, 90, -180);
|
||||
klaverArc3.setStroke(Color.DARKGREEN);
|
||||
klaverArc3.setStrokeWidth(3);
|
||||
klaverArc3.setFill(Color.TRANSPARENT);
|
||||
|
||||
Arc klaverArc4 = new Arc(50, 75, 4, 24, 90, -180);
|
||||
klaverArc4.setStroke(Color.DARKGREEN);
|
||||
klaverArc4.setStrokeWidth(3);
|
||||
klaverArc4.setFill(Color.TRANSPARENT);
|
||||
|
||||
this.klaver.getChildren().add(klaverLeaf1);
|
||||
this.klaver.getChildren().add(klaverLeaf2);
|
||||
this.klaver.getChildren().add(klaverLeaf3);
|
||||
this.klaver.getChildren().add(klaverLeaf4);
|
||||
this.klaver.getChildren().add(klaverArcStam);
|
||||
this.klaver.getChildren().add(klaverArc1);
|
||||
this.klaver.getChildren().add(klaverArc2);
|
||||
this.klaver.getChildren().add(klaverArc3);
|
||||
this.klaver.getChildren().add(klaverArc4);
|
||||
|
||||
roll();
|
||||
}
|
||||
|
||||
public int roll() {
|
||||
int roll = r.nextInt(6);
|
||||
this.setImage(rolls[roll]);
|
||||
this.getChildren().clear();
|
||||
if (roll == 3) {
|
||||
this.getChildren().add(klaver);
|
||||
} else {
|
||||
this.getChildren().add(ladybah);
|
||||
switch (roll) {
|
||||
case 0:
|
||||
this.getChildren().add(dotPattern1);
|
||||
break;
|
||||
case 1:
|
||||
this.getChildren().add(dotPattern2);
|
||||
break;
|
||||
case 2:
|
||||
this.getChildren().add(dotPattern3);
|
||||
break;
|
||||
case 4:
|
||||
this.getChildren().add(dotPattern5);
|
||||
break;
|
||||
case 5:
|
||||
this.getChildren().add(dotPattern6);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Error drawing die");
|
||||
}
|
||||
}
|
||||
return roll + 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,9 +64,9 @@ public class Game extends Pane {
|
|||
Player p = players.get(Player.getNextActive());
|
||||
int roll = dice.roll();
|
||||
p.move(roll);
|
||||
if (roll == 6) Player.six();
|
||||
if (roll == 4) Player.four();
|
||||
playerTurn.setImage(Menu.images[players.get(Player.getNextActive()).getCh()]);
|
||||
Player.six();
|
||||
Player.four();
|
||||
}));
|
||||
//this.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));
|
||||
for (Player p : players) {
|
||||
|
|
|
@ -44,7 +44,7 @@ public class Player {
|
|||
return who;
|
||||
}
|
||||
|
||||
public static void six() {
|
||||
public static void four() {
|
||||
who -= 1;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,8 @@ public class Player {
|
|||
|
||||
public void move(int roll) {
|
||||
Alert alert = new Alert(Alert.AlertType.NONE, "Je hebt " + roll + " gegooid!", ButtonType.OK);
|
||||
if (roll == 6) alert.contentTextProperty().setValue("Je hebt " + roll + " gegooid!\nJe mag dus nog een keer!");
|
||||
if (roll == 4)
|
||||
alert.contentTextProperty().setValue("Je hebt " + roll + " gegooid!\nKlavertje 4! Je mag dus nog een keer!");
|
||||
alert.titleProperty().setValue("");
|
||||
if (!Game.specials.containsKey(plaats + roll))
|
||||
alert.show();
|
||||
|
|
Loading…
Reference in a new issue