Guest User

HellowWinsjfx

a guest
Nov 4th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.93 KB | None | 0 0
  1. numagrandeviagem.blogspot.com  
  2. bem10jfx.blogspot.com.br
  3. knbjfx.blogspot.com.br
  4. package hellowins;
  5.  
  6.  
  7. /*knb const.*/
  8.  
  9.  
  10. import java.net.URL;
  11. import java.util.Random;
  12. import javafx.animation.Interpolator;
  13. import javafx.animation.TranslateTransition;
  14. import javafx.application.Application;
  15. import javafx.event.EventHandler;
  16. import javafx.scene.Group;
  17. import javafx.scene.Scene;
  18. import javafx.scene.control.Label;
  19. import javafx.scene.image.Image;
  20. import javafx.scene.image.ImageView;
  21. import javafx.scene.input.MouseEvent;
  22. import javafx.scene.layout.VBox;
  23. import javafx.scene.media.Media;
  24. import javafx.scene.media.MediaPlayer;
  25. import javafx.scene.paint.Color;
  26. import javafx.scene.shape.Circle;
  27. import javafx.scene.shape.Rectangle;
  28. import javafx.stage.Stage;
  29. import javafx.util.Duration;
  30.  
  31. public class Hellowins extends Application {
  32.     public Scene scene;
  33.     public Group gp;
  34.     public Label lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8;
  35.     public int clickX=0;
  36.     public int segue=0;
  37.     public int clickAcert=0;
  38.     public int VL_Int[]=new int[6];
  39.    
  40.     public Image imgSTG=new Image(Hellowins.class.getResourceAsStream("hallowin.jpg"));
  41.     public ImageView imgSTGCent=new ImageView(imgSTG);
  42.    
  43.     public Image imgPistol=new Image(Hellowins.class.getResourceAsStream("amam.PNG"));
  44.     public ImageView img=new ImageView(imgPistol);
  45.     public Image imgDrag=new Image(Hellowins.class.getResourceAsStream("dragao.gif"));
  46.     public ImageView imgDragao[]=new ImageView[6];
  47.     public TranslateTransition tt[]=new TranslateTransition[6];
  48.      
  49.    
  50.     /**
  51.      *
  52.      */
  53.    
  54.    
  55.    
  56.     public void ships(){
  57.    
  58.         final Circle clRadio=new Circle();
  59.         final Rectangle rect=new Rectangle();
  60.        
  61.         rect.setHeight(10);
  62.         rect.setWidth(30);
  63.      
  64.        
  65.     gp.getChildren().add(rect);
  66.     };
  67.    public void DiscoverTXT(){
  68.         final VBox vbINF=new VBox(0.7);
  69.         vbINF.layoutXProperty().bind(scene.heightProperty().add(100));
  70.         vbINF.setLayoutY(20);
  71.         gp.getChildren().add(vbINF);
  72.        
  73.         lb1=new Label("WidthClick =0");
  74.         lb2=new Label ("HeigthClick =0");
  75.         lb3=new Label("WidthStatic =0");
  76.         lb4=new Label ("HeigthStatic =0");
  77.         lb5=new Label ("ClicksAcertos =0");
  78.         lb6=new Label("ClicksTotal =0");
  79.         lb7=new Label ("ClicksErrors =0");
  80.         lb8=new Label ("Nivel = ->|<- ");
  81.        
  82.         lb1.setTextFill(Color.SILVER);
  83.         lb2.setTextFill(Color.SILVER);
  84.         lb3.setTextFill(Color.SILVER);
  85.         lb4.setTextFill(Color.SILVER);
  86.         lb5.setTextFill(Color.SILVER);
  87.         lb6.setTextFill(Color.SILVER);
  88.         lb7.setTextFill(Color.SILVER);
  89.         lb8.setTextFill(Color.SILVER);
  90.         vbINF.getChildren().addAll(lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8);
  91.        
  92.    };
  93.    
  94.     @Override
  95.     public void start(Stage stageTitular) {
  96.         final Stage stage=new Stage();
  97.         gp=new Group();
  98.         scene=new Scene(gp,690,450,Color.SILVER);
  99.         stage.setTitle("joguinho com jfx");
  100.         stage.setScene(scene);
  101.        
  102.         gp.getChildren().add(imgSTGCent);
  103.         imgSTGCent.fitWidthProperty().bind(scene.widthProperty());
  104.         imgSTGCent.fitHeightProperty().bind(scene.heightProperty());
  105.         DiscoverTXT();
  106.        
  107.         scene.setOnMouseClicked( new EventHandler<MouseEvent>() {
  108.             @Override
  109.             public void handle(MouseEvent t) {
  110.          
  111.             int PW=(int) t.getX();
  112.             int PH=(int) t.getY();
  113.          lb1.setText("WidthClick =:"+PW);
  114.          lb2.setText("HeigthClick =:"+PH);
  115.          
  116.           clickX++;
  117.          
  118.           lb6.setText(" ClicksTotal =:"+clickX);
  119.           int irru= clickAcert-clickX;
  120.           lb7.setText("ClicksErrors = "+irru);
  121.           if (
  122.                             VL_Int[1]==1&&
  123.                             VL_Int[2]==1&&
  124.                             VL_Int[3]==1&&
  125.                             VL_Int[4]==1&&
  126.                             VL_Int[5]==1){
  127.                     //uma scene transparente contendo
  128.                         //informaΓ§oes com o fim de jogo
  129.                    Label lbEnd=new Label("FIM DE JOGO");
  130.                    lbEnd.layoutXProperty().bind(scene.widthProperty().divide(2.5));
  131.                    lbEnd.layoutYProperty().bind(scene.heightProperty().divide(2.5));
  132.                    lbEnd.setTextFill(Color.WHITE);
  133.                    gp.getChildren().add(lbEnd);
  134.                }else{/*>[@]>bem10jfx.blogspot.com>[ΒΊ]>knbjfx.blogspot.com>[]>*/}
  135.                    
  136.             URL urlOne = Hellowins.class.getResource("vai.wav");
  137.             Media mdps = new Media(urlOne.toString());
  138.             MediaPlayer mediaPlayer = new MediaPlayer(mdps);
  139.             mediaPlayer.play();
  140.            
  141.             }
  142.         });
  143.        
  144.         scene.setOnMouseMoved( new EventHandler<MouseEvent>() {
  145.             @Override
  146.             public void handle(MouseEvent t) {
  147.          
  148.             int PWS=(int) t.getX();
  149.             int PHS=(int) t.getY();
  150.    
  151.          lb3.setText("WidthClick =:"+PWS);
  152.          lb4.setText("HeigthClick =:"+PHS);
  153.          segue=PWS;
  154.         img.setRotate(segue/10);
  155.         //img.setRotate(segue/360);
  156.                    
  157.             }
  158.         });
  159.        
  160.         img.setLayoutX(400);
  161.         img.layoutYProperty().bind(scene.heightProperty().subtract(70));
  162.         gp.getChildren().add(img);
  163.        
  164.         Random rand=new Random(System.currentTimeMillis());
  165.         Random randDrag=new Random(System.currentTimeMillis());
  166.            
  167.         for (int i = 1; i < 6; i++) {
  168.              System.out.println("rands"+rand.nextInt(257));
  169.        
  170.              imgDragao[i]=new ImageView();
  171.         gp.getChildren().add(imgDragao[i]);
  172.         imgDragao[i].setImage(imgDrag);
  173.         imgDragao[i].setLayoutY(rand.nextInt(257));
  174.         imgDragao[i].setLayoutX(-10);
  175.         imgDragao[i].setFitHeight(40);
  176.         imgDragao[i].setFitWidth(50);
  177.        
  178.        imgDragao[i].setOnMouseClicked(new EventHandler<MouseEvent>() {
  179.           @Override
  180.            public void handle(MouseEvent t) {
  181.                    
  182.       if (t.getSource()==imgDragao[1]){
  183.           VL_Int[1]=1;
  184.           System.out.println("press1");
  185.           tt[1].stop();
  186.           clickAcert++;
  187.           lb5.setText("ClicksAcertos ="+clickAcert);
  188.           System.out.println(""+VL_Int[1]);
  189.          
  190.        TranslateTransition tt1d=new TranslateTransition();
  191.        tt1d.setFromY(-20);
  192.        tt1d.fromYProperty().bind(imgDragao[1].layoutYProperty().subtract(20));
  193.        tt1d.setByY(200);
  194.        tt1d.toYProperty().bind(scene.heightProperty().add(370));
  195.        tt1d.setInterpolator(Interpolator.EASE_IN);
  196.        tt1d.setDuration(Duration.seconds(8));
  197.        tt1d.setNode(imgDragao[1]);
  198.        tt1d.play();
  199.        imgDragao[1].setRotate(90);
  200.        
  201.       }
  202.        else if(t.getSource()==imgDragao[2]){
  203.          System.out.println("press2");
  204.          tt[2].stop();
  205.          clickAcert++;
  206.          lb5.setText("ClicksAcertos ="+clickAcert);
  207.       VL_Int[2]=1;
  208.      System.out.println(""+VL_Int[2]);
  209.      
  210.      TranslateTransition tt1d=new TranslateTransition();
  211.        tt1d.setFromY(-20);
  212.        tt1d.setByY(200);
  213.        tt1d.toYProperty().bind(scene.heightProperty().add(370));
  214.        tt1d.setInterpolator(Interpolator.EASE_IN);
  215.        tt1d.setDuration(Duration.seconds(8));
  216.        tt1d.setNode(imgDragao[2]);
  217.        tt1d.play();
  218.        
  219.        imgDragao[2].setRotate(90);
  220.      
  221.      }
  222.      else if(t.getTarget()==imgDragao[3]){
  223.          System.out.println("press3");
  224.          tt[3].stop();
  225.          clickAcert++;
  226.          lb5.setText("ClicksAcertos ="+clickAcert);
  227.       VL_Int[3]=1;
  228.      System.out.println(""+VL_Int[3]);
  229.      
  230.      TranslateTransition tt1d=new TranslateTransition();
  231.        tt1d.setFromY(-20);
  232.        tt1d.setByY(200);
  233.        tt1d.toYProperty().bind(scene.heightProperty().add(370));
  234.        tt1d.setInterpolator(Interpolator.EASE_IN);
  235.        tt1d.setDuration(Duration.seconds(8));
  236.        tt1d.setNode(imgDragao[3]);
  237.        tt1d.play();
  238.        imgDragao[3].setRotate(90);
  239.      
  240.      }
  241.      else if(t.getTarget()==imgDragao[4]){
  242.          System.out.println("press4");
  243.          tt[4].stop();
  244.          clickAcert++;
  245.          lb5.setText("ClicksAcertos ="+clickAcert);
  246.      VL_Int[4]=1;
  247.      System.out.println(""+VL_Int[4]);
  248.      
  249.      TranslateTransition tt1d=new TranslateTransition();
  250.        tt1d.setFromY(-20);
  251.        tt1d.setByY(200);
  252.        tt1d.toYProperty().bind(scene.heightProperty().add(370));
  253.        tt1d.setInterpolator(Interpolator.EASE_IN);
  254.        tt1d.setDuration(Duration.seconds(8));
  255.        tt1d.setNode(imgDragao[4]);
  256.        tt1d.play();
  257.        imgDragao[4].setRotate(90);
  258.      }
  259.      else if(t.getTarget()==imgDragao[5]){
  260.          System.out.println("press5");
  261.          tt[5].stop();
  262.          clickAcert++;
  263.          lb5.setText("ClicksAcertos ="+clickAcert);
  264.      VL_Int[5]=1;
  265.      System.out.println(""+VL_Int[5]);
  266.      
  267.      TranslateTransition tt1d=new TranslateTransition();
  268.        tt1d.setFromY(-20);
  269.        tt1d.setByY(200);
  270.        tt1d.toYProperty().bind(scene.heightProperty().add(370));
  271.        tt1d.setInterpolator(Interpolator.EASE_IN);
  272.        tt1d.setDuration(Duration.seconds(8));
  273.        tt1d.setNode(imgDragao[5]);
  274.        tt1d.play();
  275.        imgDragao[5].setRotate(90);
  276.      }
  277.             //*      
  278.                     };
  279.             });
  280.      
  281.        tt[i]=new TranslateTransition();
  282.        tt[i].setFromX(-20);
  283.        tt[i].setByX(200);
  284.        tt[i].toXProperty().bind(scene.widthProperty().add(370));
  285.        tt[i].setInterpolator(Interpolator.EASE_IN);
  286.        tt[i].setCycleCount(TranslateTransition.INDEFINITE);
  287.        tt[i].setDuration(Duration.seconds(randDrag.nextInt((int)8)));
  288.        tt[i].setNode(imgDragao[i]);
  289.        tt[i].play();
  290.         }
  291.        
  292.     stage.show();
  293.    
  294.     }
  295.    
  296.     public  static void main(String [] args){
  297.     Hellowins.launch(Hellowins.class,args);
  298.     }
  299. };
Advertisement
Add Comment
Please, Sign In to add comment