package packman;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.shape.*;
import javafx.animation.AnimationTimer;
import javafx.scene.paint.Color;
import javafx.scene.input.MouseEvent;
import javafx.scene.control.Label;
public class pro extends Application {
int time;
int up,down,right,left;
Rectangle pack;
int px,py;
int s,sx;
Rectangle[][] fish=new Rectangle[21][21];
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
time=0;
Group root = new Group();
Scene scene = new Scene(root, 700, 700);
px=10;
py=10;
pack=new Rectangle(25,25,Color.RED);
pack.setLayoutX(100+25*px);
pack.setLayoutY(600-25*py);
for(s=1;s<21;s++){
for(sx=1;sx<21;sx++){
fish[s][sx]=new Rectangle(25,25,Color.YELLOW);
fish[s][sx].setLayoutX(100+25*s);
fish[s][sx].setLayoutY(600-25*sx);
}
}
Button btn3 = new Button();
btn3.setText("up");
btn3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
up=100;
}
});
btn3.setLayoutX(100);
btn3.setLayoutY(650);
Button btn4 = new Button();
btn4.setText("down");
btn4.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
down=100;
}
});
btn4.setLayoutX(400);
btn4.setLayoutY(650);
Button btn1 = new Button();
btn1.setText("<-");
btn1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
left=100;
}
});
btn1.setLayoutX(200);
btn1.setLayoutY(650);
Button btn2 = new Button();
btn2.setText("->");
btn2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
right=100;
}
});
btn2.setLayoutX(300);
btn2.setLayoutY(650);
root.getChildren().add(btn3);
root.getChildren().add(btn1);
root.getChildren().add(btn2);
root.getChildren().add(btn4);
for(s=1;s<21;s++){
for(sx=1;sx<21;sx++){
root.getChildren().add(fish[s][sx]);
}
}
root.getChildren().add(pack);
primaryStage.setTitle("Packman");
primaryStage.setScene(scene);
primaryStage.show();
new AnimationTimer() {
@Override
public void handle(long now) {
time=time+1;
if(time>10){
if(right>50)px=px+1;
if(left>50)px=px-1;
if(up>50)py=py+1;
if(down>50)py=py-1;
pack.setLayoutX(100+25*px);
pack.setLayoutY(600-25*py);
fish[px][py].setFill(Color.GREEN);
right=0;
left=0;
up=0;
down=0;
}
}
}.start();
}
}
最終更新:2013年08月29日 10:13