Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Optional;
- import javafx.animation.RotateTransition;
- import javafx.application.Application;
- import javafx.beans.property.SimpleIntegerProperty;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.geometry.Pos;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.chart.PieChart;
- import javafx.scene.chart.PieChart.Data;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.Labeled;
- import javafx.scene.control.ListView;
- import javafx.scene.control.TextField;
- import javafx.scene.control.TextInputDialog;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Circle;
- import javafx.scene.shape.Rectangle;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- import javafx.util.Duration;
- public class Main extends Application {
- public static void main(String[] args) {
- Application.launch(args);
- }
- public static int szansa = 3;
- public static boolean check = true;
- public static Label[] labelArr;
- public static int suma=0;
- @Override
- public void start(Stage primaryStage) throws Exception {
- Group root = new Group();
- Scene scene = new Scene(root, 800, 600);
- HBox hb = new HBox();
- hb.setAlignment(Pos.CENTER);
- hb.setSpacing(10);
- BorderPane bp = new BorderPane();
- bp.setPrefSize(800, 600);
- ObservableList<String> opcje2 = FXCollections.observableArrayList();
- Button settings = new Button("Ustawienia");
- bp.setLeft(settings);
- settings.setOnAction(e -> {
- Stage stage = new Stage();
- Group root1 = new Group();
- Scene scene1 = new Scene(root1, 400, 400);
- GridPane gp = new GridPane();
- gp.setHgap(5);
- gp.setVgap(5);
- ObservableList<String> opcje1 = FXCollections.observableArrayList();
- try {
- BufferedReader br = new BufferedReader(new FileReader("file.txt"));
- String sCurrentLine;
- while ((sCurrentLine = br.readLine()) != null) {
- opcje1.add(sCurrentLine);
- }
- } catch (IOException exc) {
- exc.printStackTrace();
- }
- ListView<String> list = new ListView<>(opcje1);
- list.setPrefHeight(200);
- list.setPrefWidth(200);
- gp.add(list, 0, 1);
- ListView<String> list2 = new ListView<>(opcje2);
- list2.setPrefHeight(200);
- list2.setPrefWidth(200);
- gp.add(list2, 1, 1);
- Button but = new Button(">");
- but.setOnAction(f -> {
- String tmp = list.getSelectionModel().getSelectedItem();
- if (tmp != null) {
- list.getSelectionModel().clearSelection();
- opcje1.remove(tmp);
- opcje2.add(tmp);
- }
- });
- gp.add(but, 1, 2);
- Button but2 = new Button("<");
- but2.setOnAction(f -> {
- String tmp = list2.getSelectionModel().getSelectedItem();
- if (tmp != null) {
- list2.getSelectionModel().clearSelection();
- opcje2.remove(tmp);
- opcje1.add(tmp);
- }
- });
- gp.add(but2, 1, 3);
- TextField tField = new TextField();
- gp.add(tField, 0, 4);
- Button addButton = new Button("Dodaj wyraz");
- gp.add(addButton, 1, 4);
- addButton.setOnAction(f -> {
- if (tField.getText() != null)
- opcje1.add(tField.getText());
- });
- root1.getChildren().add(gp);
- stage.setScene(scene1);
- stage.setTitle("Ustawienia");
- stage.show();
- });
- StackPane layout = new StackPane();
- Circle circle = new Circle();
- circle.setCenterX(300.0f);
- circle.setCenterY(135.0f);
- circle.setRadius(180.0f);
- circle.setFill(Color.AQUA);
- Label label = new Label("2");
- Label label2 = new Label("4");
- label.setTranslateX(0);
- label.setTranslateY(-160);
- label2.setTranslateX(105.801);
- label2.setTranslateY(145.623);
- RotateTransition rt=new RotateTransition(Duration.millis(5),layout);
- rt.setByAngle(72);
- Text text1 = new Text("45");
- layout.getChildren().addAll(circle, label,label2);
- bp.setCenter(layout);
- Label wynik=new Label();
- bp.setRight(wynik);
- Button b = new Button("Kręć");
- b.setOnAction(f -> {
- System.out.println(label.getTranslateX());
- System.out.println(label.getTranslateY());
- rt.play();
- int nagroda=(int) (Math.random()*900+100);
- if (opcje2.size() != 0 && check==true) {
- int a = (int) (Math.random() * opcje2.size());
- String los = opcje2.get(a);
- char[] arr = los.toCharArray();
- labelArr = new Label[arr.length];
- for (int i = 0; i < arr.length; i++) {
- Rectangle r = new Rectangle(30, 30);
- r.setFill(Color.ORANGE);
- StackPane stack = new StackPane();
- Label l = new Label(Character.toString(arr[i]));
- labelArr[i] = l;
- stack.getChildren().addAll(r, l);
- hb.getChildren().add(stack);
- l.setVisible(false);
- check=false;
- }
- }
- if(szansa != 0 && opcje2.size()>0) {
- TextInputDialog dialog = new TextInputDialog();
- dialog.setHeaderText("Podaj literę");
- Optional<String> result = dialog.showAndWait();
- int licznik = 0;
- for (int i = 0; i < labelArr.length; i++) {
- if (result.get().equals(labelArr[i].getText())) {
- System.out.println("jest :)");
- labelArr[i].setVisible(true);
- suma+=nagroda;
- System.out.println(suma);
- } else
- licznik++;
- }
- if (czyKoniec(labelArr) == 1) {
- System.out.println("wygrales");
- return;
- }
- if (licznik == labelArr.length) {
- szansa--;
- System.out.println(szansa);
- }
- wynik.textProperty().bind(new SimpleIntegerProperty(suma).asString());
- }
- });
- // Label iloscSzans=new Label("Ilosc szans"+ szansa);
- // bp.setRight(iloscSzans);
- bp.setTop(hb);
- bp.setBottom(b);
- bp.setAlignment(b, Pos.CENTER);
- root.getChildren().add(bp);
- primaryStage.setScene(scene);
- primaryStage.setTitle("Fortune Wheel");
- primaryStage.show();
- }
- int czyKoniec(Label[] arr) {
- int licznik = 0;
- for (int i = 0; i < arr.length; i++) {
- if (arr[i].isVisible() == true) {
- licznik++;
- }
- }
- if (licznik == arr.length) {
- return 1;
- } else
- return 0;
- }
- /*
- * int czyKoniec2(Label[] arr) { for(int i=0;i<arr.length;i++) {
- * if(arr[i].isVisible()==true) return 1; } return 0; }
- */ // ta nie dziala.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement