Advertisement
Guest User

passatempo

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