Advertisement
Guest User

Interface

a guest
May 4th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.91 KB | None | 0 0
  1.  
  2. /**
  3. * @author Dean
  4. */
  5.  
  6. import java.util.Timer;
  7. import java.util.TimerTask;
  8.  
  9. import javafx.application.Application;
  10. import javafx.application.Platform;
  11.  
  12. import java.io.IOException;
  13. import java.util.ArrayList;
  14.  
  15. import javafx.application.Application;
  16. import javafx.event.EventHandler;
  17. import javafx.event.ActionEvent;
  18. import javafx.geometry.Insets;
  19. import javafx.geometry.Pos;
  20. import javafx.scene.Scene;
  21. import javafx.scene.control.Button;
  22. import javafx.scene.control.TextArea;
  23. import javafx.scene.control.TextField;
  24. import javafx.scene.effect.DropShadow;
  25. import javafx.scene.image.Image;
  26. import javafx.scene.image.ImageView;
  27. import javafx.scene.input.MouseEvent;
  28. import javafx.scene.layout.GridPane;
  29. import javafx.scene.layout.HBox;
  30. import javafx.scene.layout.StackPane;
  31. import javafx.scene.layout.VBox;
  32. import javafx.scene.paint.Color;
  33. import javafx.scene.text.Text;
  34. import javafx.stage.Stage;
  35.  
  36. public class Interface extends Application {
  37.  
  38.  
  39. /**
  40. * @todo update the interface so that it displays real player information
  41. * refreshes whenever the next player is loaded
  42. * players take goes
  43. */
  44. GridPane grid;
  45. int previousPlayersAgeIndex;
  46.  
  47. Player [] players;
  48. Player currentPlayer;
  49.  
  50. TextField input;
  51.  
  52. Timer timer;
  53.  
  54. TextArea console;
  55. TextArea playerConsole;
  56. StackPane stackPane,playerConsoleStack, root;
  57. Text job, number,money, debt, username, islandName;
  58.  
  59. Button takeLoan, payDebt;
  60. Button accept, confirm, decline;
  61. Button ageOne, ageTwo, ageThree, ageFour, ageFive, ageSix, ageSeven;
  62. Button volcanoButton;
  63. Button island1, island2, island3, island4, island5;//Travel Space Button - Delete?;
  64. Button [] ageButtons;
  65.  
  66. ImageView boatImage;
  67. ImageView planeImage;
  68.  
  69. HBox badgeBox, secondRow, minimapBox, numberBox, volcanoButtonBox, firstRow;
  70. HBox usernameBox, debtBox,fourthRow,buttonBox,fifthRow, cardCareerDescriptionBox, islandButtonBox;
  71. HBox careerButtonBox;
  72. VBox userDetails,financeDetails,thirdRow;
  73.  
  74. ImageView carImageView;
  75. // Image defaultCar = new Image("img/defaultCar.png");
  76. // Image partner = new Image("img/partner.png");
  77. // Image oneCh = new Image("img/1k.png");
  78. // Image twoCh = new Image("img/2k.png");
  79. // Image threeCh = new Image("img/3k.png");
  80. // Image fourCh = new Image("img/4k.png");
  81. // Image oneChThreeP = new Image("img/1k3p.png");
  82. // Image oneChTwoP = new Image("img/1k2p.png");
  83. // Image oneChOneP = new Image("img/1k1p.png");
  84. // Image twoChOneP = new Image("img/2k1p.png");
  85. // Image twoChTwoP = new Image("img/2k2p.png");
  86. // Image threeChOneP = new Image("img/3k1p.png");
  87. // Image oneP = new Image("img/1p.png");
  88. // Image twoP = new Image("img/2p.png");
  89. // Image threeP = new Image("img/3p.png");
  90. // Image fourP = new Image("img/4p.png");
  91. //
  92. // Image carImage;
  93.  
  94. DropShadow borderGlow;
  95. Scene scene;
  96. String dialog = "";
  97.  
  98. boolean valueEntered;
  99. boolean waitForAccept;
  100. boolean isPayingDebt;
  101. boolean isTakingLoan;
  102. boolean isTakingGoldToken;
  103. boolean isBuyingHouse;
  104. boolean isPayingBankerForExams;//they are going to
  105. boolean canPayBankerForExams;//they can
  106.  
  107. boolean isSpinToWin;
  108.  
  109. boolean acceptedHouse;
  110.  
  111. String inp;
  112. Image islandPath,planePath, boatPath;
  113. ImageView islandImage,spinnerImage;
  114.  
  115. VBox spinnerImageBox, carImageBox;
  116. //Code used for graduate career card
  117. GridPane gridCareer;
  118. CareerCardholder careerCards;
  119. GraduateCareer graduateCard,option1,option2,option3;
  120. TextField description1, description2, description3;
  121. Button career1, career2, career3;
  122. Boolean chosenCareer=false;
  123. Minimap map;
  124.  
  125. ///////////////////////////////////////////////////////////////////////////////
  126. /**
  127. * screen objects go here so they can be accessed from other classes
  128. */
  129.  
  130. HBox playerInput;
  131.  
  132. boolean waitingOnPlayerSpin; //the boolean value indicating that the player needs to spin to move forward set amount of spaces
  133. boolean spaceRequiresSpin = false;
  134. boolean accepted = false;
  135. boolean declined = true;
  136.  
  137. boolean spinnerDisabled;
  138.  
  139. Board board;
  140. Island island;
  141. int i=0;
  142. int goldToken;
  143.  
  144. public static void main(String[] args) {
  145. launch(args);
  146. }
  147.  
  148. public void start(Stage stage) throws IOException {
  149. stage.setTitle("Game of Life");
  150.  
  151. spinnerDisabled=false;
  152. waitingOnPlayerSpin = true;
  153. isPayingDebt = false;
  154. isTakingLoan = false;
  155. isBuyingHouse = false;
  156.  
  157.  
  158. board = new Board(this, players);
  159.  
  160.  
  161. //border effect that will be applied to the node representing the player's current age.
  162. borderGlow = new DropShadow();
  163. borderGlow.setColor(Color.GREEN);
  164. borderGlow.setHeight(30);
  165. borderGlow.setWidth(30);
  166.  
  167. grid = new GridPane();
  168. grid.setPadding(new Insets(25, 25, 25, 25));
  169. grid.setVgap(0);
  170. grid.setAlignment(Pos.CENTER);
  171. grid.setGridLinesVisible(false);
  172.  
  173. //loading in the minimap
  174. map = new Minimap();
  175. map.update(board);
  176. root = map.getRoot();
  177.  
  178.  
  179. spinnerImage = new ImageView(board.spinner.spinnerImage);
  180. spinnerImage.setFitWidth(275);
  181. spinnerImage.setFitHeight(275);
  182.  
  183. spinnerImageBox = new VBox();
  184. spinnerImageBox.getChildren().add(spinnerImage);
  185. spinnerImageBox.setPadding(new Insets(0, 0, 30, 400));
  186.  
  187. // carImage = new Image("img/defaultCar.png");
  188. carImageView = new ImageView(board.currentPlayer.carImage);
  189.  
  190. carImageBox = new VBox();
  191. carImageBox.getChildren().add(carImageView);
  192. carImageBox.setPadding(new Insets(0,0, 30, 100));
  193.  
  194. Button volcanoButton = new Button("Volcano");
  195. volcanoButton.getStyleClass().add("redButton");
  196.  
  197. number = new Text("-");
  198. number.getStyleClass().add("largeNumber");
  199.  
  200. numberBox = new HBox();
  201. numberBox.getChildren().add(number);
  202. numberBox.setPadding(new Insets(75, 0, 0, 502));
  203.  
  204. volcanoButtonBox = new HBox();
  205. volcanoButtonBox.getChildren().add(volcanoButton);
  206. volcanoButtonBox.setAlignment(Pos.BOTTOM_RIGHT);
  207. volcanoButtonBox.setPadding(new Insets(0, 100, 0, 0)); //250 502
  208.  
  209. spinnerImageBox.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  210. if(!spinnerDisabled) {
  211. if(spaceRequiresSpin) {
  212. board.currentPlayer.space.action();
  213. return;
  214. }
  215. if(waitingOnPlayerSpin && !spaceRequiresSpin) { //we don't want the player to advance to the next space whenever the space they are currently on requires a spin to complete its action
  216. updatePositionAndRefresh();
  217.  
  218. }
  219. }
  220. });
  221.  
  222. stackPane = new StackPane();
  223. stackPane.getChildren().addAll(numberBox, carImageBox, volcanoButtonBox, spinnerImageBox);
  224.  
  225. firstRow = new HBox();
  226. firstRow.getChildren().addAll(root, stackPane);
  227. firstRow.setPadding(new Insets(0, 0, 10, 0));
  228.  
  229. ageOne = new Button("18");
  230. ageOne.getStyleClass().add("roundButton");
  231.  
  232. ageTwo = new Button("21");
  233. ageTwo.getStyleClass().add("roundButton");
  234.  
  235. ageThree = new Button("30");
  236. ageThree.getStyleClass().add("roundButton");
  237.  
  238. ageFour = new Button("40");
  239. ageFour.getStyleClass().add("roundButton");
  240.  
  241. ageFive = new Button("50");
  242. ageFive.getStyleClass().add("roundButton");
  243.  
  244. ageSix = new Button("60");
  245. ageSix.getStyleClass().add("roundButton");
  246.  
  247. ageSeven = new Button("70");
  248. ageSeven.getStyleClass().add("roundButton");
  249.  
  250. Button [] temp = {ageOne, ageTwo, ageThree, ageFour, ageFive, ageSix, ageSeven};
  251. ageButtons = temp;
  252.  
  253. secondRow = new HBox();
  254. secondRow.getChildren().addAll(ageOne, ageTwo, ageThree, ageFour, ageFive, ageSix, ageSeven);
  255. secondRow.setPadding(new Insets(0, 0, 15, 0));
  256.  
  257. planePath = new Image("img/greenPlane.png");
  258. planeImage = new ImageView(planePath);
  259. planeImage.setFitHeight(25);
  260. planeImage.setFitWidth(25);
  261.  
  262. boatPath = new Image("img/greenBoat.png");
  263. boatImage = new ImageView(boatPath);
  264. boatImage.setFitHeight(25);
  265. boatImage.setFitWidth(25);
  266.  
  267. username = new Text();
  268. username.getStyleClass().add("userText");
  269.  
  270. job = new Text();
  271. job.getStyleClass().add("userText");
  272.  
  273. usernameBox = new HBox();
  274. usernameBox.getChildren().add(username);
  275.  
  276. islandName= new Text();
  277. islandName.getStyleClass().add("userText");
  278.  
  279. badgeBox = new HBox();
  280. badgeBox.setPadding(new Insets(0, 0, 0, 5));
  281. badgeBox.getChildren().addAll(planeImage, boatImage);
  282.  
  283. usernameBox.getChildren().add(badgeBox);
  284.  
  285. userDetails = new VBox();
  286. userDetails.getChildren().addAll(usernameBox, job, islandName);
  287. userDetails.setPadding(new Insets(0, 0, 10, 5));
  288.  
  289. money = new Text();
  290. money.getStyleClass().add("moneyText");
  291.  
  292. debt = new Text();
  293. debt.getStyleClass().add("debtText");
  294.  
  295. //early retirement
  296. Button earlyRetire = new Button("Retire Early");
  297. earlyRetire.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  298. new EndScreen(this, players);
  299. });
  300.  
  301. takeLoan = new Button("Take Loan");
  302. takeLoan.getStyleClass().add("greenButton");
  303. takeLoan.setOnAction(new EventHandler<ActionEvent>() {
  304. public void handle(ActionEvent event) {
  305. isTakingLoan = true;
  306. System.out.println("Is taking loan"+isTakingLoan);
  307. disableInputNodes();
  308. input.setPromptText("Insert amount");
  309. }
  310. });
  311.  
  312. /**
  313. * @author Dean
  314. */
  315. payDebt = new Button("Pay Debt");
  316. payDebt.getStyleClass().add("redButton");
  317. payDebt.setOnAction(new EventHandler<ActionEvent>() {
  318. public void handle(ActionEvent event) {
  319. isPayingDebt = true;
  320. disableInputNodes();
  321. input.setPromptText("Insert amount");
  322. }
  323. });
  324.  
  325. debtBox = new HBox();
  326. debtBox.getChildren().add(debt);
  327. debtBox.getChildren().add(takeLoan);
  328. debtBox.getChildren().add(payDebt);
  329.  
  330. financeDetails = new VBox();
  331. financeDetails.getChildren().addAll(money, debtBox);
  332. financeDetails.setPadding(new Insets(0, 0, 10, 5));
  333.  
  334. //island buttons
  335. island1 = new Button(board.islandNames[1]);
  336. island1.getStyleClass().add("yellowButton");
  337. island1.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  338. System.out.println("Island 1 button pressed");
  339. TravelSpace.islandID = 1;
  340. TravelSpace.islandPicked = true;
  341. board.currentPlayer.space.action();
  342. });
  343.  
  344. island2 = new Button(board.islandNames[2]);
  345. island2.getStyleClass().add("yellowButton");
  346. island2.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  347. System.out.println("Island 2 button pressed");
  348. TravelSpace.islandID = 2;
  349. TravelSpace.islandPicked = true;
  350. board.currentPlayer.space.action();
  351. });
  352.  
  353. island3 = new Button(board.islandNames[3]);
  354. island3.getStyleClass().add("yellowButton");
  355. island3.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  356. System.out.println("Island 3 button pressed");
  357. TravelSpace.islandID = 3;
  358. TravelSpace.islandPicked = true;
  359. board.currentPlayer.space.action();
  360. });
  361.  
  362. island4 = new Button(board.islandNames[4]);
  363. island4.getStyleClass().add("yellowButton");
  364. island4.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  365. System.out.println("Island 4 button pressed");
  366. TravelSpace.islandID = 4;
  367. TravelSpace.islandPicked = true;
  368. board.currentPlayer.space.action();
  369. });
  370.  
  371. island5 = new Button(board.islandNames[5]);
  372. island5.getStyleClass().add("yellowButton");
  373. island5.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  374. System.out.println("Island 5 button pressed");
  375. TravelSpace.islandID = 5;
  376. TravelSpace.islandPicked = true;
  377. board.currentPlayer.space.action();
  378. });
  379.  
  380. islandButtonBox = new HBox();
  381. islandButtonBox.setPadding(new Insets(0, 75, 0, 0));
  382. islandButtonBox.getChildren().addAll(earlyRetire,island1, island2, island3, island4);
  383. islandButtonBox.setAlignment(Pos.CENTER_RIGHT);
  384. financeDetails.getChildren().add(islandButtonBox);
  385.  
  386. thirdRow = new VBox();
  387. thirdRow.getChildren().addAll(userDetails, financeDetails);
  388.  
  389. console = new TextArea("");
  390. console.setWrapText(true);
  391. console.setPrefWidth(850);
  392. console.setPrefHeight(200);
  393. console.setDisable(false);
  394. console.getStyleClass().add("greyTextField");
  395.  
  396. accept = new Button("Accept");
  397. accept.getStyleClass().add("greenButton");
  398. accept.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  399. if(isBuyingHouse) {
  400. System.out.println("Accept pressed");
  401. acceptedHouse = true;
  402. board.currentPlayer.space.action();
  403. }
  404. else if(canPayBankerForExams){
  405. isPayingBankerForExams=true;
  406. board.currentPlayer.space.action();
  407. }
  408. });
  409.  
  410. decline = new Button("Decline");
  411. decline.getStyleClass().add("redButton");
  412. decline.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  413. if(isBuyingHouse) {
  414. acceptedHouse = false;
  415. board.currentPlayer.space.action();
  416. }
  417. else if(canPayBankerForExams){
  418. isPayingBankerForExams=false;
  419. board.currentPlayer.space.action();
  420. }
  421. });
  422.  
  423. buttonBox = new HBox();
  424. buttonBox.getChildren().addAll(accept, decline);
  425. buttonBox.setPadding(new Insets(0, 8, 5, 0));
  426. buttonBox.setAlignment(Pos.BOTTOM_RIGHT);
  427.  
  428. StackPane consoleStackPane = new StackPane();
  429. consoleStackPane.getChildren().addAll(console, buttonBox);
  430.  
  431. fourthRow = new HBox();
  432. fourthRow.getChildren().add(consoleStackPane);
  433. fourthRow.setPadding(new Insets(0, 0, 10, 0));
  434.  
  435. playerConsole = new TextArea("This is where the player will be prompted");
  436. playerConsole.setPrefWidth(850);
  437. playerConsole.setPrefHeight(250);
  438. playerConsole.setDisable(false);
  439. playerConsole.getStyleClass().add("greyTextField");
  440.  
  441. confirm = new Button("Confirm");
  442. confirm.getStyleClass().add("greenButton");
  443. confirm.setOnAction(new EventHandler<ActionEvent>() {
  444. public void handle(ActionEvent event) {
  445. if(isPayingDebt) { //if the player wishes to pay off debt - would be set to true if they have pressed the pay debt button.
  446. if(validateDebtInput()) { //input in the text field needs to be validated to make sure it is a number and within bounds
  447. System.out.println("Made it in to debt");
  448. board.currentPlayer.payDebt(Integer.valueOf(input.getText()));
  449. isPayingDebt = false;
  450. }
  451. }
  452. if(isTakingLoan) {
  453. if(validateLoanInput()) {
  454. System.out.println("Validated the input");
  455. board.currentPlayer.takeLoan(Integer.valueOf(input.getText()));
  456. System.out.println("Player's balance is now"+board.currentPlayer.balance);
  457. isTakingLoan = false;
  458. }
  459. }
  460. if(isTakingGoldToken) {
  461. if(validateGoldTokenInput()) {
  462. goldToken = Integer.parseInt(input.getText());
  463. valueEntered = true;
  464. board.currentPlayer.space.action();
  465. }
  466. }
  467.  
  468. debt.setText(String.valueOf(board.currentPlayer.getDebt()));
  469. updatePlayerMoney();
  470. disableInputNodes();
  471. resetInput();
  472. }
  473. });
  474.  
  475. input = new TextField(dialog);
  476. input.setPrefWidth(200);
  477.  
  478. playerInput = new HBox();
  479. playerInput.getChildren().addAll(input, confirm);
  480. playerInput.setPadding(new Insets(0, 8, 5, 0));
  481. playerInput.setAlignment(Pos.BOTTOM_RIGHT);
  482.  
  483. playerConsoleStack = new StackPane();
  484. playerConsoleStack.getChildren().addAll(playerConsole, playerInput);
  485.  
  486. fifthRow = new HBox();
  487. fifthRow.getChildren().add(playerConsoleStack);
  488.  
  489. createCareerUI();
  490.  
  491. grid.add(firstRow, 0, 0);
  492. grid.add(secondRow, 0, 1);
  493. grid.add(thirdRow, 0, 2);
  494. grid.add(careerButtonBox, 0,0);
  495. grid.add(fourthRow, 0, 3);
  496. grid.add(cardCareerDescriptionBox, 0,1);
  497. grid.add(fifthRow, 0, 4);
  498.  
  499. career1.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  500. graduateCard=option1;
  501. updateCareerInfo();
  502. });
  503.  
  504. career2.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  505. graduateCard=option2;
  506. updateCareerInfo();
  507. });
  508. career3.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent e) -> {
  509. graduateCard=option3;
  510. updateCareerInfo();
  511. });
  512.  
  513. updateInterface(true);
  514.  
  515.  
  516. Scene scene = new Scene(grid, 1200, 1000);
  517. scene.getStylesheets().add(Interface.class.getResource("Interface.css").toExternalForm());
  518. stage.setScene(scene);
  519. stage.show();
  520. }
  521.  
  522. public void updateCareerInfo(){
  523. chosenCareer=true;
  524. board.currentPlayer.changeToGraduate(graduateCard);
  525. board.currentPlayer.space.interact();
  526. board.currentPlayer.space.action();
  527. setUpMain();
  528. updateCareerUI();
  529. }
  530.  
  531. public void updateInterface(boolean firstUpdate) {
  532. //setting text fields to the new player information
  533. username.setText(board.currentPlayer.getName());
  534. job.setText(board.currentPlayer.getJobTitle());
  535. islandName.setText(board.currentPlayer.island.islandName);
  536. money.setText(String.valueOf("£" + board.currentPlayer.getBalance()));
  537. debt.setText(String.valueOf("£" + board.currentPlayer.getDebt()));
  538.  
  539. if(!firstUpdate) {
  540. //removing the previous player's highlighted age - no need to do this if it's the first update
  541. ageButtons[previousPlayersAgeIndex].setEffect(null);
  542. }
  543.  
  544. if(board.currentPlayer.space instanceof Exams && !board.currentPlayer.passedExams) {
  545. spaceRequiresSpin = true;
  546. }
  547.  
  548. //getting the next player, or who is now the current player's age and highlighting the correct node
  549. ageButtons[board.currentPlayer.findIndexOfCurrentAge()].setEffect(borderGlow);
  550. //setting the 'new' current player's age button index to the 'previous' variable for the next update - as it will need to be switched off the next player
  551. previousPlayersAgeIndex = board.currentPlayer.findIndexOfCurrentAge();
  552.  
  553. //resetting other interface elements in preparation for the next player
  554. setPlayerConsoleToDefault();
  555. setSpinnerNumberToDefault();
  556.  
  557. //check if player's car has gained new car items and update image accordingly
  558. //board.currentPlayer.checkCar();
  559. // updateCar();
  560.  
  561. //if they have different badges to the player preceding them, these need to be removed and their badges added
  562. removeBadges();
  563. addBadges();
  564.  
  565. //disabling input nodes that are not required for the current space
  566. disableInputNodes();
  567. outputToConsole();
  568. broadCast();
  569. }
  570.  
  571. public void outputToConsole() {
  572. playerConsole.setText(board.currentPlayer.space.interact());
  573. }
  574.  
  575. public void addBadges() {
  576. if(board.currentPlayer.hasBoat() && !badgeBox.getChildren().contains(boatImage) ) {
  577. badgeBox.getChildren().add(boatImage);
  578. }
  579.  
  580. if(board.currentPlayer.hasPlane() && !badgeBox.getChildren().contains(planeImage) ) {
  581. badgeBox.getChildren().add(planeImage);
  582. }
  583. }
  584.  
  585. public void removeBadges() {
  586. if(!board.currentPlayer.hasBoat() && badgeBox.getChildren().contains(boatImage)) {
  587. badgeBox.getChildren().remove(boatImage);
  588. }
  589.  
  590. if(!board.currentPlayer.hasPlane() && badgeBox.getChildren().contains(planeImage)) {
  591. badgeBox.getChildren().remove(planeImage);
  592. }
  593. }
  594.  
  595. public void setSpinnerNumber(int num) {
  596. number.setText(String.valueOf(num));
  597.  
  598. }
  599.  
  600. public void setSpinnerNumberToDefault() {
  601. number.setText("-");
  602. }
  603.  
  604. //the player console is the lower of the two, it outputs player specific information.
  605. public void setPlayerConsoleToDefault() {
  606. playerConsole.setText("");
  607. }
  608.  
  609. //for deleting unrequired input nodes whenever the space doesn't require them.
  610. public void disableInputNodes() {
  611. if(isPayingDebt) { //if they are updating the interface to pay debt, that's not a input type for a space - has to be updated seperately.
  612. accept.setDisable(true);
  613. decline.setDisable(true);
  614. input.setDisable(false);
  615. confirm.setDisable(false);
  616. }
  617. else if(isTakingLoan) {
  618. accept.setDisable(true);
  619. decline.setDisable(true);
  620. input.setDisable(false);
  621. confirm.setDisable(false);
  622. }
  623. else {
  624. switch(board.currentPlayer.space.inputType) {
  625. case SPIN: input.setDisable(true);
  626. accept.setDisable(true);
  627. decline.setDisable(true);
  628. confirm.setDisable(true);
  629. island1.setDisable(true);
  630. island2.setDisable(true);
  631. island3.setDisable(true);
  632. island4.setDisable(true);
  633. island5.setDisable(true);
  634. break;
  635.  
  636. case ACCEPT_DECLINE_LOAN: input.setDisable(true);
  637. confirm.setDisable(true);
  638. accept.setDisable(false);
  639. decline.setDisable(false);
  640. takeLoan.setDisable(false);
  641. payDebt.setDisable(false);
  642. island1.setDisable(true);
  643. island2.setDisable(true);
  644. island3.setDisable(true);
  645. island4.setDisable(true);
  646. island5.setDisable(true);
  647. break;
  648.  
  649. case ACCEPT: input.setDisable(true);
  650. confirm.setDisable(true);
  651. accept.setDisable(false);
  652. decline.setDisable(true);
  653. island1.setDisable(true);
  654. island2.setDisable(true);
  655. island3.setDisable(true);
  656. island4.setDisable(true);
  657. island5.setDisable(true);
  658. break;
  659.  
  660. case TEXTINPUT: accept.setDisable(true);
  661. decline.setDisable(true);
  662. input.setDisable(false);
  663. confirm.setDisable(false);
  664. island1.setDisable(true);
  665. island2.setDisable(true);
  666. island3.setDisable(true);
  667. island4.setDisable(true);
  668. island5.setDisable(true);
  669. break;
  670.  
  671. case NONE: accept.setDisable(true);
  672. decline.setDisable(true);
  673. input.setDisable(true);
  674. confirm.setDisable(true);
  675. island1.setDisable(true);
  676. island2.setDisable(true);
  677. island3.setDisable(true);
  678. island4.setDisable(true);
  679. island5.setDisable(true);
  680. break;
  681.  
  682. case BUTTONS: accept.setDisable(true);
  683. decline.setDisable(true);
  684. input.setDisable(true);
  685. confirm.setDisable(true);
  686. island1.setDisable(false);
  687. island2.setDisable(false);
  688. island3.setDisable(false);
  689. island4.setDisable(false);
  690. island5.setDisable(false);
  691. break;
  692. }
  693. }
  694.  
  695. if(isPayingDebt) {
  696. takeLoan.setDisable(true);
  697. }
  698. else if(!isPayingDebt) {
  699. takeLoan.setDisable(false);
  700. }
  701.  
  702. if(isTakingLoan) {
  703. payDebt.setDisable(true);
  704. }
  705. else if(!isTakingLoan) {
  706. payDebt.setDisable(false);
  707. }
  708.  
  709.  
  710. //if the player has no debt then the button should not be activated.
  711. if(board.currentPlayer.debt <= 0) {
  712. payDebt.setDisable(true);
  713. }
  714. }
  715.  
  716. public void getPlayerInput() {
  717. inp = input.getText();
  718. }
  719.  
  720. public void resetInput() {
  721. input.clear();
  722. }
  723.  
  724. public void updatePlayerMoney() {
  725. money.setText("£" +String.valueOf(board.currentPlayer.getBalance()));
  726. }
  727.  
  728. public boolean validateDebtInput() {
  729. String text = input.getText(); //text field produces a string. need to get this string then convert to int for validation
  730. int amount = Integer.valueOf(text);
  731.  
  732. if(amount >= 0 && amount <= board.currentPlayer.getDebt() && amount <= board.currentPlayer.getBalance()) {
  733. return true;
  734. }
  735.  
  736. return false;
  737. }
  738.  
  739. public boolean validateLoanInput() {
  740. String text = input.getText();
  741. int amount = Integer.valueOf(text);
  742.  
  743. if(amount >= 10000 && amount % 10000 == 0) {
  744. return true;
  745. }
  746.  
  747. return false;
  748. }
  749.  
  750. public boolean validateGoldTokenInput() {
  751. String text = input.getText();
  752. int amount = Integer.valueOf(text);
  753.  
  754. if(amount >= 1 && amount <= 10) {
  755. return true;
  756. }
  757. return false;
  758. }
  759.  
  760. public void callSpaceAction() {
  761. board.currentPlayer.space.action();
  762. }
  763.  
  764. public void updatePositionAndRefresh() {
  765. int spin = board.spinner.spin(); //spin to get how many spaces the player is going to travel
  766. board.currentPlayer.moveAmountOfSpaces(spin, false); //move the player to the appropriate space
  767. timer = new Timer();
  768.  
  769. timer.schedule(new TimerTask() {
  770. public void run() {
  771. Platform.runLater(() -> {
  772. updateInterface(false);
  773. callSpaceAction();
  774. updateMinimap();
  775.  
  776. });
  777. }
  778. }, 2750);
  779.  
  780.  
  781. }
  782.  
  783. /**
  784. * if we indicate via the boolean value that the space the current player is on requires a spin,
  785. * the spinner, whenever clicked, will know to activate the interact method.
  786. * @param requires
  787. */
  788. public void setSpaceRequiresSpin(boolean requires) {
  789. spaceRequiresSpin = requires;
  790. }
  791.  
  792. public void setOptionCards(){
  793. option1 = careerCards.getGraduateCard();
  794. option2 = careerCards.getGraduateCard();
  795. Boolean match=true;
  796. int i=0;
  797. while(match|| i<10){
  798. if(!(option1.getTitle().equals(option2.getTitle()))){
  799. match=false;
  800. i++;
  801. }
  802. else{
  803. option2=careerCards.getGraduateCard();
  804. }
  805. }
  806. match=true;
  807. i=0;
  808. option3 = careerCards.getGraduateCard();
  809. while(match||i<10){
  810. if(!((option1.getTitle().equals(option3.getTitle()))||(option2.getTitle().equals(option3.getTitle())))){
  811. match=false;
  812. i++;
  813. }
  814. else{
  815. option3=careerCards.getGraduateCard();
  816. }
  817. }
  818. }
  819.  
  820. public void setUpCareerCard(){
  821. firstRow.setVisible(false);
  822. secondRow.setVisible(false);
  823. cardCareerDescriptionBox.setVisible(true);
  824. careerButtonBox.setVisible(true);
  825.  
  826. }
  827.  
  828. public void setUpMain(){
  829. firstRow.setVisible(true);
  830. secondRow.setVisible(true);
  831. cardCareerDescriptionBox.setVisible(false);
  832. careerButtonBox.setVisible(false);
  833. }
  834. public void updateCareerUI(){
  835. setOptionCards();
  836. career1.setText(option1.getTitle());
  837. career2.setText(option2.getTitle());
  838. career3.setText(option3.getTitle());
  839.  
  840. description1.setText(option1.getDescription());
  841. description2.setText(option2.getDescription());
  842. description3.setText(option3.getDescription());
  843. }
  844. public void createCareerUI() {
  845.  
  846. careerCards= new CareerCardholder();
  847. setOptionCards();
  848. career1= new Button(option1.getTitle());
  849. career2= new Button(option2.getTitle());
  850. career3= new Button(option3.getTitle());
  851.  
  852. description1= new TextField(option1.getDescription());
  853. description1.setMinWidth(350);
  854. description2= new TextField(option2.getDescription());
  855. description2.setMinWidth(350);
  856. description3= new TextField(option3.getDescription());
  857. description3.setMinWidth(350);
  858.  
  859. cardCareerDescriptionBox= new HBox();
  860. cardCareerDescriptionBox.setVisible(false);
  861. cardCareerDescriptionBox.setPadding(new Insets(0, 0, 0, 0));
  862. cardCareerDescriptionBox.getChildren().add(description1);
  863. cardCareerDescriptionBox.getChildren().add(description2);
  864. cardCareerDescriptionBox.getChildren().add(description3);
  865.  
  866. careerButtonBox = new HBox();
  867. careerButtonBox.getChildren().add(career1);
  868. careerButtonBox.getChildren().add(career2);
  869. careerButtonBox.getChildren().add(career3);
  870. careerButtonBox.setAlignment(Pos.CENTER);
  871. careerButtonBox.setPadding(new Insets(0, 0, 0, 0));
  872. careerButtonBox.setVisible(false);
  873. }
  874.  
  875. public void broadCast() {
  876. String name = board.currentPlayer.name;
  877. String typeOfSpace = "";
  878.  
  879. if(board.currentPlayer.space instanceof Exams) {
  880. typeOfSpace = "Exams";
  881. }
  882. else if(board.currentPlayer.space instanceof AlternateSpace) {
  883. typeOfSpace = "Alternate";
  884. }
  885. else if(board.currentPlayer.space instanceof BuyHouse) {
  886. typeOfSpace = "Buy House";
  887. }
  888. else if(board.currentPlayer.space instanceof FirstSpace) {
  889. typeOfSpace = "First";
  890. }
  891. else if(board.currentPlayer.space instanceof Payday) {
  892. typeOfSpace = "Payday";
  893. }
  894. else if(board.currentPlayer.space instanceof SpinToWin) {
  895. typeOfSpace = "Spin to Win";
  896. }
  897. else if(board.currentPlayer.space instanceof BlankSpace) {
  898. typeOfSpace = "Blank";
  899. }
  900. else if(board.currentPlayer.space instanceof Port){
  901. typeOfSpace="Port";
  902. }
  903. else if(board.currentPlayer.space instanceof Airport){
  904. typeOfSpace= "Airport";
  905. }
  906. else if( board.currentPlayer.space instanceof ChooseCareerSpace){
  907. typeOfSpace= "Choose graduate career";
  908. }
  909. console.appendText(name + " landed on a " + typeOfSpace + " space!\n");
  910. }
  911.  
  912. // public void updateCar(){
  913. // if(board.currentPlayer.single == true){
  914. // board.currentPlayer.setImage(carImage);
  915. // } else if(board.currentPlayer.partner == true){
  916. // board.currentPlayer.setImage(partner);
  917. // } else if(board.currentPlayer.oneCh == true){
  918. // board.currentPlayer.setImage(oneCh);
  919. // } else if(board.currentPlayer.twoCh == true){
  920. // board.currentPlayer.setImage(twoCh);
  921. // } else if(board.currentPlayer.threeCh == true){
  922. // board.currentPlayer.setImage(threeCh);
  923. // } else if(board.currentPlayer.fourCh == true){
  924. // board.currentPlayer.setImage(fourCh);
  925. // } else if(board.currentPlayer.oneChOneP == true){
  926. // board.currentPlayer.setImage(oneChOneP);
  927. // } else if(board.currentPlayer.oneChTwoP == true){
  928. // board.currentPlayer.setImage(oneChTwoP);
  929. // } else if(board.currentPlayer.oneChThreeP == true){
  930. // board.currentPlayer.setImage(oneChThreeP);
  931. // } else if(board.currentPlayer.twoChOneP == true){
  932. // board.currentPlayer.setImage(twoChOneP);
  933. // } else if(board.currentPlayer.twoChTwoP == true){
  934. // board.currentPlayer.setImage(twoChTwoP);
  935. // } else if(board.currentPlayer.threeChOneP == true){
  936. // board.currentPlayer.setImage(threeChOneP);
  937. // } else if(board.currentPlayer.oneP == true){
  938. // board.currentPlayer.setImage(oneP);
  939. // } else if(board.currentPlayer.twoP == true){
  940. // board.currentPlayer.setImage(twoP);
  941. // } else if(board.currentPlayer.threeP == true){
  942. // board.currentPlayer.setImage(threeP);
  943. // } else if(board.currentPlayer.fourP == true){
  944. // board.currentPlayer.setImage(fourP);
  945. // }
  946. // }
  947.  
  948. public void updateJobTitle(){
  949. job.setText(board.currentPlayer.getJobTitle());
  950. };
  951.  
  952. public void retire(){
  953. new EndScreen(this, players);
  954. }
  955.  
  956. public void updateMinimap() {
  957. firstRow.getChildren().removeAll(map.getRoot(),stackPane);
  958. map.update(board);
  959. firstRow.getChildren().addAll(map.getRoot(), stackPane);
  960. }
  961. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement