From d561433968edb6bf0c2d156ef69e25f46202fe05 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Mon, 1 May 2023 19:41:39 +0200 Subject: [PATCH 1/2] Adding Color --- app/src/main/java/school_project/Piece.java | 21 +++++++++++++++---- .../test/java/school_project/PieceTest.java | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/school_project/Piece.java b/app/src/main/java/school_project/Piece.java index 51df463..0f39258 100644 --- a/app/src/main/java/school_project/Piece.java +++ b/app/src/main/java/school_project/Piece.java @@ -1,5 +1,10 @@ package school_project; +import javafx.scene.paint.Color; +import javafx.scene.paint.Paint; + +import java.util.Random; + /** * Represent a Piece in the game. * Every Piece should be contained in a Map Object. @@ -10,13 +15,20 @@ public class Piece extends Shape{ private Vec2 Position; private Map linked_map; - - public Piece() { - super(); - } + private Paint color; public Piece(boolean[][] matrix) { super(matrix); + Random rand = new Random(); + color = new Color(rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), 1); + } + + public void setColor(Paint p){ + color = p; + } + + public Paint getColor(){ + return color; } public Vec2 getPosition() { @@ -27,6 +39,7 @@ public class Piece extends Shape{ this.Position = position; } + /** * set the map the piece is into the the map argument * @param map map where to place the piece diff --git a/app/src/test/java/school_project/PieceTest.java b/app/src/test/java/school_project/PieceTest.java index e3adc2e..6e80749 100644 --- a/app/src/test/java/school_project/PieceTest.java +++ b/app/src/test/java/school_project/PieceTest.java @@ -36,7 +36,7 @@ class PieceTest { {true, false, true}, }; - Piece piece1 = new Piece(); + Piece piece1 = new Piece(piece2_matrix); piece1.setShape(piece1_matrix); Piece piece2 = new Piece(piece2_matrix); -- 2.46.0 From 7b8cacdb2a74c42d613f37efb5e905582860da1a Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Mon, 1 May 2023 20:15:13 +0200 Subject: [PATCH 2/2] Adding Transient for serializable map --- app/src/main/java/school_project/Piece.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/school_project/Piece.java b/app/src/main/java/school_project/Piece.java index 0f39258..ac01953 100644 --- a/app/src/main/java/school_project/Piece.java +++ b/app/src/main/java/school_project/Piece.java @@ -15,7 +15,7 @@ public class Piece extends Shape{ private Vec2 Position; private Map linked_map; - private Paint color; + private transient Paint color; // https://www.baeldung.com/java-transient-keyword public Piece(boolean[][] matrix) { super(matrix); -- 2.46.0