Slangen en roltrappen :D
This commit is contained in:
parent
6507dc7abd
commit
4557f72107
|
@ -11,6 +11,7 @@ import javafx.scene.text.Text;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author J0QUE
|
||||
|
@ -21,6 +22,7 @@ public class Game extends Pane {
|
|||
|
||||
public static int[][] locations = {{290, 163}, {331, 162}, {372, 162}, {412, 161}, {446, 160}, {466, 201}, {429, 202}, {382, 201}, {340, 201}, {313, 201}, {274, 201}, {253, 235}, {293, 242}, {339, 243}, {370, 243}, {419, 242}, {447, 241}, {484, 241}, {517, 277}, {468, 277}, {431, 278}, {402, 280}, {344, 281}, {304, 282}, {277, 282}, {228, 283}, {216, 319}, {256, 319}, {291, 320}, {338, 324}, {367, 324}, {407, 323}, {453, 320}, {486, 320}, {528, 321}, {554, 359}, {506, 362}, {478, 362}, {432, 362}, {395, 361}, {346, 359}, {302, 360}, {272, 360}, {223, 359}, {203, 359}, {179, 359}, {210, 398}, {248, 399}, {292, 400}, {333, 404}, {373, 406}, {404, 396}, {446, 399}, {484, 401}, {523, 402}, {575, 402}, {563, 430}, {520, 438}, {460, 441}, {435, 443}, {394, 442}, {361, 442}, {311, 442}, {275, 439}, {225, 438}, {194, 438}, {203, 473}, {243, 477}, {297, 482}, {335, 482}, {375, 481}, {412, 481}, {450, 481}, {486, 480}, {533, 480}, {520, 517}, {465, 520}, {426, 522}, {389, 523}, {350, 524}, {317, 524}, {276, 524}, {238, 524}, {243, 553}, {276, 555}, {332, 558}, {370, 559}, {415, 560}, {456, 559}, {484, 560}, {479, 594}, {432, 596}, {387, 596}, {347, 597}, {313, 598}, {272, 598}, {287, 635}, {332, 636}, {368, 639}, {417, 642}, {449, 643}};
|
||||
|
||||
public static final HashMap<Integer, Integer> specials = new HashMap<>();
|
||||
|
||||
public static ArrayList<Player> players = new ArrayList<>();
|
||||
|
||||
|
@ -42,7 +44,8 @@ public class Game extends Pane {
|
|||
}
|
||||
//System.out.print("{");
|
||||
//this.setOnMouseClicked(event -> System.out.printf("{%d, %d},%n", (int) event.getSceneX(), (int) event.getSceneY()));
|
||||
|
||||
specials.put(5, 10);
|
||||
specials.put(15, 7);
|
||||
|
||||
Dice dice = new Dice(1100, 700);
|
||||
this.getChildren().add(dice);
|
||||
|
@ -50,11 +53,13 @@ public class Game extends Pane {
|
|||
Player p = players.get(Player.getNextActive());
|
||||
int roll = dice.roll();
|
||||
p.move(roll);
|
||||
if (roll == 6) Player.six();
|
||||
}));
|
||||
this.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));
|
||||
for (Player p : players) {
|
||||
this.getChildren().add(p.getImageView());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package nl.minkema.leendert;
|
||||
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.util.Duration;
|
||||
|
@ -22,11 +24,12 @@ public class Player {
|
|||
|
||||
private static int who = 0;
|
||||
|
||||
|
||||
public Player(Image image) {
|
||||
Random r = new Random(System.currentTimeMillis());
|
||||
this.image = image;
|
||||
this.view = new ImageView(this.image);
|
||||
this.add = new int[]{-image.widthProperty().intValue() / 2, -image.heightProperty().intValue() / 2};// new int[]{r.nextInt(10) - 5, r.nextInt(10) - 5};
|
||||
this.add = new int[]{r.nextInt(10) - 5 - image.widthProperty().intValue() / 2, r.nextInt(10) - 5 - image.heightProperty().intValue() / 2};// new int[]{r.nextInt(10) - 5, r.nextInt(10) - 5};
|
||||
coords = new int[]{coords[0] + add[0], coords[1] + add[1]};
|
||||
System.out.println(Arrays.toString(coords));
|
||||
getImageView().setTranslateX(coords[0]);
|
||||
|
@ -37,9 +40,16 @@ public class Player {
|
|||
return view;
|
||||
}
|
||||
|
||||
public void move(int waar) {
|
||||
System.out.println(waar);
|
||||
if (waar + plaats > 100) return;
|
||||
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!");
|
||||
alert.titleProperty().setValue("");
|
||||
if (!Game.specials.containsKey(plaats + roll))
|
||||
alert.show();
|
||||
if (roll + plaats > 100) {
|
||||
|
||||
return;
|
||||
}
|
||||
TranslateTransition tt = new TranslateTransition(Duration.millis(200), getImageView());
|
||||
tt.setFromX(coords[0]);
|
||||
tt.setFromY(coords[1]);
|
||||
|
@ -47,30 +57,55 @@ public class Player {
|
|||
tt.setToY(coords[1] = Game.locations[plaats + 1][1] + add[1]);
|
||||
TranslateTransition last = tt;
|
||||
|
||||
for (int i = plaats + 2; i < waar + plaats + 1; i++) {
|
||||
for (int i = plaats + 2; i < roll + plaats + 1; i++) {
|
||||
TranslateTransition tl = new TranslateTransition(Duration.millis(200), getImageView());
|
||||
tl.setFromX(coords[0]);
|
||||
tl.setFromY(coords[1]);
|
||||
tl.setToX(coords[0] = Game.locations[i][0] + add[0]);
|
||||
tl.setToY(coords[1] = Game.locations[i][1] + add[1]);
|
||||
last.setOnFinished(e -> tl.play());
|
||||
System.out.println(Arrays.toString(coords));
|
||||
last = tl;
|
||||
}
|
||||
tt.play();
|
||||
plaats += waar;
|
||||
plaats += roll;
|
||||
if (Game.specials.containsKey(plaats)) {
|
||||
TranslateTransition tl = new TranslateTransition(Duration.millis(200), getImageView());
|
||||
tl.setFromX(coords[0]);
|
||||
tl.setFromY(coords[1]);
|
||||
tl.setToX(coords[0] = Game.locations[Game.specials.get(plaats)][0] + add[0]);
|
||||
tl.setToY(coords[1] = Game.locations[Game.specials.get(plaats)][1] + add[1]);
|
||||
last.setOnFinished(e -> tl.play());
|
||||
|
||||
if (plaats==100){
|
||||
String text;
|
||||
if (plaats < Game.specials.get(plaats)) {
|
||||
text = alert.getContentText() + "\n\nRoltrappen!\nJe mag " + (Game.specials.get(plaats) - plaats) + " plaatsen vooruit!";
|
||||
} else {
|
||||
text = alert.getContentText() + "\n\nSlangen!\nJe moet " + (plaats - Game.specials.get(plaats)) + " plaatsen terug!";
|
||||
|
||||
}
|
||||
Alert alert1 = new Alert(Alert.AlertType.NONE, text, ButtonType.OK);
|
||||
alert1.show();
|
||||
|
||||
plaats = Game.specials.get(plaats);
|
||||
}
|
||||
|
||||
tt.play();
|
||||
|
||||
if (plaats == 100) {
|
||||
System.out.println("Een speler heeft gewonnen!");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static int getNextActive() {
|
||||
System.out.println(who);
|
||||
who++;
|
||||
if (who >= Game.players.size()) {
|
||||
return who = 0;
|
||||
}
|
||||
|
||||
return who;
|
||||
}
|
||||
|
||||
public static void six() {
|
||||
who -= 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue