Advertisement
Guest User

MathGame v2

a guest
Jul 4th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.43 KB | None | 0 0
  1.  
  2. package Math.Game1;
  3. import java.io.IOException;
  4. import java.nio.charset.Charset;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import java.util.List;
  10. import javafx.animation.*;
  11. import javafx.util.*;
  12. import java.util.*;
  13. import javafx.scene.text.Font;
  14. import javafx.scene.text.Text;
  15. import javafx.scene.input.MouseEvent;
  16. import javafx.scene.input.DragEvent;
  17. import static java.time.Clock.system;
  18. import javafx.animation.KeyFrame;
  19. import javafx.application.Application;
  20. import javafx.event.ActionEvent;
  21. import javafx.event.EventHandler;
  22. import javafx.scene.Cursor;
  23. import javafx.scene.Scene;
  24. import javafx.scene.Group;
  25. import javafx.scene.Node;
  26. import javafx.scene.control.Button;
  27. import javafx.scene.control.*;
  28. import javafx.scene.input.InputMethodEvent;
  29. import javafx.scene.layout.HBox;
  30. import javafx.scene.layout.StackPane;
  31. import javafx.scene.layout.VBox;
  32. import javafx.stage.Stage;
  33. import javafx.scene.shape.Line;
  34. import javafx.scene.shape.Shape;
  35. import javafx.scene.shape.Circle;
  36. import javafx.scene.text.Text;
  37. import javafx.scene.paint.Color;
  38. import javafx.scene.paint.Paint;
  39. import javafx.scene.shape.Rectangle;
  40. import javafx.scene.text.Font;
  41. import javafx.stage.Modality;
  42. import javafx.util.Duration;
  43. import static sun.net.www.http.HttpClient.New;
  44.  
  45. /**
  46. *
  47. * @author Craig
  48. */
  49.  
  50. public class MathGame1 extends Application {
  51.  
  52. private static final int CIRCLES_NUMBER = 5;
  53. private static final int CIRCLE_RADIUS = 50;
  54. private static final double WINDOW_WIDTH = 600;
  55. private static final double WINDOW_HEIGHT = 400;
  56. private static final double LINE_OFFSET = 50;
  57. private static final String CIRCLE_ID = "Circle";
  58. private static final String TEXT_ID = "Text";
  59. private static final String LINE_ID = "Line";
  60. int clockTime;
  61. //Customizable Cirlce Strings
  62. int C0;
  63. int C1;
  64. int C2;
  65. int C3;
  66. int C4;
  67.  
  68. ArrayList<String> listOfStrings;
  69. boolean level_1;
  70. boolean level_2;
  71. boolean level_3;
  72. boolean countDown;
  73. boolean timerOn;
  74. Timeline timeLine;
  75.  
  76. Scene startScene;
  77. Scene editScene;
  78. Scene gameScene;
  79. Scene instrucScene1;
  80. Scene game1Scene;
  81. Scene game2Scene;
  82. Scene instructScene2;
  83. Scene gameModeSelect;
  84. //Start Screen
  85. Stage stage;
  86. //Editing Screen
  87. Stage stage2;
  88. //OG game Screen
  89. Stage stage3;
  90. //instruction 1 screen
  91. Stage stage4;
  92. //Count down Version
  93. Stage stage5;
  94. //intruction 2
  95. Stage stage6;
  96. //game select screen
  97. Stage stage7;
  98. @Override
  99. public void start(Stage primaryStage) {
  100. C0 = 1;
  101. C1 = 2;
  102. C2 = 3;
  103. C3 = 4;
  104. C4 = 5;
  105. stage3 = primaryStage;
  106. level_1 = true;
  107. startScreen();
  108.  
  109. System.out.println("job done");
  110.  
  111. }
  112. private void startScreen(){
  113. // Game Title
  114. Text gameTitle = new Text();
  115. gameTitle.setText("Mr.Baker's Education Fun House :D");
  116. gameTitle.setFill(Color.DEEPPINK);
  117. gameTitle.setFont(Font.font("Guardians", 9));
  118. gameTitle.setX(10);
  119. gameTitle.setY(10);
  120. //Start Problem
  121. Button buttonPlay = new Button();
  122. buttonPlay.setText("Play Standard Mode");
  123. buttonPlay.setOnAction(e -> buttonPlay_Click());
  124. buttonPlay.setLayoutX(30);
  125. buttonPlay.setLayoutY(30);
  126.  
  127. Button buttonPlayC = new Button();
  128. buttonPlayC.setText("Play Countdown Mode");
  129. buttonPlayC.setOnAction(e -> buttonPlayC_Click());
  130. buttonPlayC.setLayoutX(200);
  131. buttonPlayC.setLayoutY(30);
  132.  
  133. Button buttoninstruc1 = new Button();
  134. buttoninstruc1.setText("Instructions");
  135. buttoninstruc1.setOnAction(e -> buttoninstruc1_Click());
  136. buttoninstruc1.setLayoutX(100);
  137. buttoninstruc1.setLayoutY(30);
  138.  
  139. VBox pane1 = new VBox(10);
  140. pane1.getChildren().addAll(gameTitle,buttonPlay,buttonPlayC,buttoninstruc1);
  141.  
  142. //Starting Screen
  143. startScene = new Scene(pane1,300,300);
  144. stage = new Stage();
  145. stage.setScene(startScene);
  146. stage.show();
  147.  
  148. }
  149.  
  150. Button buttonOK;
  151. /* private void createEditScreen() {
  152. System.out.println("Create Edit Screen: " + Boolean.toString(true));
  153.  
  154. //Editing Scene
  155. C0 = new TextField();
  156. C0.setPrefColumnCount(20);
  157. C0.setPromptText("Set Circle 0's Value");
  158. C0.setOnInputMethodTextChanged(textEntered);
  159. C0.setOnAction(textAction);
  160. C0.setOnKeyReleased(e -> { System.out.println("Key Released: " + Boolean.toString(true));});
  161.  
  162. C1 = new TextField();
  163. C1.setPrefColumnCount(20);
  164. C1.setPromptText("Set Circle 1's Value");
  165. C1.setOnInputMethodTextChanged(textEntered);
  166. C1.setOnAction(textAction);
  167.  
  168. C2 = new TextField();
  169. C2.setPrefColumnCount(20);
  170. C2.setPromptText("Set Circle 2's Value");
  171. C2.setOnInputMethodTextChanged(textEntered);
  172. C2.setOnAction(textAction);
  173.  
  174. C3 = new TextField();
  175. C3.setPrefColumnCount(20);
  176. C3.setPromptText("Set Circle 3's Value");
  177. C3.setOnInputMethodTextChanged(textEntered);
  178. C3.setOnAction(textAction);
  179.  
  180. C4 = new TextField();
  181. C4.setPrefColumnCount(20);
  182. C4.setPromptText("Set Circle 4's Value");
  183. C4.setOnInputMethodTextChanged(textEntered);
  184. C4.setOnAction(textAction);
  185.  
  186. Button buttonLF = new Button();
  187. buttonLF.setText("Load From File");
  188. buttonLF.setOnAction(e -> buttonLF_Click());
  189. buttonLF.setLayoutX(30);
  190. buttonLF.setLayoutY(100);
  191. buttonLF.setDisable(false);
  192.  
  193. buttonOK = new Button();
  194. buttonOK.setText("Ok");
  195. buttonOK.setOnAction(e -> buttonOK_Click());
  196. buttonOK.setLayoutX(30);
  197. buttonOK.setLayoutY(30);
  198. buttonOK.setDisable(false);
  199.  
  200. Button buttonB = new Button();
  201. buttonB.setText("Back");
  202. buttonB.setOnAction(e -> buttonB_Click());
  203. buttonB.setLayoutX(30);
  204. buttonB.setLayoutY(200);
  205. buttonB.setDisable(false);
  206.  
  207. VBox pane2 = new VBox(20);
  208. editScene = new Scene(pane2,500,500);
  209. stage2 = new Stage();
  210. stage2.setScene(editScene);
  211. pane2.getChildren().addAll(C0,C1,C2,C3,C4,buttonOK,buttonB,buttonLF);
  212. stage2.show();
  213.  
  214. }*/
  215.  
  216. EventHandler< InputMethodEvent > textEntered =
  217. new EventHandler< InputMethodEvent >() {
  218.  
  219. @Override
  220. public void handle(InputMethodEvent t) {
  221.  
  222. boolean allDataEntered = true;
  223.  
  224. // if (C0.getText().isEmpty())
  225. allDataEntered = false;
  226.  
  227. // if (C1.getText().isEmpty())
  228. allDataEntered = false;
  229.  
  230. // if (C2.getText().isEmpty())
  231. allDataEntered = false;
  232.  
  233. // if (C3.getText().isEmpty())
  234. allDataEntered = false;
  235.  
  236. // if (C4.getText().isEmpty())
  237. allDataEntered = false;
  238.  
  239. System.out.println("Text Entered: " + Boolean.toString(allDataEntered));
  240.  
  241. buttonOK.setDisable(!allDataEntered);
  242. }
  243. };
  244.  
  245. EventHandler< ActionEvent > textAction =
  246. new EventHandler< ActionEvent >() {
  247.  
  248. @Override
  249. public void handle(ActionEvent t) {
  250.  
  251. boolean allDataEntered = true;
  252.  
  253. // if (C0.getText().isEmpty())
  254. allDataEntered = false;
  255.  
  256. // if (C1.getText().isEmpty())
  257. allDataEntered = false;
  258.  
  259. // if (C2.getText().isEmpty())
  260. allDataEntered = false;
  261.  
  262. // if (C3.getText().isEmpty())
  263. allDataEntered = false;
  264.  
  265. // if (C4.getText().isEmpty())
  266. allDataEntered = false;
  267.  
  268. System.out.println("Text Action: " + Boolean.toString(allDataEntered));
  269.  
  270. buttonOK.setDisable(!allDataEntered);
  271. }
  272. };
  273. private void jepordyGame(){
  274. Rectangle r = new Rectangle();
  275. r.setX(0);
  276. r.setY(0);
  277. r.setWidth(50);
  278. r.setHeight(50);
  279.  
  280.  
  281. }
  282. private void createTimedBallGame(){
  283. listOfStrings = new ArrayList<String>();
  284. listOfStrings.add("1");
  285. listOfStrings.add("2");
  286. listOfStrings.add("3");
  287. listOfStrings.add("4");
  288. listOfStrings.add("5");
  289.  
  290. if (countDown == true)
  291. clockTime = 20;
  292. else
  293. clockTime = 0;
  294.  
  295.  
  296.  
  297. timerOn = true;
  298.  
  299. Group group = new Group();
  300. Scene scene = new Scene(group);
  301. stage3.setHeight(WINDOW_HEIGHT);
  302. stage3.setWidth(WINDOW_WIDTH);
  303. stage3.setTitle("Line Up - Put the balls in order from smallest to largest");
  304. stage3.setResizable(false);
  305. Text texttime = new Text();
  306. Rectangle r = new Rectangle();
  307. r.setX(0);
  308. r.setY(0);
  309. r.setWidth(50);
  310. r.setHeight(50);
  311.  
  312.  
  313. texttime.setText("Start");
  314. texttime.setFill(Color.ORANGE);
  315. texttime.setFont(Font.font ("Verdana", 20));
  316. texttime.setX(10);
  317. texttime.setY(30);
  318. System.out.println("Text");
  319. texttime.setId("Timer");
  320.  
  321. // primaryStage.initModality(Modality.APPLICATION_MODAL);
  322.  
  323. KeyFrame k = new KeyFrame(Duration.seconds(1),
  324. e-> {
  325. if (timerOn == true){
  326. if (countDown)
  327. clockTime = clockTime - 1;
  328. else
  329. clockTime = clockTime + 1;
  330.  
  331. if (countDown && clockTime <= 0){
  332. // game over
  333. clockTime = 0;
  334. timerOn = false;
  335. texttime.setText("Game Over");
  336. gameOver(group);
  337. }
  338. else {
  339. texttime.setText(Integer.toString(clockTime));
  340. }
  341. }
  342. });
  343.  
  344. timerOn = true;
  345. timeLine = new Timeline(k);
  346. timeLine.setCycleCount(Timeline.INDEFINITE);
  347. timeLine.play();
  348. if (level_2 == true) {
  349. listOfStrings.clear();
  350. listOfStrings.add("1/2");
  351. listOfStrings.add("3/4");
  352. listOfStrings.add("5/7");
  353. listOfStrings.add("3/2");
  354. listOfStrings.add("7/4");
  355.  
  356.  
  357. }
  358. else if(level_3 == true){
  359. listOfStrings.clear();
  360. listOfStrings.add(".2");
  361. listOfStrings.add("1/2");
  362. listOfStrings.add(".6");
  363. listOfStrings.add("3/4");
  364. listOfStrings.add("4/5");
  365. }
  366.  
  367. group.getChildren().addAll(texttime);
  368. for(int i=0; i < CIRCLES_NUMBER; i++){
  369. Circle circle = new Circle();
  370. Color c = new Color(Math.random(),Math.random(),Math.random(),1.0);
  371. circle.setFill(c);
  372. circle.setCenterX((WINDOW_WIDTH-LINE_OFFSET-2*CIRCLE_RADIUS)*Math.random()+CIRCLE_RADIUS);
  373. circle.setCenterY((WINDOW_HEIGHT-LINE_OFFSET-2*CIRCLE_RADIUS)*Math.random()+CIRCLE_RADIUS);
  374. circle.setRadius(CIRCLE_RADIUS);
  375. circle.setCursor(Cursor.HAND);
  376.  
  377. circle.setOnMouseDragged(circleOnMouseDraggedEventHandler);
  378. circle.setOnDragDropped(circleOnDragDroppedEventHandler);
  379. circle.setId(CIRCLE_ID + Integer.toString(i));
  380.  
  381. Text text = new Text();
  382. text.setText(listOfStrings.get(i));
  383. text.setFill(c.invert());
  384. text.setFont(Font.font ("Verdana", 20));
  385. text.setX(circle.getCenterX());
  386. text.setY(circle.getCenterY());
  387. text.setId(TEXT_ID + Integer.toString(i));
  388.  
  389. group.getChildren().addAll(circle, text);
  390.  
  391. System.out.println("Button: " + Integer.toString(i));
  392. System.out.println("Size: " + Integer.toString(group.getChildren().size()));
  393.  
  394. }
  395.  
  396. Line line = new Line();
  397. line.setStartX(LINE_OFFSET);
  398. line.setStartY(WINDOW_HEIGHT-LINE_OFFSET);
  399. line.setEndX(WINDOW_WIDTH-LINE_OFFSET);
  400. line.setEndY(WINDOW_HEIGHT-LINE_OFFSET);
  401. line.setStrokeWidth(15);
  402. line.setStroke(Color.AQUA);
  403. line.setCursor(Cursor.OPEN_HAND);
  404. line.setOnMouseDragReleased(lineOnMouseDragReleasedEventHandler);
  405. line.setOnDragDropped(lineOnDragDroppedEventHandler);
  406. line.setOnDragEntered(lineOnDragEnteredEventHandler);
  407. line.setId(LINE_ID);
  408.  
  409. group.getChildren().add(line);
  410. group.setId("Scene Group");
  411.  
  412. System.out.println("Final Size: " + Integer.toString(group.getChildren().size()));
  413.  
  414. stage3.setScene(scene);
  415. stage3.show();
  416.  
  417. }
  418.  
  419. /**
  420. * @param args the command line arguments
  421. */
  422. public static void main(String[] args) {
  423. launch(args);
  424.  
  425. }
  426. public void buttoninstruc1_Click(){
  427. stage.close();
  428. Text instruc1 = new Text();
  429. instruc1.setText("STANDARD MODE\n"
  430. + "1.Add in desired sequence\n"
  431. + "2.put each cirlce in order\n"
  432. + "3.Press Play Again to play again or press quit to exit\n"
  433. + "\n"
  434. + "\n"
  435. + "COUNTDOWN MODE\n"
  436. + "1. Add in desired sequence\n"
  437. + "2.put each circle in order before time runs out\n"
  438. + "3.Press Play Again to play again or pres quit to exit the game\n"
  439. + "\n\n");
  440. Button buttonBack1 = new Button();
  441. buttonBack1.setText("Back");
  442. buttonBack1.setOnAction(e -> buttonBack1_Click());
  443. buttonBack1.setLayoutX(30);
  444. buttonBack1.setLayoutY(30);
  445. VBox pane3 = new VBox();
  446. instrucScene1 = new Scene(pane3, 500, 500);
  447. stage4 = new Stage();
  448. stage4.setScene(instrucScene1);
  449. pane3.getChildren().addAll(instruc1,buttonBack1);
  450. stage4.show();
  451. }
  452. public void buttonOK_Click(){
  453. stage2.close();
  454. createTimedBallGame();
  455. }
  456.  
  457. public void buttonPlay_Click(){
  458. stage.close();
  459. countDown = false;
  460. createTimedBallGame();
  461.  
  462. }
  463. public void buttonPlayC_Click(){
  464. stage.close();
  465. countDown = true;
  466. createTimedBallGame();
  467. }
  468. public void buttonBack1_Click(){
  469. stage4.close();
  470. startScreen();
  471. }
  472.  
  473. public void buttonB_Click(){
  474. stage2.close();
  475. startScreen();
  476. }
  477.  
  478.  
  479. /* public void buttonLF_Click(){
  480. List<String> levels = new ArrayList<>();
  481. try {
  482. levels = Files.readAllLines(Paths.get("levels.txt"),Charset.defaultCharset());
  483. }
  484. catch(IOException e ) {
  485. e.printStackTrace();
  486. }
  487.  
  488. C0.setText(C0);
  489. C1.setText("2");
  490. C2.setText(levels.get(2));
  491. C3.setText(levels.get(3));
  492. C4.setText(levels.get(4));
  493.  
  494. }
  495. */
  496.  
  497. EventHandler<MouseEvent> circleOnMouseDraggedEventHandler =
  498. new EventHandler<MouseEvent>() {
  499.  
  500. @Override
  501. public void handle(MouseEvent t) {
  502. if (!timerOn)
  503. return;
  504.  
  505. double newX = t.getX();
  506. double newY = t.getY();
  507.  
  508. Circle myCircle = (Circle)(t.getSource());
  509. Group myGroup = (Group)myCircle.getParent();
  510. //check for collsion with borders
  511.  
  512. if (newX < myCircle.getRadius()) {
  513. newX = myCircle.getRadius();
  514. }
  515.  
  516. if (newY < myCircle.getRadius()) {
  517. newY = myCircle.getRadius();
  518. }
  519.  
  520. if (myCircle.getRadius() + newX > WINDOW_WIDTH) {
  521. newX = WINDOW_WIDTH - myCircle.getRadius();
  522. }
  523.  
  524.  
  525. // check for collision with line
  526. Line myLine = (Line)myGroup.lookup("#"+LINE_ID);
  527. if (myLine == null){
  528. System.out.println("Circle Dragged Event - Line Node not found! ");
  529. }
  530. else {
  531. // detect collision with line
  532. if (myCircle.getRadius() + newY > myLine.getEndY()) {
  533. System.out.println("Circle collision + with line!");
  534. newY = myLine.getEndY() - myCircle.getRadius();
  535. }
  536. }
  537.  
  538. myCircle.setCenterX(newX);
  539. myCircle.setCenterY(newY);
  540.  
  541. // find the text for the circle
  542. String myCircleId = myCircle.getId();
  543. String myTextId = TEXT_ID + myCircleId.substring(myCircleId.length()-1);
  544. Text myText = (Text)myGroup.lookup("#"+ myTextId);
  545. if (myText != null) {
  546. myText.setX(newX);
  547. myText.setY(newY);
  548. }
  549. else {
  550. System.out.println("Circle Dragged Event - Text Node not found: " + myTextId);
  551. }
  552.  
  553. System.out.println("Circle Y Translate: " + Double.toString(newY));
  554. System.out.println("Circle Y: " + Double.toString(myCircle.getCenterY() + myCircle.getRadius()));
  555. System.out.println("Line Y: " + Double.toString(myLine.getEndY() - myLine.getStrokeWidth()));
  556.  
  557. //System.out.println("Circle Dragged Event " + myCircleId);
  558. //System.out.println("Circle Dragged Event " + myTextId);
  559. //System.out.println("Circle Dragged Event " + myGroup.getId());
  560. //System.out.println("Group Size: " + Integer.toString(myGroup.getChildren().size()));
  561.  
  562. //check if all balls are on the line
  563. boolean allOnLine = true;
  564. for (Node node: myGroup.getChildren()) {
  565. if (node != null) {
  566. if (node.getId() != null) {
  567. if (node.getId().startsWith(CIRCLE_ID)) {
  568. // see if circle is on the line
  569. myCircle = (Circle) node;
  570. if (myCircle.getRadius() + myCircle.getCenterY() >= myLine.getEndY()) {
  571. // on the line
  572. allOnLine = true;
  573. }
  574. else {
  575. allOnLine = false;
  576. break;
  577. }
  578. }
  579. }
  580. }
  581. }
  582.  
  583. double CircleCX0 = 0;
  584. myCircle = (Circle)myGroup.lookup("#"+CIRCLE_ID + "0");
  585. if (myCircle == null){
  586. System.out.println("Could not find circle 0");
  587. }else{
  588.  
  589. CircleCX0 = myCircle.getCenterX();
  590. }
  591.  
  592. double CircleCX1 = 0;
  593. myCircle = (Circle)myGroup.lookup("#"+CIRCLE_ID + "1");
  594. if (myCircle == null){
  595. System.out.println("Could not find circle 1");
  596. }else{
  597.  
  598. CircleCX1 = myCircle.getCenterX();
  599. }
  600. double CircleCX2 = 0;
  601. myCircle = (Circle)myGroup.lookup("#"+CIRCLE_ID + "2");
  602. if (myCircle == null){
  603. System.out.println("Could not find circle 2");
  604. }else{
  605.  
  606. CircleCX2 = myCircle.getCenterX();
  607. }
  608. double CircleCX3 = 0;
  609. myCircle = (Circle)myGroup.lookup("#"+CIRCLE_ID + "3");
  610. if (myCircle == null){
  611. System.out.println("Could not find circle 3");
  612. }else{
  613.  
  614. CircleCX3 = myCircle.getCenterX();
  615. }
  616. double CircleCX4 = 0;
  617. myCircle = (Circle)myGroup.lookup("#"+CIRCLE_ID + "4");
  618. if (myCircle == null){
  619. System.out.println("Could not find circle 4");
  620. }else{
  621.  
  622. CircleCX4 = myCircle.getCenterX();
  623. }
  624.  
  625. if (allOnLine){
  626. if (CircleCX0 < CircleCX1){
  627. if(CircleCX1 < CircleCX2){
  628. if(CircleCX2 < CircleCX3){
  629. if(CircleCX3 < CircleCX4){
  630. gameOver(myGroup);
  631.  
  632. }
  633. }
  634. }
  635. }
  636.  
  637. }
  638. }
  639.  
  640. };
  641.  
  642.  
  643. public void gameOver(Group myGroup) {
  644.  
  645. Text textComplete = new Text();
  646. textComplete.setText("");
  647. if (!countDown) {
  648. textComplete.setText("YOU DID IT!");
  649. textComplete.setFont(new Font("Guardians",36));
  650. textComplete.setX(50);
  651. textComplete.setY(50);
  652. System.out.println("You did it");
  653. myGroup.getChildren().addAll(textComplete);
  654.  
  655. }
  656.  
  657. timerOn = false;
  658. timeLine.stop();
  659. if(level_2 == true){
  660. Button buttonNextLevel = new Button();
  661. buttonNextLevel.setText("Next Level");
  662. buttonNextLevel.setOnAction(e -> buttonNextLevel_Click());
  663. buttonNextLevel.setLayoutX(30);
  664. buttonNextLevel.setLayoutY(100);
  665. Button buttonQuit = new Button();
  666. buttonQuit.setText("Quit");
  667. buttonQuit.setOnAction(e -> buttonQuit_Click());
  668. buttonQuit.setLayoutX(120);
  669. buttonQuit.setLayoutY(100);
  670. myGroup.getChildren().addAll(buttonNextLevel,buttonQuit);
  671. System.out.println("Level 2 to 3");
  672. }else if(level_1 == true){
  673. Button buttonNextLevel = new Button();
  674. buttonNextLevel.setText("Next Level");
  675. buttonNextLevel.setOnAction(e -> buttonNextLevel_Click());
  676. buttonNextLevel.setLayoutX(30);
  677. buttonNextLevel.setLayoutY(100);
  678. Button buttonQuit = new Button();
  679. buttonQuit.setText("Quit");
  680. buttonQuit.setOnAction(e -> buttonQuit_Click());
  681. buttonQuit.setLayoutX(120);
  682. buttonQuit.setLayoutY(100);
  683. myGroup.getChildren().addAll(buttonNextLevel,buttonQuit);
  684. System.out.println("Level 1 to 2");
  685. }
  686. else if (level_3 == true){
  687. Button buttonQuit = new Button();
  688. buttonQuit.setText("Quit");
  689. buttonQuit.setOnAction(e -> buttonQuit_Click());
  690. buttonQuit.setLayoutX(120);
  691. buttonQuit.setLayoutY(100);
  692. myGroup.getChildren().add(buttonQuit);
  693. System.out.println("End Game");
  694. }
  695.  
  696.  
  697. }
  698. public void buttonNextLevel_Click(){
  699. stage3.close();
  700. if(level_2 == true){
  701. level_3 = true;
  702. level_2 = false;
  703. level_1 = false;
  704. }
  705. else if(level_1 == true){
  706. level_2 = true;
  707. level_1 = false;
  708. level_3 = false;
  709. }
  710.  
  711. createTimedBallGame();
  712. }
  713. public void buttonQuit_Click(){
  714. stage3.close();
  715.  
  716. }
  717.  
  718. EventHandler<DragEvent> circleOnDragDroppedEventHandler =
  719. new EventHandler<DragEvent>() {
  720.  
  721. @Override
  722. public void handle(DragEvent t) {
  723.  
  724. // ((Line)(t.getSource())).setStroke(Color.BROWN);
  725. System.out.println("Circle Drag Dropped");
  726. }
  727. };
  728.  
  729. EventHandler<DragEvent> lineOnDragDroppedEventHandler =
  730. new EventHandler<DragEvent>() {
  731.  
  732. @Override
  733. public void handle(DragEvent t) {
  734.  
  735. // ((Line)(t.getSource())).setStroke(Color.BROWN);
  736. System.out.println("Line Drag Dropped");
  737. }
  738. };
  739.  
  740. EventHandler<DragEvent> lineOnDragEnteredEventHandler =
  741. new EventHandler<DragEvent>() {
  742.  
  743. @Override
  744. public void handle(DragEvent t) {
  745.  
  746. // ((Line)(t.getSource())).setStroke(Color.BROWN);
  747. System.out.println("Line Drag Entered");
  748. }
  749. };
  750.  
  751.  
  752. EventHandler<MouseEvent> lineOnMouseDragReleasedEventHandler =
  753. new EventHandler<MouseEvent>() {
  754.  
  755. @Override
  756. public void handle(MouseEvent t) {
  757.  
  758. ((Line)(t.getSource())).setStroke(Color.BROWN);
  759. System.out.println("Line Drag Release");
  760. }
  761. };
  762.  
  763. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement