package war3;
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;
public class pro extends Application {
int[][] point=new int[11][11];
Rectangle[][] x=new Rectangle[11][11];
int time,px,py;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 700, 700);
time=0;
int s,sx;
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
point[s][sx]=0;
}
}
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
px=50*s-50;
py=50*sx-50;
x[s][sx]=new Rectangle(50,50,Color.GREEN);
x[s][sx].setLayoutX(px);
x[s][sx].setLayoutY(py);
root.getChildren().add(x[s][sx]);
}
}
primaryStage.setTitle("練習");
primaryStage.setScene(scene);
primaryStage.show();
new AnimationTimer() {
@Override
public void handle(long now) {
time=time+1;
if(time>10){
int x1,y1,s,sx;
x1=(int)(10*Math.random())+1;
y1=(int)(10*Math.random())+1;
point[x1][y1]=2;
x1=(int)(10*Math.random())+1;
y1=(int)(10*Math.random())+1;
point[x1][y1]=0;
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
if(point[s][sx]==0)x[s][sx].setFill(Color.GREEN);
if(point[s][sx]==1)x[s][sx].setFill(Color.WHITE);
if(point[s][sx]==2)x[s][sx].setFill(Color.BLACK);
}
}
time=0;
}
}
}.start();
scene.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me) {
double mx,my;
mx=me.getX();
my=me.getY();
int x1,y1;
x1=(int)(mx/50)+1;
y1=(int)(my/50)+1;
if(x1>8)x1=0;
if(y1>8)y1=0;
if(x1<1)x1=0;
if(y1<1)y1=0;
point[x1][y1]=1;
}
});
}
}
最終更新:2013年09月04日 18:31