Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.59 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.Optional;
  5.  
  6. import javafx.animation.RotateTransition;
  7. import javafx.application.Application;
  8. import javafx.beans.property.SimpleIntegerProperty;
  9. import javafx.collections.FXCollections;
  10. import javafx.collections.ObservableList;
  11. import javafx.geometry.Pos;
  12. import javafx.scene.Group;
  13. import javafx.scene.Scene;
  14. import javafx.scene.chart.PieChart;
  15. import javafx.scene.chart.PieChart.Data;
  16. import javafx.scene.control.Button;
  17. import javafx.scene.control.Label;
  18. import javafx.scene.control.Labeled;
  19. import javafx.scene.control.ListView;
  20. import javafx.scene.control.TextField;
  21. import javafx.scene.control.TextInputDialog;
  22. import javafx.scene.layout.BorderPane;
  23. import javafx.scene.layout.GridPane;
  24. import javafx.scene.layout.HBox;
  25. import javafx.scene.layout.StackPane;
  26. import javafx.scene.paint.Color;
  27. import javafx.scene.shape.Circle;
  28. import javafx.scene.shape.Rectangle;
  29. import javafx.scene.text.Text;
  30. import javafx.stage.Stage;
  31. import javafx.util.Duration;
  32.  
  33. public class Main extends Application {
  34.  
  35.     public static void main(String[] args) {
  36.         Application.launch(args);
  37.  
  38.     }
  39.  
  40.     public static int szansa = 3;
  41.     public static boolean check = true;
  42.     public static Label[] labelArr;
  43.     public static int suma=0;
  44.  
  45.     @Override
  46.     public void start(Stage primaryStage) throws Exception {
  47.  
  48.         Group root = new Group();
  49.         Scene scene = new Scene(root, 800, 600);
  50.         HBox hb = new HBox();
  51.         hb.setAlignment(Pos.CENTER);
  52.         hb.setSpacing(10);
  53.  
  54.         BorderPane bp = new BorderPane();
  55.         bp.setPrefSize(800, 600);
  56.  
  57.         ObservableList<String> opcje2 = FXCollections.observableArrayList();
  58.  
  59.         Button settings = new Button("Ustawienia");
  60.         bp.setLeft(settings);
  61.  
  62.         settings.setOnAction(e -> {
  63.             Stage stage = new Stage();
  64.             Group root1 = new Group();
  65.             Scene scene1 = new Scene(root1, 400, 400);
  66.  
  67.             GridPane gp = new GridPane();
  68.  
  69.             gp.setHgap(5);
  70.             gp.setVgap(5);
  71.  
  72.             ObservableList<String> opcje1 = FXCollections.observableArrayList();
  73.  
  74.             try {
  75.                 BufferedReader br = new BufferedReader(new FileReader("file.txt"));
  76.                 String sCurrentLine;
  77.  
  78.                 while ((sCurrentLine = br.readLine()) != null) {
  79.                     opcje1.add(sCurrentLine);
  80.                 }
  81.  
  82.             } catch (IOException exc) {
  83.                 exc.printStackTrace();
  84.             }
  85.  
  86.             ListView<String> list = new ListView<>(opcje1);
  87.             list.setPrefHeight(200);
  88.             list.setPrefWidth(200);
  89.             gp.add(list, 0, 1);
  90.  
  91.             ListView<String> list2 = new ListView<>(opcje2);
  92.             list2.setPrefHeight(200);
  93.             list2.setPrefWidth(200);
  94.             gp.add(list2, 1, 1);
  95.  
  96.             Button but = new Button(">");
  97.             but.setOnAction(f -> {
  98.                 String tmp = list.getSelectionModel().getSelectedItem();
  99.                 if (tmp != null) {
  100.                     list.getSelectionModel().clearSelection();
  101.                     opcje1.remove(tmp);
  102.                     opcje2.add(tmp);
  103.                 }
  104.  
  105.             });
  106.             gp.add(but, 1, 2);
  107.  
  108.             Button but2 = new Button("<");
  109.  
  110.             but2.setOnAction(f -> {
  111.                 String tmp = list2.getSelectionModel().getSelectedItem();
  112.  
  113.                 if (tmp != null) {
  114.                     list2.getSelectionModel().clearSelection();
  115.                     opcje2.remove(tmp);
  116.                     opcje1.add(tmp);
  117.                 }
  118.  
  119.             });
  120.  
  121.             gp.add(but2, 1, 3);
  122.  
  123.             TextField tField = new TextField();
  124.             gp.add(tField, 0, 4);
  125.  
  126.             Button addButton = new Button("Dodaj wyraz");
  127.             gp.add(addButton, 1, 4);
  128.  
  129.             addButton.setOnAction(f -> {
  130.                 if (tField.getText() != null)
  131.                     opcje1.add(tField.getText());
  132.             });
  133.  
  134.             root1.getChildren().add(gp);
  135.             stage.setScene(scene1);
  136.             stage.setTitle("Ustawienia");
  137.             stage.show();
  138.  
  139.         });
  140.         StackPane layout = new StackPane();
  141.        
  142.        
  143.           Circle circle = new Circle();
  144.           circle.setCenterX(300.0f);
  145.           circle.setCenterY(135.0f);
  146.           circle.setRadius(180.0f);
  147.           circle.setFill(Color.AQUA);
  148.        
  149.           Label label = new Label("2");
  150.           Label label2 = new Label("4");
  151.        
  152.        
  153.           label.setTranslateX(0);
  154.           label.setTranslateY(-160);
  155.  
  156.          
  157.  
  158.           label2.setTranslateX(105.801);
  159.           label2.setTranslateY(145.623);
  160.           RotateTransition rt=new RotateTransition(Duration.millis(5),layout);
  161.           rt.setByAngle(72);
  162.          
  163.          
  164.        
  165.         Text text1 = new Text("45");
  166.    
  167.         layout.getChildren().addAll(circle, label,label2);
  168.        
  169.         bp.setCenter(layout);
  170.  
  171.         Label wynik=new Label();
  172.        
  173.         bp.setRight(wynik);
  174.        
  175.         Button b = new Button("Kręć");
  176.         b.setOnAction(f -> {
  177.            
  178.             System.out.println(label.getTranslateX());
  179.               System.out.println(label.getTranslateY());
  180.        
  181.             rt.play();
  182.        
  183.         int nagroda=(int) (Math.random()*900+100);
  184.            
  185.             if (opcje2.size() != 0 && check==true) {
  186.            
  187.                 int a = (int) (Math.random() * opcje2.size());
  188.                 String los = opcje2.get(a);
  189.                 char[] arr = los.toCharArray();
  190.                 labelArr = new Label[arr.length];
  191.  
  192.                
  193.  
  194.                     for (int i = 0; i < arr.length; i++) {
  195.                         Rectangle r = new Rectangle(30, 30);
  196.                         r.setFill(Color.ORANGE);
  197.                         StackPane stack = new StackPane();
  198.  
  199.                         Label l = new Label(Character.toString(arr[i]));
  200.                         labelArr[i] = l;
  201.  
  202.                         stack.getChildren().addAll(r, l);
  203.                         hb.getChildren().add(stack);
  204.  
  205.                         l.setVisible(false);
  206.                         check=false;
  207.  
  208.                     }
  209.                    
  210.             }
  211.  
  212.                 if(szansa != 0 && opcje2.size()>0) {
  213.  
  214.                     TextInputDialog dialog = new TextInputDialog();
  215.                     dialog.setHeaderText("Podaj literę");
  216.                     Optional<String> result = dialog.showAndWait();
  217.                     int licznik = 0;
  218.  
  219.                     for (int i = 0; i < labelArr.length; i++) {
  220.  
  221.                         if (result.get().equals(labelArr[i].getText())) {
  222.                             System.out.println("jest :)");
  223.                             labelArr[i].setVisible(true);
  224.                             suma+=nagroda;
  225.                             System.out.println(suma);
  226.                         } else
  227.                             licznik++;
  228.                     }
  229.  
  230.                     if (czyKoniec(labelArr) == 1) {
  231.                         System.out.println("wygrales");
  232.                         return;
  233.                     }
  234.  
  235.                     if (licznik == labelArr.length) {
  236.                         szansa--;
  237.                         System.out.println(szansa);
  238.  
  239.                     }
  240.                     wynik.textProperty().bind(new SimpleIntegerProperty(suma).asString());
  241.  
  242.                 }
  243.            
  244.  
  245.         });
  246.  
  247.         // Label iloscSzans=new Label("Ilosc szans"+ szansa);
  248.         // bp.setRight(iloscSzans);
  249.         bp.setTop(hb);
  250.         bp.setBottom(b);
  251.         bp.setAlignment(b, Pos.CENTER);
  252.  
  253.         root.getChildren().add(bp);
  254.         primaryStage.setScene(scene);
  255.         primaryStage.setTitle("Fortune Wheel");
  256.         primaryStage.show();
  257.     }
  258.  
  259.     int czyKoniec(Label[] arr) {
  260.         int licznik = 0;
  261.         for (int i = 0; i < arr.length; i++) {
  262.             if (arr[i].isVisible() == true) {
  263.                 licznik++;
  264.             }
  265.  
  266.         }
  267.         if (licznik == arr.length) {
  268.             return 1;
  269.         } else
  270.             return 0;
  271.     }
  272.  
  273.     /*
  274.      * int czyKoniec2(Label[] arr) { for(int i=0;i<arr.length;i++) {
  275.      * if(arr[i].isVisible()==true) return 1; } return 0; }
  276.      */ // ta nie dziala.
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement