Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hellowins;
- /*knb const.*/
- import java.net.URL;
- import java.util.Random;
- import javafx.animation.Interpolator;
- import javafx.animation.TranslateTransition;
- import javafx.application.Application;
- import javafx.event.EventHandler;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.VBox;
- import javafx.scene.media.Media;
- import javafx.scene.media.MediaPlayer;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Circle;
- import javafx.scene.shape.Rectangle;
- import javafx.stage.Stage;
- import javafx.util.Duration;
- public class Hellowins extends Application {
- public Scene scene;
- public Group gp;
- public Label lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8;
- public int clickX=0;
- public int segue=0;
- public int clickAcert=0;
- public int VL_Int[]=new int[6];
- public Image imgSTG=new Image(Hellowins.class.getResourceAsStream("hallowin.jpg"));
- public ImageView imgSTGCent=new ImageView(imgSTG);
- public Image imgPistol=new Image(Hellowins.class.getResourceAsStream("amam.PNG"));
- public ImageView img=new ImageView(imgPistol);
- public Image imgDrag=new Image(Hellowins.class.getResourceAsStream("dragao.gif"));
- public ImageView imgDragao[]=new ImageView[6];
- public TranslateTransition tt[]=new TranslateTransition[6];
- /**
- *
- */
- public void ships(){
- final Circle clRadio=new Circle();
- final Rectangle rect=new Rectangle();
- rect.setHeight(10);
- rect.setWidth(30);
- gp.getChildren().add(rect);
- };
- public void DiscoverTXT(){
- final VBox vbINF=new VBox(0.7);
- vbINF.layoutXProperty().bind(scene.heightProperty().add(100));
- vbINF.setLayoutY(20);
- gp.getChildren().add(vbINF);
- lb1=new Label("WidthClick =0");
- lb2=new Label ("HeigthClick =0");
- lb3=new Label("WidthStatic =0");
- lb4=new Label ("HeigthStatic =0");
- lb5=new Label ("ClicksAcertos =0");
- lb6=new Label("ClicksTotal =0");
- lb7=new Label ("ClicksErrors =0");
- lb8=new Label ("Nivel = ->|<- ");
- lb1.setTextFill(Color.SILVER);
- lb2.setTextFill(Color.SILVER);
- lb3.setTextFill(Color.SILVER);
- lb4.setTextFill(Color.SILVER);
- lb5.setTextFill(Color.SILVER);
- lb6.setTextFill(Color.SILVER);
- lb7.setTextFill(Color.SILVER);
- lb8.setTextFill(Color.SILVER);
- vbINF.getChildren().addAll(lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8);
- };
- @Override
- public void start(Stage stageTitular) {
- final Stage stage=new Stage();
- gp=new Group();
- scene=new Scene(gp,690,450,Color.SILVER);
- stage.setTitle("joguinho com jfx");
- stage.setScene(scene);
- gp.getChildren().add(imgSTGCent);
- imgSTGCent.fitWidthProperty().bind(scene.widthProperty());
- imgSTGCent.fitHeightProperty().bind(scene.heightProperty());
- DiscoverTXT();
- scene.setOnMouseClicked( new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- int PW=(int) t.getX();
- int PH=(int) t.getY();
- lb1.setText("WidthClick =:"+PW);
- lb2.setText("HeigthClick =:"+PH);
- clickX++;
- lb6.setText(" ClicksTotal =:"+clickX);
- int irru= clickAcert-clickX;
- lb7.setText("ClicksErrors = "+irru);
- if (
- VL_Int[1]==1&&
- VL_Int[2]==1&&
- VL_Int[3]==1&&
- VL_Int[4]==1&&
- VL_Int[5]==1){
- //uma scene transparente contendo
- //informaƧoes com o fim de jogo
- Label lbEnd=new Label("FIM DE JOGO");
- lbEnd.layoutXProperty().bind(scene.widthProperty().divide(2.5));
- lbEnd.layoutYProperty().bind(scene.heightProperty().divide(2.5));
- lbEnd.setTextFill(Color.WHITE);
- gp.getChildren().add(lbEnd);
- }else{}
- URL urlOne = Hellowins.class.getResource("vai.wav");
- Media mdps = new Media(urlOne.toString());
- MediaPlayer mediaPlayer = new MediaPlayer(mdps);
- mediaPlayer.play();
- }
- });
- scene.setOnMouseMoved( new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- int PWS=(int) t.getX();
- int PHS=(int) t.getY();
- lb3.setText("WidthClick =:"+PWS);
- lb4.setText("HeigthClick =:"+PHS);
- segue=PWS;
- img.setRotate(segue/10);
- //img.setRotate(segue/360);
- }
- });
- img.setLayoutX(400);
- img.layoutYProperty().bind(scene.heightProperty().subtract(70));
- gp.getChildren().add(img);
- Random rand=new Random(System.currentTimeMillis());
- Random randDrag=new Random(System.currentTimeMillis());
- for (int i = 1; i < 6; i++) {
- System.out.println("rands"+rand.nextInt(257));
- imgDragao[i]=new ImageView();
- gp.getChildren().add(imgDragao[i]);
- imgDragao[i].setImage(imgDrag);
- imgDragao[i].setLayoutY(rand.nextInt(257));
- imgDragao[i].setLayoutX(-10);
- imgDragao[i].setFitHeight(40);
- imgDragao[i].setFitWidth(50);
- imgDragao[i].setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- if (t.getSource()==imgDragao[1]){
- VL_Int[1]=1;
- System.out.println("press1");
- tt[1].stop();
- clickAcert++;
- lb5.setText("ClicksAcertos ="+clickAcert);
- System.out.println(""+VL_Int[1]);
- TranslateTransition tt1d=new TranslateTransition();
- tt1d.setFromY(-20);
- tt1d.fromYProperty().bind(imgDragao[1].layoutYProperty().subtract(20));
- tt1d.setByY(200);
- tt1d.toYProperty().bind(scene.heightProperty().add(370));
- tt1d.setInterpolator(Interpolator.EASE_IN);
- tt1d.setDuration(Duration.seconds(8));
- tt1d.setNode(imgDragao[1]);
- tt1d.play();
- imgDragao[1].setRotate(90);
- }
- else if(t.getSource()==imgDragao[2]){
- System.out.println("press2");
- tt[2].stop();
- clickAcert++;
- lb5.setText("ClicksAcertos ="+clickAcert);
- VL_Int[2]=1;
- System.out.println(""+VL_Int[2]);
- TranslateTransition tt1d=new TranslateTransition();
- tt1d.setFromY(-20);
- tt1d.setByY(200);
- tt1d.toYProperty().bind(scene.heightProperty().add(370));
- tt1d.setInterpolator(Interpolator.EASE_IN);
- tt1d.setDuration(Duration.seconds(8));
- tt1d.setNode(imgDragao[2]);
- tt1d.play();
- imgDragao[2].setRotate(90);
- }
- else if(t.getTarget()==imgDragao[3]){
- System.out.println("press3");
- tt[3].stop();
- clickAcert++;
- lb5.setText("ClicksAcertos ="+clickAcert);
- VL_Int[3]=1;
- System.out.println(""+VL_Int[3]);
- TranslateTransition tt1d=new TranslateTransition();
- tt1d.setFromY(-20);
- tt1d.setByY(200);
- tt1d.toYProperty().bind(scene.heightProperty().add(370));
- tt1d.setInterpolator(Interpolator.EASE_IN);
- tt1d.setDuration(Duration.seconds(8));
- tt1d.setNode(imgDragao[3]);
- tt1d.play();
- imgDragao[3].setRotate(90);
- }
- else if(t.getTarget()==imgDragao[4]){
- System.out.println("press4");
- tt[4].stop();
- clickAcert++;
- lb5.setText("ClicksAcertos ="+clickAcert);
- VL_Int[4]=1;
- System.out.println(""+VL_Int[4]);
- TranslateTransition tt1d=new TranslateTransition();
- tt1d.setFromY(-20);
- tt1d.setByY(200);
- tt1d.toYProperty().bind(scene.heightProperty().add(370));
- tt1d.setInterpolator(Interpolator.EASE_IN);
- tt1d.setDuration(Duration.seconds(8));
- tt1d.setNode(imgDragao[4]);
- tt1d.play();
- imgDragao[4].setRotate(90);
- }
- else if(t.getTarget()==imgDragao[5]){
- System.out.println("press5");
- tt[5].stop();
- clickAcert++;
- lb5.setText("ClicksAcertos ="+clickAcert);
- VL_Int[5]=1;
- System.out.println(""+VL_Int[5]);
- TranslateTransition tt1d=new TranslateTransition();
- tt1d.setFromY(-20);
- tt1d.setByY(200);
- tt1d.toYProperty().bind(scene.heightProperty().add(370));
- tt1d.setInterpolator(Interpolator.EASE_IN);
- tt1d.setDuration(Duration.seconds(8));
- tt1d.setNode(imgDragao[5]);
- tt1d.play();
- imgDragao[5].setRotate(90);
- }
- //*
- };
- });
- tt[i]=new TranslateTransition();
- tt[i].setFromX(-20);
- tt[i].setByX(200);
- tt[i].toXProperty().bind(scene.widthProperty().add(370));
- tt[i].setInterpolator(Interpolator.EASE_IN);
- tt[i].setCycleCount(TranslateTransition.INDEFINITE);
- tt[i].setDuration(Duration.seconds(randDrag.nextInt((int)8)));
- tt[i].setNode(imgDragao[i]);
- tt[i].play();
- }
- stage.show();
- }
- public static void main(String [] args){
- Hellowins.launch(Hellowins.class,args);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement