fixup! Fixing Branch
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Debucquoy Anthony 2023-04-06 18:25:04 +02:00
parent a6fc46a0ea
commit 37cc19f49a
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 1 additions and 229 deletions

View File

@ -1,226 +0,0 @@
package application;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.layout.Pane;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.Cursor;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale;
import javafx.animation.RotateTransition;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Piece extends Application{
double x;
double y;
public void start(Stage primaryStage) throws Exception {
Polygon piece1 = new Polygon();
Polygon piece2 = new Polygon();
Polygon piece3 = new Polygon();
Polygon piece4 = new Polygon();
Polygon piece5 = new Polygon();
Polygon piece6 = new Polygon();
Polygon piece7 = new Polygon();
piece1.getPoints().addAll(new Double [] {
0.0,0.0,
200.0,0.0,
200.0,200.0,
100.0,200.0,
100.0,100.0,
0.0,100.0});
piece2.getPoints().addAll(new Double [] {
100.0,0.0,
200.0,0.0,
200.0,300.0,
100.0,300.0,
});
piece3.getPoints().addAll(new Double [] {
0.0,0.0,
200.0,0.0,
200.0,200.0,
0.0,200.0,
});
piece4.getPoints().addAll(new Double [] {
0.0,0.0,
200.0,0.0,
200.0,300.0,
0.0,300.0,
});
piece5.getPoints().addAll(new Double [] {
0.0,0.0,
100.0,0.0,
100.0,100.0,
0.0,100.0,
});
piece6.getPoints().addAll(new Double [] {
0.0,0.0,
200.0,0.0,
200.0,300.0,
100.0,300.0,
100.0,100.0,
0.0,100.0});
piece7.getPoints().addAll(new Double [] {
100.0,0.0,
200.0,0.0,
200.0,200.0,
100.0,200.0,
});
/*for(int i ; i<tab.lenght ; i++ ) {
for (int j , i<tab.widnth , j++) {
if (tab[0][0]==TRUE;) {
if(tab[
}
}
}*/
Group root = new Group();
root.getChildren().addAll(piece2,piece1,piece3,piece4,piece5,piece6,piece7/*,....,pieceN*/);
Scene scene = new Scene(root,690,650,Color.WHEAT);
root.getChildren().forEach(n -> makeDraggable((Polygon) n));
root.getChildren().forEach(n -> rotation((Polygon) n, scene));
primaryStage.setScene(scene);
primaryStage.setTitle("piece 1");
primaryStage.show();
piece1.setFill(Color.LIMEGREEN);
piece1.setStroke(Color.BLACK);
piece1.setStrokeWidth(3);
piece2.setFill(Color.LIMEGREEN);
piece2.setStroke(Color.BLACK);
piece2.setStrokeWidth(3);
piece3.setFill(Color.LIMEGREEN);
piece3.setStroke(Color.BLACK);
piece3.setStrokeWidth(3);
piece4.setFill(Color.LIMEGREEN);
piece4.setStroke(Color.BLACK);
piece4.setStrokeWidth(3);
piece5.setFill(Color.LIMEGREEN);
piece5.setStroke(Color.BLACK);
piece5.setStrokeWidth(3);
piece6.setFill(Color.LIMEGREEN);
piece6.setStroke(Color.BLACK);
piece6.setStrokeWidth(3);
piece7.setFill(Color.LIMEGREEN);
piece7.setStroke(Color.BLACK);
piece7.setStrokeWidth(3);
}
//double click delayed bug to fix
//ftm just the last piece implemented can be rotated
public static void rotaterght (Node node) {
RotateTransition rotaterght = new RotateTransition();
//setting attributes for the RotateTransition
rotaterght.setByAngle(90);
rotaterght.autoReverseProperty();
rotaterght.setDuration(Duration.millis(1000));
rotaterght.setNode(node);
rotaterght.setAxis(Rotate.Z_AXIS);
rotaterght.play();}
public static void rotatelft (Node node) {
RotateTransition rotatelft = new RotateTransition();
rotatelft.setByAngle(-90);// minus to rotate to the left
rotatelft.autoReverseProperty();
rotatelft.setDuration(Duration.millis(1000));
rotatelft.setNode(node);
rotatelft.setAxis(Rotate.Z_AXIS);
rotatelft.play();}
public void rotation (Polygon node, Scene scene) {
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent event) {// 'event' means corresponds to clicking on the clipboard
switch (event.getCode()) {// 'getCode' gets the code of the key pressed on the clipboard
case RIGHT: rotaterght(node); break;
//args to set
case LEFT: rotatelft(node); break;
default: System.out.println("this case hasn't been taken in charge yet");
}
}
});
}
public void makeDraggable(Polygon node) {
node.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
// record a (x,y) distance for the drag and drop operation.
x = node.getLayoutX() - mouseEvent.getSceneX();
y = node.getLayoutY() - mouseEvent.getSceneY();
node.requestFocus();
node.setFocusTraversable(true);
node.focusedProperty();
node.focusVisibleProperty();
/*node.setFocused(true);*/
node.setCursor(Cursor.CLOSED_HAND);
node.setFill(Color.AZURE);
}
});
node.setOnMouseReleased(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
node.setCursor(Cursor.HAND);
node.setFill(Color.LIMEGREEN);
}
});
node.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
node.setLayoutX(mouseEvent.getSceneX() + x);
node.setLayoutY(mouseEvent.getSceneY() + y);
}
});
node.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
node.setCursor(Cursor.HAND);
}
});
}
public static void main(String[] args) {
launch(args);
}
}

View File

@ -1,9 +1,7 @@
package school_project; package school_project;
import javafx.application.Application; import javafx.application.Application;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.layout.Pane;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.Cursor; import javafx.scene.Cursor;