├── README.md ├── SnakesAndLaddersClassDiagram.uxf ├── resources └── Res │ ├── ResourceLoader.java │ ├── images │ ├── Anaconda-PNG-Image.png │ ├── Dice.png │ ├── Ladder-PNG-Image-45634.png │ ├── Rose-Metal-Wallpaper-Wall-Mural-Rose-Gold-Metal-sheet-feature-wallpaper.jpg │ ├── Snake-PNG-HD.png │ ├── Snake-PNG-Picture.png │ ├── Snake-PNG.png │ ├── Snake.gif │ ├── blankdice.png │ ├── blue_circle.png │ ├── dice1.png │ ├── dice2.png │ ├── dice3.png │ ├── dice4.png │ ├── dice5.png │ ├── dice6.png │ ├── green_circle.png │ ├── index.jpg │ ├── index1.jpg │ ├── index2.jpg │ ├── index3.jpg │ ├── index4.jpg │ ├── index5.jpg │ ├── index6.jpg │ ├── index7.jpg │ ├── kisspng-sketch-snake-u86c7u738b-coral-reef-snakes-orange-creative-snake-5a90adfe3cf9a5.8576785615194311662498.png │ ├── kisspng-snake-vipers-encapsulated-postscript-computer-icon-anaconda-5ac5a86a353fd6.1808144115229031462181.jpg │ ├── snake-png-image-3654-414.png │ ├── snake-png-image-picture-download-png-image-200.png │ ├── snake-png-image-picture-download-png-image-3052.png │ ├── snake.png │ └── snake_png_3_by_paradise234-d5e4bke.png │ └── music │ ├── Amelie- La Valse D' Amelie.mp3 │ ├── Amelie- La Valse des Vieux Os.mp3 │ ├── Comptine d'un autre ete _ L'apres midi.mp3 │ ├── La noyée - Yann Tiersen.mp3 │ ├── Soir de fête - Yann Tiersen [HQ].mp3 │ ├── Yann Thiersen - Guilty.mp3 │ ├── Yann Tiersen - La Plage.mp3 │ ├── Yann Tiersen - La Veillée.mp3 │ └── Yann Tiersen - Le Banquet.mp3 └── src ├── GameBoard └── GameBoard.java ├── GameGUI ├── GameGUI.java ├── Main.java ├── PlayAgainOrExitAlert.java ├── PlayAgainOrExitPanel.fxml └── SnakesAndLadders.fxml ├── ObjectControllers └── PlayerController.java ├── POJO ├── ComputerPlayer.java ├── HumanPlayer.java ├── Piece.java ├── Player.java └── Tile.java └── enums ├── GameMode.java ├── GameVariation.java ├── PlayerType.java └── TileContainer.java /README.md: -------------------------------------------------------------------------------- 1 | # ► READ ME 2 | 3 | Game preview screenshot: http://prntscr.com/kkk7ad 4 | 5 | Here is some information about the game: https://en.wikipedia.org/wiki/Snakes_and_Ladders 6 | 7 | 8 | # How to run my application 9 | 10 | - Go to my releases (https://github.com/Tressos-Aristomenis/Snakes-And-Ladders-JavaFX-from-scratch/releases). 11 | - Go to my latest release. 12 | - Download the .zip file. 13 | - Unzip and run the .jar file that is inside. 14 | - Enjoy and star my repository if you enjoyed it! 15 | 16 | 17 | # Game Variations: 18 | - CLASSIC 19 | 20 | The standard rules of the game mention that if the dice roll is too large, you go to the final square and back again. 21 | Eg. Say you currently are at 98. If you hit 3 you should go 98 + 3 = 101, which is too large so you land 1 square before the final one. 22 | 23 | - Aristomenis 24 | 25 | This is my edition. The only change is that when your dice roll is too large, you start from the begin. 26 | Eg. Say you are at 99, if you hit 5 you should go 99 + 5 = 104, which is too large so you land at square 4. 27 | 28 | Warning: This edition is extremely disturbing after some time. 29 | 30 | 31 | # Features 32 | - I have added some background music of one of my favourite artists, "Yann Tiersen". You can always pause or mute if you dislike it. 33 | "music" folder contains all the tracks. 34 | - You can play either against computer or against a human. 35 | 36 | 37 | # // TO-DO: 38 | 39 | - ✔ Add a volume slider. 40 | - ✔ Fix potential bug when last square is reached (Show-and-wait and PauseTransition don't work well together). 41 | - Make it resizable for multiple screens. 42 | -------------------------------------------------------------------------------- /SnakesAndLaddersClassDiagram.uxf: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | 3 | 4 | // Uncomment the following line to change the fontsize and font: 5 | fontsize=10 6 | // fontfamily=SansSerif //possible: SansSerif,Serif,Monospaced 7 | 8 | 9 | ////////////////////////////////////////////////////////////////////////////////////////////// 10 | // Welcome to UMLet! 11 | // 12 | // Double-click on elements to add them to the diagram, or to copy them 13 | // Edit elements by modifying the text in this panel 14 | // Hold Ctrl to select multiple elements 15 | // Use Ctrl+mouse to select via lasso 16 | // 17 | // Use +/- or Ctrl+mouse wheel to zoom 18 | // Drag a whole relation at its central square icon 19 | // 20 | // Press Ctrl+C to copy the whole diagram to the system clipboard (then just paste it to, eg, Word) 21 | // Edit the files in the "palettes" directory to create your own element palettes 22 | // 23 | // Select "Custom Elements > New..." to create new element types 24 | ////////////////////////////////////////////////////////////////////////////////////////////// 25 | 26 | 27 | // This text will be stored with each diagram; use it for notes. 28 | 9 29 | 30 | UMLClass 31 | 32 | 729 33 | 27 34 | 189 35 | 108 36 | 37 | Piece 38 | -- 39 | - color: String 40 | - position: Integer 41 | - pieceImage: ImageView 42 | -- 43 | + Setters 44 | + Getters 45 | 46 | 47 | 48 | UMLClass 49 | 50 | 828 51 | 333 52 | 189 53 | 108 54 | 55 | Tile 56 | -- 57 | - position: Integer 58 | - tileContainer: TileContainer 59 | -- 60 | + Setters 61 | + Getters 62 | + containsLadderOrSnake() 63 | 64 | 65 | 66 | 67 | UMLClass 68 | 69 | 108 70 | 486 71 | 360 72 | 198 73 | 74 | GameBoard 75 | -- 76 | - delays, rows and columns number. 77 | - tiles: Tile[] 78 | - player1, player2: Player 79 | - SNAKES: Map<Integer, Integer> 80 | - LADDERS: Map<Integer, Integer> 81 | -- 82 | + getUpdatedPosition(currentPosition: Integer): Integer 83 | + getBoardCoordinates(newIndex: Integer): int[] 84 | + set/getPlayer1() 85 | + set/getPlayer2() 86 | + getCurrentPlayer() 87 | + getTile(index: Integer): Tile 88 | + playAgainOrExit(): Boolean 89 | + rollDice(): Integer 90 | - initializeTiles() 91 | - initializeSnakesAndLaddersPositions() 92 | 93 | 94 | 95 | UMLClass 96 | 97 | 9 98 | 171 99 | 261 100 | 90 101 | 102 | Computer Player 103 | -- 104 | + getPlayerType(): PlayerType.COMPUTER 105 | 106 | 107 | 108 | 109 | UMLClass 110 | 111 | 729 112 | 171 113 | 234 114 | 90 115 | 116 | Human Player 117 | -- 118 | + getPlayerType(): PlayerType.HUMAN 119 | 120 | 121 | 122 | UMLClass 123 | 124 | 405 125 | 162 126 | 189 127 | 117 128 | 129 | /Player/ 130 | -- 131 | - turn: Integer 132 | - playerPiece: Piece 133 | -- 134 | + Setters 135 | + Getters 136 | + getPlayerType() 137 | + toString() 138 | 139 | 140 | 141 | UMLClass 142 | 143 | 594 144 | 639 145 | 216 146 | 162 147 | 148 | GameGUI 149 | -- 150 | - gameBoard: GameBoard 151 | - gameMode: GameMode 152 | - playerController: PlayerController 153 | - FXML stuff 154 | _- MY_MEDIA_PLAYER: MediaPlayer_ 155 | - Media Player stuff 156 | - Paths for images, styles etc. 157 | -- 158 | + onDiceClick() 159 | + updateScore() 160 | + choosePieceImage() 161 | + aboutMediaPlayer() 162 | 163 | 164 | 165 | UMLNote 166 | 167 | 990 168 | 684 169 | 261 170 | 126 171 | 172 | updates the GUI, 173 | controller. 174 | 175 | At initialize: gameBoard = 176 | = new GameBoard(gameGrid: GridPane) 177 | 178 | Creates instance for PlayerImplementation. 179 | bg=green 180 | 181 | 182 | 183 | Relation 184 | 185 | 801 186 | 702 187 | 207 188 | 27 189 | 190 | lt=- 191 | 10.0;10.0;210.0;10.0 192 | 193 | 194 | Relation 195 | 196 | 261 197 | 207 198 | 162 199 | 27 200 | 201 | lt=<<<<- 202 | 160.0;10.0;10.0;10.0 203 | 204 | 205 | Relation 206 | 207 | 585 208 | 207 209 | 162 210 | 27 211 | 212 | lt=<<<<- 213 | 10.0;10.0;160.0;10.0 214 | 215 | 216 | UMLClass 217 | 218 | 396 219 | 45 220 | 207 221 | 72 222 | 223 | <<enumeration>> 224 | PlayerType 225 | -- 226 | HUMAN, COMPUTER 227 | 228 | 229 | 230 | UMLClass 231 | 232 | 1134 233 | 351 234 | 189 235 | 63 236 | 237 | <<enumeration>> 238 | TileContainer 239 | -- 240 | NONE, LADDER, SNAKE 241 | 242 | 243 | 244 | UMLClass 245 | 246 | 495 247 | 315 248 | 216 249 | 108 250 | 251 | PlayerController 252 | -- 253 | - gameGUI: GameGUI 254 | - gameBoard: GameBoard 255 | -- 256 | + rollTheDiceAndMove() 257 | + move(new_index) 258 | + getPlayerIndexAfterRoll(diceRoll: Integer): Integer 259 | + isComputerTurn(): Boolean 260 | + swapTurns() 261 | 262 | 263 | 264 | UMLNote 265 | 266 | 990 267 | 630 268 | 261 269 | 36 270 | 271 | onPieceChoose() - creates 2 players 272 | bg=green 273 | 274 | 275 | 276 | Relation 277 | 278 | 801 279 | 639 280 | 207 281 | 27 282 | 283 | lt=- 284 | 10.0;10.0;210.0;10.0 285 | 286 | 287 | UMLClass 288 | 289 | 756 290 | 504 291 | 189 292 | 63 293 | 294 | <<enumeration>> 295 | GameMode 296 | -- 297 | AGAINST_HUMAN, AGAINST_COMPUTER 298 | 299 | 300 | 301 | Relation 302 | 303 | 486 304 | 108 305 | 27 306 | 72 307 | 308 | lt=- 309 | 10.0;10.0;10.0;60.0 310 | 311 | 312 | Relation 313 | 314 | 1008 315 | 378 316 | 144 317 | 27 318 | 319 | lt=- 320 | 140.0;10.0;10.0;10.0 321 | 322 | 323 | Relation 324 | 325 | 783 326 | 558 327 | 27 328 | 99 329 | 330 | lt=- 331 | 10.0;10.0;10.0;90.0 332 | 333 | 334 | Relation 335 | 336 | 585 337 | 72 338 | 162 339 | 108 340 | 341 | lt=- 342 | m1= 1 343 | m2= 1 344 | has 345 | 10.0;100.0;160.0;10.0 346 | 347 | 348 | Relation 349 | 350 | 594 351 | 414 352 | 54 353 | 243 354 | 355 | lt=- 356 | m1= 1 357 | m2= 1 358 | updates 359 | 10.0;10.0;10.0;250.0 360 | 361 | 362 | Relation 363 | 364 | 909 365 | 63 366 | 117 367 | 288 368 | 369 | lt=- 370 | m1= 1 371 | m2= 1 372 | < contains 373 | 10.0;20.0;110.0;20.0;110.0;300.0 374 | 375 | 376 | Relation 377 | 378 | 450 379 | 675 380 | 162 381 | 63 382 | 383 | lt=- 384 | m1= 1 385 | m2= 1 386 | 387 | 388 | 389 | 390 | < consists of 391 | 10.0;10.0;10.0;50.0;160.0;50.0 392 | 393 | 394 | Relation 395 | 396 | 207 397 | 270 398 | 216 399 | 234 400 | 401 | lt=- 402 | m1= 1 403 | m2= 2 404 | contains > 405 | 10.0;240.0;220.0;10.0 406 | 407 | 408 | UMLClass 409 | 410 | 63 411 | 315 412 | 189 413 | 63 414 | 415 | <<enumeration>> 416 | GameVariation 417 | -- 418 | CLASSIC, ARISTOMENIS 419 | 420 | 421 | 422 | Relation 423 | 424 | 144 425 | 369 426 | 27 427 | 135 428 | 429 | lt=- 430 | 10.0;10.0;10.0;130.0 431 | 432 | 433 | Relation 434 | 435 | 459 436 | 414 437 | 144 438 | 180 439 | 440 | lt=- 441 | m1= 1 442 | m2= 1 443 | has direct access 444 | to game board 445 | 120.0;10.0;10.0;180.0 446 | 447 | 448 | ======= 449 | 450 | 451 | // Uncomment the following line to change the fontsize and font: 452 | fontsize=10 453 | // fontfamily=SansSerif //possible: SansSerif,Serif,Monospaced 454 | 455 | 456 | ////////////////////////////////////////////////////////////////////////////////////////////// 457 | // Welcome to UMLet! 458 | // 459 | // Double-click on elements to add them to the diagram, or to copy them 460 | // Edit elements by modifying the text in this panel 461 | // Hold Ctrl to select multiple elements 462 | // Use Ctrl+mouse to select via lasso 463 | // 464 | // Use +/- or Ctrl+mouse wheel to zoom 465 | // Drag a whole relation at its central square icon 466 | // 467 | // Press Ctrl+C to copy the whole diagram to the system clipboard (then just paste it to, eg, Word) 468 | // Edit the files in the "palettes" directory to create your own element palettes 469 | // 470 | // Select "Custom Elements > New..." to create new element types 471 | ////////////////////////////////////////////////////////////////////////////////////////////// 472 | 473 | 474 | // This text will be stored with each diagram; use it for notes. 475 | 9 476 | 477 | UMLClass 478 | 479 | 729 480 | 27 481 | 189 482 | 108 483 | 484 | Piece 485 | -- 486 | - color: String 487 | - position: Integer 488 | - pieceImage: ImageView 489 | -- 490 | + Setters 491 | + Getters 492 | 493 | 494 | 495 | UMLClass 496 | 497 | 828 498 | 333 499 | 189 500 | 108 501 | 502 | Tile 503 | -- 504 | - position: Integer 505 | - tileContainer: TileContainer 506 | -- 507 | + Setters 508 | + Getters 509 | + containsLadderOrSnake() 510 | 511 | 512 | 513 | 514 | UMLClass 515 | 516 | 108 517 | 486 518 | 360 519 | 198 520 | 521 | GameBoard 522 | -- 523 | - delays, rows and columns number. 524 | - tiles: Tile[] 525 | - player1, player2: Player 526 | - SNAKES: Map<Integer, Integer> 527 | - LADDERS: Map<Integer, Integer> 528 | -- 529 | + getUpdatedPosition(currentPosition: Integer): Integer 530 | + getBoardCoordinates(newIndex: Integer): int[] 531 | + set/getPlayer1() 532 | + set/getPlayer2() 533 | + getCurrentPlayer() 534 | + getTile(index: Integer): Tile 535 | + playAgainOrExit(): Boolean 536 | + rollDice(): Integer 537 | - initializeTiles() 538 | - initializeSnakesAndLaddersPositions() 539 | 540 | 541 | 542 | UMLClass 543 | 544 | 9 545 | 171 546 | 261 547 | 90 548 | 549 | Computer Player 550 | -- 551 | + getPlayerType(): PlayerType.COMPUTER 552 | 553 | 554 | 555 | 556 | UMLClass 557 | 558 | 729 559 | 171 560 | 234 561 | 90 562 | 563 | Human Player 564 | -- 565 | + getPlayerType(): PlayerType.HUMAN 566 | 567 | 568 | 569 | UMLClass 570 | 571 | 405 572 | 162 573 | 189 574 | 117 575 | 576 | /Player/ 577 | -- 578 | - turn: Integer 579 | - playerPiece: Piece 580 | -- 581 | + Setters 582 | + Getters 583 | + getPlayerType() 584 | + toString() 585 | 586 | 587 | 588 | UMLClass 589 | 590 | 594 591 | 639 592 | 216 593 | 162 594 | 595 | GameGUI 596 | -- 597 | - gameBoard: GameBoard 598 | - gameMode: GameMode 599 | - playerController: PlayerController 600 | - FXML stuff 601 | _- MY_MEDIA_PLAYER: MediaPlayer_ 602 | - Media Player stuff 603 | - Paths for images, styles etc. 604 | -- 605 | + onDiceClick() 606 | + updateScore() 607 | + choosePieceImage() 608 | + aboutMediaPlayer() 609 | 610 | 611 | 612 | UMLNote 613 | 614 | 990 615 | 684 616 | 261 617 | 126 618 | 619 | updates the GUI, 620 | controller. 621 | 622 | At initialize: gameBoard = 623 | = new GameBoard(gameGrid: GridPane) 624 | 625 | Creates instance for PlayerImplementation. 626 | bg=green 627 | 628 | 629 | 630 | Relation 631 | 632 | 801 633 | 702 634 | 207 635 | 27 636 | 637 | lt=- 638 | 10.0;10.0;210.0;10.0 639 | 640 | 641 | Relation 642 | 643 | 261 644 | 207 645 | 162 646 | 27 647 | 648 | lt=<<<<- 649 | 160.0;10.0;10.0;10.0 650 | 651 | 652 | Relation 653 | 654 | 585 655 | 207 656 | 162 657 | 27 658 | 659 | lt=<<<<- 660 | 10.0;10.0;160.0;10.0 661 | 662 | 663 | UMLClass 664 | 665 | 396 666 | 45 667 | 207 668 | 72 669 | 670 | <<enumeration>> 671 | PlayerType 672 | -- 673 | HUMAN, COMPUTER 674 | 675 | 676 | 677 | UMLClass 678 | 679 | 1134 680 | 351 681 | 189 682 | 63 683 | 684 | <<enumeration>> 685 | TileContainer 686 | -- 687 | NONE, LADDER, SNAKE 688 | 689 | 690 | 691 | UMLClass 692 | 693 | 495 694 | 315 695 | 216 696 | 108 697 | 698 | PlayerController 699 | -- 700 | - gameGUI: GameGUI 701 | - gameBoard: GameBoard 702 | -- 703 | + rollTheDiceAndMove() 704 | + move(new_index) 705 | + getPlayerIndexAfterRoll(diceRoll: Integer): Integer 706 | + isComputerTurn(): Boolean 707 | + swapTurns() 708 | 709 | 710 | 711 | UMLNote 712 | 713 | 990 714 | 630 715 | 261 716 | 36 717 | 718 | onPieceChoose() - creates 2 players 719 | bg=green 720 | 721 | 722 | 723 | Relation 724 | 725 | 801 726 | 639 727 | 207 728 | 27 729 | 730 | lt=- 731 | 10.0;10.0;210.0;10.0 732 | 733 | 734 | UMLClass 735 | 736 | 756 737 | 504 738 | 189 739 | 63 740 | 741 | <<enumeration>> 742 | GameMode 743 | -- 744 | AGAINST_HUMAN, AGAINST_COMPUTER 745 | 746 | 747 | 748 | Relation 749 | 750 | 486 751 | 108 752 | 27 753 | 72 754 | 755 | lt=- 756 | 10.0;10.0;10.0;60.0 757 | 758 | 759 | Relation 760 | 761 | 1008 762 | 378 763 | 144 764 | 27 765 | 766 | lt=- 767 | 140.0;10.0;10.0;10.0 768 | 769 | 770 | Relation 771 | 772 | 783 773 | 558 774 | 27 775 | 99 776 | 777 | lt=- 778 | 10.0;10.0;10.0;90.0 779 | 780 | 781 | Relation 782 | 783 | 585 784 | 72 785 | 162 786 | 108 787 | 788 | lt=- 789 | m1= 1 790 | m2= 1 791 | has 792 | 10.0;100.0;160.0;10.0 793 | 794 | 795 | Relation 796 | 797 | 594 798 | 414 799 | 54 800 | 243 801 | 802 | lt=- 803 | m1= 1 804 | m2= 1 805 | updates 806 | 10.0;10.0;10.0;250.0 807 | 808 | 809 | Relation 810 | 811 | 909 812 | 63 813 | 117 814 | 288 815 | 816 | lt=- 817 | m1= 1 818 | m2= 1 819 | < contains 820 | 10.0;20.0;110.0;20.0;110.0;300.0 821 | 822 | 823 | Relation 824 | 825 | 450 826 | 675 827 | 162 828 | 63 829 | 830 | lt=- 831 | m1= 1 832 | m2= 1 833 | 834 | 835 | 836 | 837 | < consists of 838 | 10.0;10.0;10.0;50.0;160.0;50.0 839 | 840 | 841 | Relation 842 | 843 | 207 844 | 270 845 | 216 846 | 234 847 | 848 | lt=- 849 | m1= 1 850 | m2= 2 851 | contains > 852 | 10.0;240.0;220.0;10.0 853 | 854 | 855 | UMLClass 856 | 857 | 63 858 | 315 859 | 189 860 | 63 861 | 862 | <<enumeration>> 863 | GameVariation 864 | -- 865 | CLASSIC, ARISTOMENIS 866 | 867 | 868 | 869 | Relation 870 | 871 | 144 872 | 369 873 | 27 874 | 135 875 | 876 | lt=- 877 | 10.0;10.0;10.0;130.0 878 | 879 | 880 | Relation 881 | 882 | 459 883 | 414 884 | 144 885 | 180 886 | 887 | lt=- 888 | m1= 1 889 | m2= 1 890 | has direct access 891 | to game board 892 | 120.0;10.0;10.0;180.0 893 | 894 | 895 | >>>>>>> be0b7b730ce763f6f2650a3c23988a012dae4b6b 896 | -------------------------------------------------------------------------------- /resources/Res/ResourceLoader.java: -------------------------------------------------------------------------------- 1 | package Res; 2 | 3 | import java.io.File; 4 | import javafx.scene.image.Image; 5 | 6 | /** 7 | * 8 | * @author Aris 9 | */ 10 | public class ResourceLoader { 11 | static ResourceLoader resourceLoader = new ResourceLoader(); 12 | static File TRACKS_DIRECTORY; 13 | public static File[] TRACKLIST; 14 | 15 | ResourceLoader() { 16 | TRACKS_DIRECTORY = new File("./resources/Res/music"); 17 | TRACKLIST = getTracklist(); 18 | } 19 | 20 | public static Image getImage(String filename) { 21 | return new Image(resourceLoader.getClass().getClassLoader().getResource("Res/images/" + filename).toString()); 22 | } 23 | 24 | public static String getTrack(int track_num) { 25 | String trackDirectory = TRACKLIST[track_num].toString(); 26 | String trackname = trackDirectory.substring(trackDirectory.lastIndexOf("\\") + 1, trackDirectory.length()); 27 | 28 | return resourceLoader.getClass().getClassLoader().getResource("Res/music/" + trackname).toString(); 29 | } 30 | 31 | private static File[] getTracklist() { 32 | return TRACKS_DIRECTORY.listFiles(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /resources/Res/images/Anaconda-PNG-Image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Anaconda-PNG-Image.png -------------------------------------------------------------------------------- /resources/Res/images/Dice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Dice.png -------------------------------------------------------------------------------- /resources/Res/images/Ladder-PNG-Image-45634.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Ladder-PNG-Image-45634.png -------------------------------------------------------------------------------- /resources/Res/images/Rose-Metal-Wallpaper-Wall-Mural-Rose-Gold-Metal-sheet-feature-wallpaper.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Rose-Metal-Wallpaper-Wall-Mural-Rose-Gold-Metal-sheet-feature-wallpaper.jpg -------------------------------------------------------------------------------- /resources/Res/images/Snake-PNG-HD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Snake-PNG-HD.png -------------------------------------------------------------------------------- /resources/Res/images/Snake-PNG-Picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Snake-PNG-Picture.png -------------------------------------------------------------------------------- /resources/Res/images/Snake-PNG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Snake-PNG.png -------------------------------------------------------------------------------- /resources/Res/images/Snake.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/Snake.gif -------------------------------------------------------------------------------- /resources/Res/images/blankdice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/blankdice.png -------------------------------------------------------------------------------- /resources/Res/images/blue_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/blue_circle.png -------------------------------------------------------------------------------- /resources/Res/images/dice1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/dice1.png -------------------------------------------------------------------------------- /resources/Res/images/dice2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/dice2.png -------------------------------------------------------------------------------- /resources/Res/images/dice3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/dice3.png -------------------------------------------------------------------------------- /resources/Res/images/dice4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/dice4.png -------------------------------------------------------------------------------- /resources/Res/images/dice5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/dice5.png -------------------------------------------------------------------------------- /resources/Res/images/dice6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/dice6.png -------------------------------------------------------------------------------- /resources/Res/images/green_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/green_circle.png -------------------------------------------------------------------------------- /resources/Res/images/index.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index.jpg -------------------------------------------------------------------------------- /resources/Res/images/index1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index1.jpg -------------------------------------------------------------------------------- /resources/Res/images/index2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index2.jpg -------------------------------------------------------------------------------- /resources/Res/images/index3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index3.jpg -------------------------------------------------------------------------------- /resources/Res/images/index4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index4.jpg -------------------------------------------------------------------------------- /resources/Res/images/index5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index5.jpg -------------------------------------------------------------------------------- /resources/Res/images/index6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index6.jpg -------------------------------------------------------------------------------- /resources/Res/images/index7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/index7.jpg -------------------------------------------------------------------------------- /resources/Res/images/kisspng-sketch-snake-u86c7u738b-coral-reef-snakes-orange-creative-snake-5a90adfe3cf9a5.8576785615194311662498.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/kisspng-sketch-snake-u86c7u738b-coral-reef-snakes-orange-creative-snake-5a90adfe3cf9a5.8576785615194311662498.png -------------------------------------------------------------------------------- /resources/Res/images/kisspng-snake-vipers-encapsulated-postscript-computer-icon-anaconda-5ac5a86a353fd6.1808144115229031462181.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/kisspng-snake-vipers-encapsulated-postscript-computer-icon-anaconda-5ac5a86a353fd6.1808144115229031462181.jpg -------------------------------------------------------------------------------- /resources/Res/images/snake-png-image-3654-414.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/snake-png-image-3654-414.png -------------------------------------------------------------------------------- /resources/Res/images/snake-png-image-picture-download-png-image-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/snake-png-image-picture-download-png-image-200.png -------------------------------------------------------------------------------- /resources/Res/images/snake-png-image-picture-download-png-image-3052.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/snake-png-image-picture-download-png-image-3052.png -------------------------------------------------------------------------------- /resources/Res/images/snake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/snake.png -------------------------------------------------------------------------------- /resources/Res/images/snake_png_3_by_paradise234-d5e4bke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/images/snake_png_3_by_paradise234-d5e4bke.png -------------------------------------------------------------------------------- /resources/Res/music/Amelie- La Valse D' Amelie.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Amelie- La Valse D' Amelie.mp3 -------------------------------------------------------------------------------- /resources/Res/music/Amelie- La Valse des Vieux Os.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Amelie- La Valse des Vieux Os.mp3 -------------------------------------------------------------------------------- /resources/Res/music/Comptine d'un autre ete _ L'apres midi.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Comptine d'un autre ete _ L'apres midi.mp3 -------------------------------------------------------------------------------- /resources/Res/music/La noyée - Yann Tiersen.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/La noyée - Yann Tiersen.mp3 -------------------------------------------------------------------------------- /resources/Res/music/Soir de fête - Yann Tiersen [HQ].mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Soir de fête - Yann Tiersen [HQ].mp3 -------------------------------------------------------------------------------- /resources/Res/music/Yann Thiersen - Guilty.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Yann Thiersen - Guilty.mp3 -------------------------------------------------------------------------------- /resources/Res/music/Yann Tiersen - La Plage.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Yann Tiersen - La Plage.mp3 -------------------------------------------------------------------------------- /resources/Res/music/Yann Tiersen - La Veillée.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Yann Tiersen - La Veillée.mp3 -------------------------------------------------------------------------------- /resources/Res/music/Yann Tiersen - Le Banquet.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasti37/Snakes-And-Ladders-JavaFX-from-scratch/97216861d51349201da6a662ca428fe8292452c4/resources/Res/music/Yann Tiersen - Le Banquet.mp3 -------------------------------------------------------------------------------- /src/GameBoard/GameBoard.java: -------------------------------------------------------------------------------- 1 | package GameBoard; 2 | 3 | import POJO.Player; 4 | import POJO.Tile; 5 | import enums.TileContainer; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.Random; 9 | 10 | /** 11 | * 12 | * @author Aris 13 | */ 14 | public class GameBoard { 15 | public static final int ROWS = 10; 16 | public static final int COLS = 10; 17 | public static final int NUMBER_OF_TILES = ROWS * COLS; 18 | public static final int WIN_POINT = 100; 19 | public static final int DICE_ROLL_DELAY = 1; 20 | public static final int COMPUTER_MOVE_DELAY = 2; 21 | public static final int PLAYER_STARTING_POSITION = 0; 22 | 23 | private Tile[] tiles; 24 | private Player player1, player2; 25 | private Map SNAKES; 26 | private Map LADDERS; 27 | 28 | public GameBoard() { 29 | initializeSNAKESandLADDERSPositions(); 30 | initializeTiles(); 31 | } 32 | 33 | private void initializeTiles() { 34 | tiles = new Tile[NUMBER_OF_TILES]; 35 | 36 | for (int i = 0; i < tiles.length; i++) { 37 | if (SNAKES.containsKey(i)) { 38 | tiles[i] = new Tile(i, TileContainer.SNAKE); 39 | } else if (LADDERS.containsKey(i)) { 40 | tiles[i] = new Tile(i, TileContainer.LADDER); 41 | } else { 42 | tiles[i] = new Tile(i, TileContainer.NONE); 43 | } 44 | } 45 | } 46 | 47 | private void initializeSNAKESandLADDERSPositions() { 48 | SNAKES = new HashMap<>(); 49 | LADDERS = new HashMap<>(); 50 | 51 | SNAKES.put(19, 6); 52 | SNAKES.put(42, 17); 53 | SNAKES.put(49, 16); 54 | SNAKES.put(58, 45); 55 | SNAKES.put(61, 22); 56 | SNAKES.put(75, 47); 57 | SNAKES.put(88, 36); 58 | SNAKES.put(94, 70); 59 | SNAKES.put(97, 65); 60 | LADDERS.put(3, 37); 61 | LADDERS.put(7, 13); 62 | LADDERS.put(14, 32); 63 | LADDERS.put(27, 56); 64 | LADDERS.put(39, 44); 65 | LADDERS.put(41, 85); 66 | LADDERS.put(69, 87); 67 | LADDERS.put(79, 98); 68 | LADDERS.put(89, 91); 69 | } 70 | 71 | public int getUpdatedPosition(int currentIndex) { 72 | int updatedIndex = -1; 73 | 74 | if (SNAKES.containsKey(currentIndex)) { 75 | updatedIndex = SNAKES.get(currentIndex); 76 | } else if (LADDERS.containsKey(currentIndex)) { 77 | updatedIndex = LADDERS.get(currentIndex); 78 | } 79 | 80 | return updatedIndex; 81 | } 82 | 83 | public int[] getBoardCoordinates(int newIndex) { 84 | int row = newIndex / ROWS; // ROWS - 1 - newIndex / ROWS if I don't send rows*cols - newIndex 85 | int column = newIndex % COLS; 86 | 87 | if (row % 2 == 1) { // If I don't want to send ROW * COLS - newIndex, the condition will be row % 2 == 0 88 | column = COLS - 1 - column; 89 | } 90 | 91 | return new int[] {row, column}; 92 | } 93 | 94 | public int rollDice() { 95 | final int MIN = 1; 96 | final int MAX = 6; 97 | 98 | return new Random().nextInt((MAX - MIN) + 1) + MIN; 99 | } 100 | 101 | public Player getCurrentPlayer() { 102 | Player currentPlayer = null; 103 | 104 | if (player1.getTurn() == 1) { 105 | currentPlayer = player1; 106 | } else if (player2.getTurn() == 1) { 107 | currentPlayer = player2; 108 | } 109 | 110 | return currentPlayer; 111 | } 112 | 113 | public Tile getTile(int index) { 114 | return tiles[index]; 115 | } 116 | 117 | public Player getPlayer1() { 118 | return player1; 119 | } 120 | 121 | public void setPlayer1(Player player1) { 122 | this.player1 = player1; 123 | } 124 | 125 | public Player getPlayer2() { 126 | return player2; 127 | } 128 | 129 | public void setPlayer2(Player player2) { 130 | this.player2 = player2; 131 | } 132 | } -------------------------------------------------------------------------------- /src/GameGUI/GameGUI.java: -------------------------------------------------------------------------------- 1 | package GameGUI; 2 | 3 | import GameBoard.GameBoard; 4 | import ObjectControllers.PlayerController; 5 | import POJO.ComputerPlayer; 6 | import POJO.HumanPlayer; 7 | import POJO.Piece; 8 | import POJO.Player; 9 | import Res.ResourceLoader; 10 | import enums.GameMode; 11 | import enums.GameVariation; 12 | import java.io.IOException; 13 | import java.net.URL; 14 | import java.util.Random; 15 | import java.util.ResourceBundle; 16 | import javafx.beans.InvalidationListener; 17 | import javafx.beans.Observable; 18 | import javafx.collections.ObservableList; 19 | import javafx.fxml.FXML; 20 | import javafx.fxml.FXMLLoader; 21 | import javafx.fxml.Initializable; 22 | import javafx.scene.Node; 23 | import javafx.scene.Parent; 24 | import javafx.scene.Scene; 25 | import javafx.scene.control.Alert; 26 | import javafx.scene.control.Button; 27 | import javafx.scene.control.Label; 28 | import javafx.scene.control.Slider; 29 | import javafx.scene.image.Image; 30 | import javafx.scene.image.ImageView; 31 | import javafx.scene.input.MouseEvent; 32 | import javafx.scene.layout.GridPane; 33 | import javafx.scene.layout.Pane; 34 | import javafx.scene.media.Media; 35 | import javafx.scene.media.MediaPlayer; 36 | import javafx.stage.Stage; 37 | 38 | /** 39 | * 40 | * @author Aris 41 | */ 42 | 43 | public class GameGUI implements Initializable { 44 | @FXML 45 | private GridPane gameGrid; 46 | 47 | @FXML 48 | private Slider volumeSlider; 49 | 50 | @FXML 51 | private Label nowPlayingLabel; 52 | 53 | @FXML 54 | private Label currentTurnLabel; 55 | 56 | @FXML 57 | private Button rollTheDiceBtn; 58 | 59 | @FXML 60 | private Label numberRolledLabel; 61 | 62 | @FXML 63 | private ImageView diceIndicatorImage; 64 | 65 | @FXML 66 | private Button againstHumanBtn; 67 | 68 | @FXML 69 | private Button againstComputerBtn; 70 | 71 | @FXML 72 | private Label myScore; 73 | 74 | @FXML 75 | private Label enemyScore; 76 | 77 | @FXML 78 | private ImageView chooseBluePieceImage; 79 | 80 | @FXML 81 | private ImageView chooseGreenPieceImage; 82 | 83 | @FXML 84 | private Button classicVariation; 85 | 86 | @FXML 87 | private Button aristosVariation; 88 | 89 | public static final String SNAKE_OR_LADDER_HIT_CELL_STYLE = "-fx-background-color: #FFDF00"; 90 | private final String DEFAULT_TILE_STYLE = "-fx-background-color: #228b22"; 91 | private final Image BLUE_PIECE_IMAGE = ResourceLoader.getImage("blue_circle.png"); 92 | private final Image GREEN_PIECE_IMAGE = ResourceLoader.getImage("green_circle.png"); 93 | private final Image ROLL_THE_DICE_IMAGE = ResourceLoader.getImage("Dice.png"); 94 | private final double DEFAULT_STARTING_VOLUME = 0.35; 95 | 96 | private ImageView inGameBluePieceImage, inGameGreenPieceImage; 97 | private GameBoard gameBoard; 98 | private GameVariation gameVariation; 99 | private GameMode gameMode; 100 | private PlayerController playerController; 101 | private static MediaPlayer MY_MEDIA_PLAYER; 102 | private Media currentTrack = null; 103 | 104 | 105 | @Override 106 | public void initialize(URL url, ResourceBundle rb) { 107 | try { 108 | initializeStatus(); 109 | } catch (Exception e) { 110 | e.printStackTrace(); 111 | reportError(e.toString()); 112 | } 113 | } 114 | 115 | private void initializeStatus() { 116 | colorTiles(); 117 | gameBoard = new GameBoard(); 118 | playerController = new PlayerController(this, gameBoard); 119 | gameMode = GameMode.AGAINST_HUMAN; 120 | gameVariation = GameVariation.CLASSIC; 121 | 122 | inGameBluePieceImage = new ImageView(BLUE_PIECE_IMAGE); 123 | inGameGreenPieceImage = new ImageView(GREEN_PIECE_IMAGE); 124 | rollTheDiceBtn.setGraphic(new ImageView(ROLL_THE_DICE_IMAGE)); 125 | 126 | againstHumanBtn.setOnAction(ev -> { 127 | gameMode = GameMode.AGAINST_HUMAN; 128 | startNewGame(); 129 | }); 130 | againstComputerBtn.setOnAction(ev -> { 131 | gameMode = GameMode.AGAINST_COMPUTER; 132 | startNewGame(); 133 | }); 134 | classicVariation.setOnAction(ev -> { 135 | gameVariation = GameVariation.CLASSIC; 136 | startNewGame(); 137 | }); 138 | aristosVariation.setOnAction(ev -> { 139 | gameVariation = GameVariation.ARISTOMENIS; 140 | startNewGame(); 141 | }); 142 | 143 | initializeMediaPlayer(); 144 | startNewGame(); 145 | } 146 | 147 | private void startNewGame() { 148 | nullifyPlayerStats(); 149 | removePiecesFromBoard(); 150 | resetAllTiles(); 151 | unlockPieceImages(); 152 | numberRolledLabel.setText("Game starting..."); 153 | diceIndicatorImage.setImage(ResourceLoader.getImage("blankdice.png")); 154 | currentTurnLabel.setText(""); 155 | lockDiceButton(); 156 | } 157 | 158 | public void playAgain() { 159 | removePiecesFromBoard(); 160 | resetAllTiles(); 161 | unlockPieceImages(); 162 | numberRolledLabel.setText("Game starting..."); 163 | diceIndicatorImage.setImage(ResourceLoader.getImage("blankdice.png")); 164 | currentTurnLabel.setText(""); 165 | lockDiceButton(); 166 | } 167 | 168 | @FXML 169 | public void onDiceClick() { 170 | playerController.rollDiceAndMove(); 171 | } 172 | 173 | @FXML 174 | public void choosePieceImage(MouseEvent event) { 175 | ImageView chosenImage = (ImageView) event.getSource(); 176 | 177 | final Piece bluePiece = new Piece(GameBoard.PLAYER_STARTING_POSITION, "Blue", inGameBluePieceImage); 178 | final Piece greenPiece = new Piece(GameBoard.PLAYER_STARTING_POSITION, "Green", inGameGreenPieceImage); 179 | 180 | Player player1 = null; 181 | Player player2 = null; 182 | 183 | if (chosenImage.equals(chooseBluePieceImage)) { 184 | player1 = new HumanPlayer(1, bluePiece); 185 | 186 | if (gameMode == GameMode.AGAINST_HUMAN) { 187 | player2 = new HumanPlayer(0, greenPiece); 188 | } else if (gameMode == GameMode.AGAINST_COMPUTER) { 189 | player2 = new ComputerPlayer(0, greenPiece); 190 | } 191 | } else if (chosenImage.equals(chooseGreenPieceImage)) { 192 | player1 = new HumanPlayer(1, greenPiece); 193 | 194 | if (gameMode == GameMode.AGAINST_HUMAN) { 195 | player2 = new HumanPlayer(0, bluePiece); 196 | } else if (gameMode == GameMode.AGAINST_COMPUTER) { 197 | player2 = new ComputerPlayer(0, bluePiece); 198 | } 199 | } 200 | 201 | gameBoard.setPlayer1(player1); 202 | gameBoard.setPlayer2(player2); 203 | 204 | lockPieceImages(); 205 | updateCurrentTurnLabel(); 206 | unlockDiceButton(); 207 | } 208 | 209 | 210 | public void initializeMediaPlayer() { 211 | int randomTrackNumber = new Random().nextInt((ResourceLoader.TRACKLIST.length -1 - 0) + 1) + 0; 212 | String track = ResourceLoader.getTrack(randomTrackNumber); 213 | currentTrack = new Media(track); 214 | 215 | MY_MEDIA_PLAYER = new MediaPlayer(currentTrack); 216 | MY_MEDIA_PLAYER.play(); 217 | MY_MEDIA_PLAYER.setVolume(DEFAULT_STARTING_VOLUME); 218 | 219 | volumeSlider.setValue(MY_MEDIA_PLAYER.getVolume() * 100); 220 | volumeSlider.valueProperty().addListener(new InvalidationListener() { 221 | @Override 222 | public void invalidated(Observable observable) { 223 | MY_MEDIA_PLAYER.setVolume(volumeSlider.getValue() / 100.0); 224 | } 225 | }); 226 | 227 | nowPlayingLabel.setText(ResourceLoader.TRACKLIST[randomTrackNumber].getName()); 228 | 229 | MY_MEDIA_PLAYER.setOnEndOfMedia(new Runnable() { 230 | @Override 231 | public void run() { 232 | playNextTrack(); 233 | } 234 | }); 235 | } 236 | 237 | @FXML 238 | public void resumeTrack() { 239 | MY_MEDIA_PLAYER.play(); 240 | } 241 | 242 | @FXML 243 | public void pauseTrack() { 244 | MY_MEDIA_PLAYER.pause(); 245 | } 246 | 247 | @FXML 248 | public void playNextTrack() { 249 | MY_MEDIA_PLAYER.stop(); // stop current media player. 250 | int randomTrackNumber = new Random().nextInt((ResourceLoader.TRACKLIST.length -1 - 0) + 1) + 0; 251 | String track = ResourceLoader.getTrack(randomTrackNumber); 252 | currentTrack = new Media(track); 253 | 254 | MY_MEDIA_PLAYER = new MediaPlayer(currentTrack); // create new media player with another track. 255 | MY_MEDIA_PLAYER.play(); 256 | MY_MEDIA_PLAYER.setVolume(volumeSlider.getValue() / 100.0); 257 | 258 | nowPlayingLabel.setText(ResourceLoader.TRACKLIST[randomTrackNumber].getName()); 259 | 260 | MY_MEDIA_PLAYER.setOnEndOfMedia(new Runnable() { 261 | @Override 262 | public void run() { 263 | playNextTrack(); 264 | } 265 | }); 266 | } 267 | 268 | public void updateScore(Player winner) { 269 | if (winner == gameBoard.getPlayer1()) { 270 | int newScore = Integer.parseInt(myScore.getText()) + 1; 271 | myScore.setText(String.valueOf(newScore)); 272 | } 273 | else if (winner == gameBoard.getPlayer2()) { 274 | int newScore = Integer.parseInt(enemyScore.getText()) + 1; 275 | enemyScore.setText(String.valueOf(newScore)); 276 | } 277 | } 278 | 279 | public void unlockDiceButton() { 280 | rollTheDiceBtn.setDisable(false); 281 | } 282 | 283 | public void lockDiceButton() { 284 | rollTheDiceBtn.setDisable(true); 285 | } 286 | 287 | private void unlockPieceImages() { 288 | chooseBluePieceImage.setDisable(false); 289 | chooseGreenPieceImage.setDisable(false); 290 | } 291 | 292 | private void lockPieceImages() { 293 | chooseBluePieceImage.setDisable(true); 294 | chooseGreenPieceImage.setDisable(true); 295 | } 296 | 297 | private void removePiecesFromBoard() { 298 | gameGrid.getChildren().remove(inGameBluePieceImage); 299 | gameGrid.getChildren().remove(inGameGreenPieceImage); 300 | } 301 | 302 | private void nullifyPlayerStats() { 303 | myScore.setText("0"); 304 | enemyScore.setText("0"); 305 | } 306 | 307 | public void movePieceImages(final int destinationRow, final int destinationColumn) { 308 | ImageView currentPieceImage = gameBoard.getCurrentPlayer().getPlayerPiece().getPieceImage(); 309 | gameGrid.getChildren().remove(currentPieceImage); 310 | gameGrid.add(currentPieceImage, destinationColumn, destinationRow); 311 | } 312 | 313 | private void colorTiles() { 314 | for (Node node : gameGrid.getChildren()) { 315 | ((Pane) node).setStyle(DEFAULT_TILE_STYLE); 316 | } 317 | } 318 | 319 | public void indicateDiceRoll(int diceRoll) { 320 | switch (diceRoll) { 321 | case 1: 322 | diceIndicatorImage.setImage(ResourceLoader.getImage("dice1.png")); 323 | break; 324 | case 2: 325 | diceIndicatorImage.setImage(ResourceLoader.getImage("dice2.png")); 326 | break; 327 | case 3: 328 | diceIndicatorImage.setImage(ResourceLoader.getImage("dice3.png")); 329 | break; 330 | case 4: 331 | diceIndicatorImage.setImage(ResourceLoader.getImage("dice4.png")); 332 | break; 333 | case 5: 334 | diceIndicatorImage.setImage(ResourceLoader.getImage("dice5.png")); 335 | break; 336 | case 6: 337 | diceIndicatorImage.setImage(ResourceLoader.getImage("dice6.png")); 338 | break; 339 | } 340 | 341 | numberRolledLabel.setText(gameBoard.getCurrentPlayer().getPlayerPiece().getColor() + " rolled: " + diceRoll); 342 | } 343 | 344 | public void updateCurrentTurnLabel() { 345 | currentTurnLabel.setText(gameBoard.getCurrentPlayer().getPlayerPiece().getColor().toUpperCase()); 346 | } 347 | 348 | public void resetAllTiles() { 349 | for (Node child : gameGrid.getChildren()) { 350 | if (child instanceof Pane) { 351 | child.setStyle(DEFAULT_TILE_STYLE); 352 | } 353 | } 354 | } 355 | 356 | public void setCellStyle(Pane clicked, String style) { 357 | clicked.setStyle(style); 358 | } 359 | 360 | public Node getNodeByRowColumnIndex(final int row, final int column) { 361 | Node result = null; 362 | ObservableList childrens = gameGrid.getChildren(); 363 | 364 | for (Node node : childrens) { 365 | if (GridPane.getRowIndex(node) == row && GridPane.getColumnIndex(node) == column) { 366 | result = node; 367 | break; 368 | } 369 | } 370 | 371 | return result; 372 | } 373 | 374 | public void gameOver() { 375 | Stage gameOverStage = new Stage(); 376 | Player winner = gameBoard.getCurrentPlayer(); 377 | Parent root = null; 378 | PlayAgainOrExitAlert playAgainOrExit = null; 379 | 380 | try { 381 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("PlayAgainOrExitPanel.fxml")); 382 | root = fxmlLoader.load(); 383 | playAgainOrExit = fxmlLoader.getController(); 384 | playAgainOrExit.setWinnerName(winner.getPlayerPiece().getColor().toUpperCase()); 385 | } catch (IOException ex) { 386 | ex.printStackTrace(); 387 | } 388 | 389 | gameOverStage.setTitle("Game over"); 390 | gameOverStage.setScene(new Scene(root)); 391 | gameOverStage.show(); 392 | gameOverStage.setAlwaysOnTop(true); 393 | 394 | gameOverStage.setOnCloseRequest(ev -> { 395 | playAgainOrNot(); 396 | }); 397 | } 398 | 399 | private void playAgainOrNot() { 400 | Player winner = gameBoard.getCurrentPlayer(); 401 | 402 | if (PlayAgainOrExitAlert.isRematch) { 403 | updateScore(winner); 404 | playAgain(); 405 | } else { 406 | System.exit(0); 407 | } 408 | } 409 | 410 | public void reportError(String exception) { 411 | Alert alert = new Alert(Alert.AlertType.ERROR); 412 | alert.setTitle("Error"); 413 | alert.setHeaderText(null); 414 | alert.setContentText(exception); 415 | alert.showAndWait(); 416 | } 417 | 418 | public GameBoard getGameBoard() { 419 | return this.gameBoard; 420 | } 421 | 422 | public GameVariation getGameVariation() { 423 | return this.gameVariation; 424 | } 425 | } 426 | -------------------------------------------------------------------------------- /src/GameGUI/Main.java: -------------------------------------------------------------------------------- 1 | package GameGUI; 2 | 3 | import Res.ResourceLoader; 4 | import javafx.application.Application; 5 | import javafx.fxml.FXMLLoader; 6 | import javafx.scene.Parent; 7 | import javafx.scene.Scene; 8 | import javafx.stage.Stage; 9 | 10 | /** 11 | * 12 | * @author Aris 13 | */ 14 | public class Main extends Application { 15 | private final String FXML_LOCATION = "/GameGUI/SnakesAndLadders.fxml"; 16 | 17 | @Override 18 | public void start(Stage stage) throws Exception { 19 | FXMLLoader myLoader = new FXMLLoader(getClass().getResource(FXML_LOCATION)); 20 | Parent root = myLoader.load(); 21 | 22 | Scene scene = new Scene(root); 23 | 24 | stage.setScene(scene); 25 | stage.setResizable(false); 26 | stage.setTitle("SNAKES AND LADDERS"); 27 | stage.getIcons().add(ResourceLoader.getImage("snake.png")); 28 | stage.show(); 29 | } 30 | 31 | public static void main(String[] args) { 32 | launch(args); 33 | } 34 | } -------------------------------------------------------------------------------- /src/GameGUI/PlayAgainOrExitAlert.java: -------------------------------------------------------------------------------- 1 | package GameGUI; 2 | 3 | import java.net.URL; 4 | import java.util.ResourceBundle; 5 | import javafx.fxml.FXML; 6 | import javafx.fxml.Initializable; 7 | import javafx.scene.control.Button; 8 | import javafx.scene.control.Label; 9 | import javafx.stage.Stage; 10 | import javafx.stage.WindowEvent; 11 | 12 | /** 13 | * 14 | * @author Aris 15 | */ 16 | public class PlayAgainOrExitAlert implements Initializable { 17 | @FXML 18 | private Label winnerName; 19 | 20 | @FXML 21 | private Button yesBtn; 22 | 23 | @FXML 24 | private Button noBtn; 25 | 26 | public static boolean isRematch; 27 | 28 | @Override 29 | public void initialize(URL location, ResourceBundle resources) { 30 | yesBtn.setOnAction(ev -> { 31 | isRematch = true; 32 | Stage stage = (Stage) yesBtn.getScene().getWindow(); 33 | stage.fireEvent(new WindowEvent(stage,WindowEvent.WINDOW_CLOSE_REQUEST)); 34 | stage.close(); 35 | }); 36 | 37 | noBtn.setOnAction(ev -> { 38 | isRematch = false; 39 | Stage stage = (Stage) noBtn.getScene().getWindow(); 40 | stage.fireEvent(new WindowEvent(stage,WindowEvent.WINDOW_CLOSE_REQUEST)); 41 | stage.close(); 42 | }); 43 | } 44 | 45 | public boolean rematchOrNot() { 46 | return isRematch; 47 | } 48 | 49 | public void setWinnerName(String winner) { 50 | winnerName.setText(winner); 51 | } 52 | 53 | public Label getWinnerName() { 54 | return winnerName; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/GameGUI/PlayAgainOrExitPanel.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 21 | 26 | 31 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/GameGUI/SnakesAndLadders.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 31 | 36 | 37 | 38 | 43 | 48 | 53 | 54 | 55 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 79 | 84 | 85 | 86 | 94 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 138 | 142 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 158 | 163 | 168 | 169 | 170 | 171 | 172 | 180 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 200 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |
249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | 1109 | 1110 | 1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 |
1281 |
-------------------------------------------------------------------------------- /src/ObjectControllers/PlayerController.java: -------------------------------------------------------------------------------- 1 | package ObjectControllers; 2 | 3 | import GameBoard.GameBoard; 4 | import GameGUI.GameGUI; 5 | import POJO.Player; 6 | import enums.GameVariation; 7 | import enums.PlayerType; 8 | import javafx.animation.PauseTransition; 9 | import javafx.scene.layout.Pane; 10 | import javafx.util.Duration; 11 | 12 | /** 13 | * 14 | * @author Aris 15 | */ 16 | public class PlayerController { 17 | private GameGUI gameGUI; 18 | private GameBoard gameBoard; 19 | 20 | public PlayerController(GameGUI gameGUI, GameBoard gameBoard) { 21 | this.gameGUI = gameGUI; 22 | this.gameBoard = gameBoard; 23 | } 24 | 25 | public void rollDiceAndMove() { 26 | int diceRoll = gameBoard.rollDice(); 27 | gameGUI.lockDiceButton(); 28 | 29 | PauseTransition pause = new PauseTransition(Duration.seconds(GameBoard.DICE_ROLL_DELAY)); 30 | 31 | pause.setOnFinished(event -> { 32 | gameGUI.indicateDiceRoll(diceRoll); 33 | gameGUI.resetAllTiles(); 34 | gameGUI.unlockDiceButton(); 35 | 36 | int newIndex = getPlayerIndexAfterRoll(diceRoll); 37 | move(newIndex); 38 | 39 | if (newIndex == GameBoard.WIN_POINT) { 40 | pause.stop(); 41 | gameGUI.gameOver(); 42 | } else { 43 | swapTurns(); 44 | gameGUI.updateCurrentTurnLabel(); 45 | } 46 | 47 | if (isComputerTurn()) { 48 | computerRollDiceAndMove(); 49 | } 50 | }); 51 | 52 | pause.play(); 53 | } 54 | 55 | public void computerRollDiceAndMove() { 56 | int diceRoll = gameBoard.rollDice(); 57 | gameGUI.lockDiceButton(); 58 | 59 | PauseTransition pause = new PauseTransition(Duration.seconds(GameBoard.COMPUTER_MOVE_DELAY)); 60 | 61 | pause.setOnFinished(event -> { 62 | gameGUI.indicateDiceRoll(diceRoll); 63 | gameGUI.resetAllTiles(); 64 | gameGUI.unlockDiceButton(); 65 | 66 | int newIndex = getPlayerIndexAfterRoll(diceRoll); 67 | move(newIndex); 68 | 69 | if (newIndex == GameBoard.WIN_POINT) { 70 | pause.stop(); 71 | gameGUI.gameOver(); 72 | } else { 73 | swapTurns(); 74 | gameGUI.updateCurrentTurnLabel(); 75 | } 76 | }); 77 | 78 | pause.play(); 79 | } 80 | 81 | public void move(int currentIndex) { 82 | int[] newCoordinates = gameBoard.getBoardCoordinates(GameBoard.NUMBER_OF_TILES - currentIndex); 83 | Pane clickedCell = (Pane)gameGUI.getNodeByRowColumnIndex(newCoordinates[0], newCoordinates[1]); 84 | 85 | gameBoard.getCurrentPlayer().getPlayerPiece().setPosition(currentIndex); 86 | gameGUI.movePieceImages(newCoordinates[0], newCoordinates[1]); 87 | 88 | if (currentIndex == GameBoard.WIN_POINT) { 89 | --currentIndex; // silly way of avoiding the ArrayOutOfBoundsException. 90 | } 91 | 92 | if (gameBoard.getTile(currentIndex).containsLadderOrSnake()) { 93 | gameGUI.setCellStyle(clickedCell, GameGUI.SNAKE_OR_LADDER_HIT_CELL_STYLE); 94 | int updatedIndex = gameBoard.getUpdatedPosition(currentIndex); 95 | move(updatedIndex); 96 | return; 97 | } 98 | } 99 | 100 | public int getPlayerIndexAfterRoll(int diceRoll) { 101 | Player currentPlayer = gameBoard.getCurrentPlayer(); 102 | 103 | int currentPosition = currentPlayer.getPlayerPiece().getPosition(); 104 | int newIndex = -1; 105 | 106 | newIndex = currentPosition + diceRoll; 107 | 108 | if (newIndex > 100) { 109 | if (gameGUI.getGameVariation() == GameVariation.CLASSIC) { 110 | newIndex = 200 - newIndex; 111 | } else if (gameGUI.getGameVariation() == GameVariation.ARISTOMENIS) { 112 | newIndex = newIndex - 100; 113 | } 114 | } 115 | 116 | return newIndex; 117 | } 118 | 119 | public void swapTurns() { 120 | if (gameBoard.getCurrentPlayer() == gameBoard.getPlayer1()) { 121 | gameBoard.getPlayer1().setTurn(0); 122 | gameBoard.getPlayer2().setTurn(1); 123 | } else if (gameBoard.getCurrentPlayer() == gameBoard.getPlayer2()) { 124 | gameBoard.getPlayer1().setTurn(1); 125 | gameBoard.getPlayer2().setTurn(0); 126 | } 127 | } 128 | 129 | public boolean isComputerTurn() { 130 | return (gameBoard.getCurrentPlayer() == gameBoard.getPlayer2()) && (gameBoard.getPlayer2().getPlayerType() == PlayerType.COMPUTER); 131 | } 132 | } -------------------------------------------------------------------------------- /src/POJO/ComputerPlayer.java: -------------------------------------------------------------------------------- 1 | package POJO; 2 | 3 | import enums.PlayerType; 4 | 5 | /** 6 | * 7 | * @author Aris 8 | */ 9 | public class ComputerPlayer extends Player { 10 | public ComputerPlayer() { 11 | super(); 12 | } 13 | 14 | public ComputerPlayer(int turn, Piece playerPiece) { 15 | super(turn, playerPiece); 16 | } 17 | 18 | @Override 19 | public PlayerType getPlayerType() { 20 | return PlayerType.COMPUTER; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/POJO/HumanPlayer.java: -------------------------------------------------------------------------------- 1 | package POJO; 2 | 3 | import enums.PlayerType; 4 | 5 | /** 6 | * 7 | * @author Aris 8 | */ 9 | public class HumanPlayer extends Player { 10 | public HumanPlayer() { 11 | super(); 12 | } 13 | 14 | public HumanPlayer(int turn, Piece playerPiece) { 15 | super(turn, playerPiece); 16 | } 17 | 18 | @Override 19 | public PlayerType getPlayerType() { 20 | return PlayerType.HUMAN; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/POJO/Piece.java: -------------------------------------------------------------------------------- 1 | package POJO; 2 | 3 | import javafx.scene.image.ImageView; 4 | 5 | /** 6 | * 7 | * @author Aris 8 | */ 9 | public class Piece { 10 | private int position; 11 | private String color; 12 | private ImageView pieceImage; 13 | 14 | public Piece(int position, String color, ImageView pieceImage) { 15 | this.position = position; 16 | this.color = color; 17 | this.pieceImage = pieceImage; 18 | } 19 | 20 | public int getPosition() { 21 | return position; 22 | } 23 | 24 | public void setPosition(int position) { 25 | this.position = position; 26 | } 27 | 28 | public String getColor() { 29 | return color; 30 | } 31 | 32 | public void setColor(String color) { 33 | this.color = color; 34 | } 35 | 36 | public ImageView getPieceImage() { 37 | return pieceImage; 38 | } 39 | 40 | public void setPieceImage(ImageView pieceImage) { 41 | this.pieceImage = pieceImage; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/POJO/Player.java: -------------------------------------------------------------------------------- 1 | package POJO; 2 | 3 | import enums.PlayerType; 4 | 5 | /** 6 | * 7 | * @author Aris 8 | */ 9 | public abstract class Player { 10 | private int turn; 11 | private Piece playerPiece; 12 | 13 | public Player() {} 14 | 15 | public Player(int turn, Piece playerPiece) { 16 | this.turn = turn; 17 | this.playerPiece = playerPiece; 18 | } 19 | 20 | public int getTurn() { 21 | return turn; 22 | } 23 | 24 | public void setTurn(int turn) { 25 | this.turn = turn; 26 | } 27 | 28 | public Piece getPlayerPiece() { 29 | return playerPiece; 30 | } 31 | 32 | public void setPlayerPiece(Piece playerPiece) { 33 | this.playerPiece = playerPiece; 34 | } 35 | 36 | public abstract PlayerType getPlayerType(); 37 | 38 | @Override 39 | public String toString() { 40 | return "[Turn: " + turn + ", Piece: " + playerPiece.getColor() + "]"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/POJO/Tile.java: -------------------------------------------------------------------------------- 1 | package POJO; 2 | 3 | import enums.TileContainer; 4 | 5 | /** 6 | * 7 | * @author Aris 8 | */ 9 | public class Tile { 10 | private int position; 11 | private final TileContainer tileContainer; 12 | 13 | public Tile(int position, TileContainer tileContainer) { 14 | this.position = position; 15 | this.tileContainer = tileContainer; 16 | } 17 | 18 | public int getPosition() { 19 | return position; 20 | } 21 | 22 | public void setPosition(int position) { 23 | this.position = position; 24 | } 25 | 26 | public TileContainer getTileContainer() { 27 | return this.tileContainer; 28 | } 29 | 30 | public boolean containsLadderOrSnake() { 31 | return this.tileContainer != TileContainer.NONE; 32 | } 33 | } -------------------------------------------------------------------------------- /src/enums/GameMode.java: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | /** 4 | * 5 | * @author Aris 6 | */ 7 | public enum GameMode { 8 | AGAINST_HUMAN, AGAINST_COMPUTER 9 | } 10 | -------------------------------------------------------------------------------- /src/enums/GameVariation.java: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | /** 4 | * 5 | * @author Aris 6 | */ 7 | public enum GameVariation { 8 | CLASSIC, ARISTOMENIS 9 | } 10 | -------------------------------------------------------------------------------- /src/enums/PlayerType.java: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | public enum PlayerType { 4 | HUMAN, COMPUTER; 5 | } 6 | -------------------------------------------------------------------------------- /src/enums/TileContainer.java: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | /** 4 | * 5 | * @author Aris 6 | */ 7 | public enum TileContainer { 8 | NONE, LADDER, SNAKE 9 | } 10 | --------------------------------------------------------------------------------