mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 08:56:01 +02:00
Add items;
+ Minor changes
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RunConfigurationProducerService">
|
||||||
|
<option name="ignoredProducers">
|
||||||
|
<set>
|
||||||
|
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
package com.yes.yes.behaviours;
|
package com.yes.yes.behaviours;
|
||||||
|
|
||||||
import com.yes.yes.utils.BlockContainer;
|
import com.yes.yes.entities.parts.Square;
|
||||||
import com.yes.yes.utils.Component;
|
import com.yes.yes.utils.*;
|
||||||
import com.yes.yes.utils.Coordinate;
|
|
||||||
import com.yes.yes.utils.Entity;
|
|
||||||
|
|
||||||
public class PlaceBehaviour extends Component {
|
public class PlaceBehaviour extends Component {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param entity
|
||||||
|
* @param blockContainer
|
||||||
|
*/
|
||||||
public PlaceBehaviour(Entity entity, BlockContainer blockContainer) {
|
public PlaceBehaviour(Entity entity, BlockContainer blockContainer) {
|
||||||
super(entity, blockContainer);
|
super(entity, blockContainer);
|
||||||
}
|
}
|
||||||
@@ -26,6 +28,13 @@ public class PlaceBehaviour extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Item item = new Item();
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
for (int i1 = 0; i1 < 4; i1++) {
|
||||||
|
item.setPart(i, i1, new Square());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent.getChildren().add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import javafx.scene.shape.Rectangle;
|
|||||||
public class TestMachine2 extends Entity {
|
public class TestMachine2 extends Entity {
|
||||||
public TestMachine2() {
|
public TestMachine2() {
|
||||||
super();
|
super();
|
||||||
this.getChildren().add(new Rectangle(25, 25));
|
this.getChildren().add(new Rectangle(50, 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestMachine2(BlockContainer blockContainer) {
|
public TestMachine2(BlockContainer blockContainer) {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.yes.yes.entities.parts;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
|
public class Square extends com.yes.yes.utils.Part {
|
||||||
|
public Square() {
|
||||||
|
var rect = new Rectangle(25,25);
|
||||||
|
rect.setFill(Color.RED);
|
||||||
|
rect.setStroke(Color.BLACK);
|
||||||
|
rect.setStrokeWidth(1);
|
||||||
|
this.getChildren().add(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.yes.yes.utils;
|
||||||
|
|
||||||
|
public class Item extends javafx.scene.Group {
|
||||||
|
final Part[][] parts = new Part[4][4];
|
||||||
|
|
||||||
|
public void setPart(int layer, int section, Part part) throws IllegalArgumentException {
|
||||||
|
if (layer < 0 || layer > 4 && section < 0 || section > 4) {
|
||||||
|
throw new IllegalArgumentException("Argument out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parts[layer][section] != null) {
|
||||||
|
this.getChildren().remove(parts[layer][section]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
parts[layer][section] = part;
|
||||||
|
this.getChildren().add(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Part getPart(int layer, int section) throws IllegalArgumentException {
|
||||||
|
if (layer < 0 || layer > 4 && section < 0 || section > 4) {
|
||||||
|
throw new IllegalArgumentException("Argument out of range");
|
||||||
|
}
|
||||||
|
return parts[layer][section];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rotate(int quarters) {
|
||||||
|
quarters %= 4;
|
||||||
|
|
||||||
|
for (int i = 0; i < quarters; i++) {
|
||||||
|
for (int l = 0; l < 4; l++) {
|
||||||
|
Part[] rot = new Part[4];
|
||||||
|
|
||||||
|
rot[0] = parts[l][2];
|
||||||
|
rot[1] = parts[l][0];
|
||||||
|
rot[2] = parts[l][3];
|
||||||
|
rot[3] = parts[l][1];
|
||||||
|
|
||||||
|
parts[l] = rot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
parts[i][j].rotate(quarters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.yes.yes.utils;
|
||||||
|
|
||||||
|
import javafx.scene.Node;
|
||||||
|
|
||||||
|
public abstract class Part extends javafx.scene.Group {
|
||||||
|
public void addChild(Node element) {
|
||||||
|
this.getChildren().add(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeChild(Node element) {
|
||||||
|
this.getChildren().remove(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rotate(int quarters) {
|
||||||
|
|
||||||
|
this.getTransforms().clear();
|
||||||
|
this.getTransforms().add(new javafx.scene.transform.Rotate(quarters % 4 * 90, 1, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user