diff --git a/src/main/java/nl/minkema/leendert/Game.java b/src/main/java/nl/minkema/leendert/Game.java index fd144c0..ae47cff 100644 --- a/src/main/java/nl/minkema/leendert/Game.java +++ b/src/main/java/nl/minkema/leendert/Game.java @@ -4,8 +4,6 @@ import javafx.event.EventHandler; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; @@ -22,11 +20,8 @@ import java.util.HashMap; public class Game extends Pane { - public static int[][] locations; - - public static final HashMap specials = new HashMap<>(); - + public static int[][] locations; public static ArrayList players = new ArrayList<>(); public Game() { @@ -35,9 +30,9 @@ public class Game extends Pane { ImageView view = new ImageView(bord); view.setPreserveRatio(true); - view.setFitHeight(500); + view.setFitHeight(800); view.setX(150); - view.setY(135); + view.setY(0); this.getChildren().add(view); for (int i = 0, locationsLength = locations.length; i < locationsLength; i++) { @@ -45,32 +40,41 @@ public class Game extends Pane { getChildren().add(new Circle(k[0], k[1], 5, Color.RED)); getChildren().add(new Text(k[0], k[1], String.valueOf(i))); } - //System.out.print("{"); this.setOnMouseClicked(new EventHandler() { int i = 0; @Override public void handle(MouseEvent event) { - System.out.printf("%d: %d,%d,%n", i++, (int) event.getSceneX(), (int) event.getSceneY()); + //System.out.printf("%d: %d,%d%n", i++, (int) event.getSceneX(), (int) event.getSceneY()); } }); - specials.put(5, 10); - specials.put(15, 7); + ImageView playerTurn = new ImageView(); + playerTurn.setX(1000); + playerTurn.setY(50); + playerTurn.setPreserveRatio(true); + playerTurn.setFitWidth(100); + + this.getChildren().add(playerTurn); + Dice dice = new Dice(1100, 700); this.getChildren().add(dice); - this.getChildren().add(Menu.createButton("Roll", 1100, 650, e -> { + this.getChildren().add(Menu.createButton("Gooi", 1100, 650, e -> { Player p = players.get(Player.getNextActive()); int roll = dice.roll(); p.move(roll); if (roll == 6) Player.six(); + playerTurn.setImage(Menu.images[players.get(Player.getNextActive()).getCh()]); + Player.six(); })); - this.setBackground(new Background(new BackgroundFill(Color.RED, null, null))); + //this.setBackground(new Background(new BackgroundFill(Color.RED, null, null))); for (Player p : players) { this.getChildren().add(p.getImageView()); } + playerTurn.setImage(Menu.images[players.get(1).getCh()]); + } } diff --git a/src/main/java/nl/minkema/leendert/Main.java b/src/main/java/nl/minkema/leendert/Main.java index 2a7d962..42bec80 100644 --- a/src/main/java/nl/minkema/leendert/Main.java +++ b/src/main/java/nl/minkema/leendert/Main.java @@ -14,19 +14,6 @@ import java.util.Properties; public class Main extends Application { public static Scene scene; - @Override - public void start(Stage primaryStage) throws Exception { - - SvgImageLoaderFactory.install(); - - primaryStage.setTitle("Het spectaculaire tuinavontuur"); - scene = new Scene(new Menu(), 1200, 800); - primaryStage.setScene(scene); - primaryStage.setResizable(false); - primaryStage.show(); - } - - public static void main(String[] args) throws Exception { Properties properties = new Properties(); @@ -45,7 +32,26 @@ public class Main extends Application { } } + properties = new Properties(); + properties.load(Main.class.getResourceAsStream("/text/specials.properties")); + + for (Object s : properties.keySet()) { + Game.specials.put(Integer.parseInt((String) s), Integer.parseInt((String) properties.get(s))); + } + launch(args); } + + @Override + public void start(Stage primaryStage) throws Exception { + + SvgImageLoaderFactory.install(); + + primaryStage.setTitle("Het spectaculaire tuinavontuur"); + scene = new Scene(new Menu(), 1200, 800); + primaryStage.setScene(scene); + primaryStage.setResizable(false); + primaryStage.show(); + } } diff --git a/src/main/java/nl/minkema/leendert/Menu.java b/src/main/java/nl/minkema/leendert/Menu.java index a5a383e..3c39c94 100644 --- a/src/main/java/nl/minkema/leendert/Menu.java +++ b/src/main/java/nl/minkema/leendert/Menu.java @@ -4,6 +4,8 @@ import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; @@ -27,8 +29,11 @@ import java.util.Random; public class Menu extends Group { + public static Image[] images; private static Random random = new Random(System.currentTimeMillis()); - private final Image[] images; + private int hoeveel = -1; + + private ArrayList chosen = new ArrayList<>(); public Menu() throws URISyntaxException, MalformedURLException { ArrayList nodes = new ArrayList<>(); @@ -52,11 +57,11 @@ public class Menu extends Group { menuplayer.play(); menuplayer.play(); + menuplayer.stop(); + nodes.add(view); - nodes.add(createButton("2 players", 100, 100, event -> { - System.out.println("2 players"); - })); - nodes.add(createButton("3 players", 100, 150, event -> System.out.println("3 players"))); + + int imagewidth = 100; images = new Image[]{ new Image("/svg/p1.svg", imagewidth, 0, true, false), @@ -75,21 +80,55 @@ public class Menu extends Group { y += 150; x = -70; } + final int ch = i1; + iv.setOnMouseClicked(e -> { + if (chosen.contains(ch)) { + new Alert(Alert.AlertType.ERROR, "Sorry, dit karakter is al door iemand anders gekozen...").show(); + return; + } + if (hoeveel < 0) { + Alert alert = new Alert(Alert.AlertType.ERROR, "Je moet eerst kiezen hoe veel spelers je wilt!\nDruk links op de juiste hoeveelheid kaboutertjes!", ButtonType.OK); + alert.show(); + } else { + Image image = new Image(i.impl_getUrl(), 0, 50, true, false); + Game.players.add(new Player(image, ch)); + hoeveel--; + if (hoeveel == 0) { + Main.scene.setRoot(new Game()); + } else { + String een = "Er moet nog 1 persoon kiezen!"; + String meer = String.format("Er moeten nog %d mensen kiezen!", hoeveel); + Alert alert = new Alert(Alert.AlertType.NONE, hoeveel > 1 ? meer : een, ButtonType.OK); + alert.show(); + } + + } + chosen.add(ch); + }); nodes.add(iv); } int x2 = 30, y2 = 50; for (int i = 0; i < 4; i++) { - if (i==0) continue; + if (i == 0) continue; int number = 1 + i; - int locy = (int) (y2 + 150 * i + 10); + int locy = y2 + 150 * i + 10; for (int e = 0; e < number; e++) { ImageView view1 = new ImageView(new Image("/svg/p1.svg", 75, 0, true, false)); view1.setX(x2 + 85 * e + 10 * e); view1.setY(locy); nodes.add(view1); } + Rectangle clickable = new Rectangle(x2 - 10, locy + 125, 95 + i * 95, 150); + clickable.setFill(Color.TRANSPARENT); + clickable.setStroke(Color.BLACK); + final int s = i + 1; + clickable.setOnMouseClicked(e -> { + hoeveel = s; + new Alert(Alert.AlertType.INFORMATION, "Alle " + hoeveel + " spelers kunnen nu een karakter kiezen. \nAls iemand de verkeerde kiest kan je opnieuw \nop de knop drukken om opnieuw te beginnen.").show(); + }); + nodes.add(clickable); } getChildren().addAll(nodes); diff --git a/src/main/java/nl/minkema/leendert/Player.java b/src/main/java/nl/minkema/leendert/Player.java index cd15679..75c25e1 100644 --- a/src/main/java/nl/minkema/leendert/Player.java +++ b/src/main/java/nl/minkema/leendert/Player.java @@ -7,7 +7,6 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.util.Duration; -import java.util.Arrays; import java.util.Random; /** @@ -16,30 +15,51 @@ import java.util.Random; */ 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]; - private final int[] add; - - private static int who = 0; - public Player(Image image) { + 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]}; - System.out.println(Arrays.toString(coords)); 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 six() { + who -= 1; + } + public ImageView getImageView() { return view; } + public Image getImage() { + return image; + } + + 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 == 6) alert.contentTextProperty().setValue("Je hebt " + roll + " gegooid!\nJe mag dus nog een keer!"); @@ -95,17 +115,4 @@ public class Player { } } - - public static int getNextActive() { - who++; - if (who >= Game.players.size()) { - return who = 0; - } - - return who; - } - - public static void six() { - who -= 1; - } } diff --git a/src/main/resources/svg/Bord.svg b/src/main/resources/svg/Bord.svg index 84601af..b056063 100644 --- a/src/main/resources/svg/Bord.svg +++ b/src/main/resources/svg/Bord.svg @@ -1,107 +1,180 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/text/locations.properties b/src/main/resources/text/locations.properties index 2d08470..b9cf8e6 100644 --- a/src/main/resources/text/locations.properties +++ b/src/main/resources/text/locations.properties @@ -1,101 +1,101 @@ -0: 290,163 -1: 331,162 -2: 372,162 -3: 412,161 -4: 446,160 -5: 466,201 -6: 429,202 -7: 382,201 -8: 340,201 -9: 313,201 -10: 274,201 -11: 253,235 -12: 293,242 -13: 339,243 -14: 370,243 -15: 419,242 -16: 447,241 -17: 484,241 -18: 517,277 -19: 468,277 -20: 431,278 -21: 402,280 -22: 344,281 -23: 304,282 -24: 277,282 -25: 228,283 -26: 216,319 -27: 256,319 -28: 291,320 -29: 338,324 -30: 367,324 -31: 407,323 -32: 453,320 -33: 486,320 -34: 528,321 -35: 554,359 -36: 506,362 -37: 478,362 -38: 432,362 -39: 395,361 -40: 346,359 -41: 302,360 -42: 272,360 -43: 223,359 -44: 203,359 -45: 179,359 -46: 210,398 -47: 248,399 -48: 292,400 -49: 333,404 -50: 373,406 -51: 404,396 -52: 446,399 -53: 484,401 -54: 523,402 -55: 575,402 -56: 563,430 -57: 520,438 -58: 460,441 -59: 435,443 -60: 394,442 -61: 361,442 -62: 311,442 -63: 275,439 -64: 225,438 -65: 194,438 -66: 203,473 -67: 243,477 -68: 297,482 -69: 335,482 -70: 375,481 -71: 412,481 -72: 450,481 -73: 486,480 -74: 533,480 -75: 520,517 -76: 465,520 -77: 426,522 -78: 389,523 -79: 350,524 -80: 317,524 -81: 276,524 -82: 238,524 -83: 243,553 -84: 276,555 -85: 332,558 -86: 370,559 -87: 415,560 -88: 456,559 -89: 484,560 -90: 479,594 -91: 432,596 -92: 387,596 -93: 347,597 -94: 313,598 -95: 272,598 -96: 287,635 -97: 332,636 -98: 368,639 -99: 417,642 -100: 449,643 \ No newline at end of file +0:438,52 +1:496,53 +2:548,53 +3:609,52 +4:664,53 +5:704,111 +6:639,109 +7:583,110 +8:529,110 +9:472,107 +10:418,105 +11:381,166 +12:446,173 +13:499,168 +14:554,169 +15:605,168 +16:670,167 +17:721,168 +18:758,220 +19:704,228 +20:635,226 +21:578,223 +22:521,223 +23:451,222 +24:413,222 +25:346,224 +26:323,281 +27:379,281 +28:434,281 +29:490,281 +30:545,281 +31:603,280 +32:665,281 +33:720,280 +34:782,280 +35:809,330 +36:755,335 +37:703,336 +38:646,337 +39:588,337 +40:527,338 +41:470,339 +42:408,336 +43:361,336 +44:289,339 +45:265,399 +46:322,397 +47:372,395 +48:439,395 +49:500,393 +50:554,393 +51:606,396 +52:675,396 +53:721,396 +54:792,396 +55:835,397 +56:817,452 +57:755,455 +58:695,457 +59:648,457 +60:581,455 +61:528,454 +62:467,454 +63:401,454 +64:358,452 +65:302,453 +66:320,511 +67:378,515 +68:442,513 +69:486,512 +70:551,513 +71:607,514 +72:671,515 +73:732,515 +74:782,514 +75:758,572 +76:687,573 +77:633,572 +78:575,573 +79:533,574 +80:471,572 +81:407,570 +82:357,570 +83:382,639 +84:437,636 +85:503,633 +86:548,631 +87:605,630 +88:660,627 +89:733,628 +90:695,672 +91:648,681 +92:582,682 +93:526,682 +94:479,682 +95:411,683 +96:444,736 +97:497,751 +98:549,749 +99:607,748 +100:674,746 \ No newline at end of file diff --git a/src/main/resources/text/specials.properties b/src/main/resources/text/specials.properties new file mode 100644 index 0000000..e69de29