122 lines
4.1 KiB
Java
122 lines
4.1 KiB
Java
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;
|
|
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* @author J0QUE
|
|
* @version 1.0
|
|
*/
|
|
public class Player {
|
|
|
|
private static int who = 0;
|
|
private final Image image;
|
|
private final ImageView view;
|
|
private final int ch;
|
|
private final int[] add;
|
|
private int plaats = 0;
|
|
private int[] coords = Game.locations[plaats];
|
|
|
|
|
|
public Player(Image image, int ch) {
|
|
this.ch = ch;
|
|
Random r = new Random(System.currentTimeMillis());
|
|
this.image = image;
|
|
this.view = new ImageView(this.image);
|
|
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]};
|
|
getImageView().setTranslateX(coords[0]);
|
|
getImageView().setTranslateY(coords[1]);
|
|
}
|
|
|
|
public static int getNextActive() {
|
|
who++;
|
|
if (who >= Game.players.size()) {
|
|
return who = 0;
|
|
}
|
|
|
|
return who;
|
|
}
|
|
|
|
public static void four() {
|
|
who -= 1;
|
|
}
|
|
|
|
public ImageView getImageView() {
|
|
return view;
|
|
}
|
|
|
|
public int getCh() {
|
|
return ch;
|
|
}
|
|
|
|
public void move(int roll) {
|
|
Alert alert = new Alert(Alert.AlertType.NONE, "Je hebt " + roll + " gegooid!", ButtonType.OK);
|
|
if (roll == 4)
|
|
alert.contentTextProperty().setValue("Je hebt " + roll + " gegooid!\nKlavertje 4! Je mag dus nog een keer!");
|
|
alert.titleProperty().setValue("");
|
|
if (plaats + roll == 69 && Main.memes) {
|
|
alert.contentTextProperty().setValue("heheheh 69 icksdie\n" + alert.getContentText());
|
|
}
|
|
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]);
|
|
tt.setToX(coords[0] = Game.locations[plaats + 1][0] + add[0]);
|
|
tt.setToY(coords[1] = Game.locations[plaats + 1][1] + add[1]);
|
|
TranslateTransition last = tt;
|
|
|
|
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());
|
|
last = tl;
|
|
}
|
|
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());
|
|
|
|
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!");
|
|
Alert alert2 = new Alert(Alert.AlertType.WARNING, "Speler " + Menu.names[getCh()], ButtonType.OK);
|
|
alert2.show();
|
|
}
|
|
}
|
|
|
|
}
|