Starting Piece Shape and Maps, WIP: wrong algorithm
This commit is contained in:
31
app/src/main/java/school_project/Piece.java
Normal file
31
app/src/main/java/school_project/Piece.java
Normal file
@ -0,0 +1,31 @@
|
||||
package school_project;
|
||||
|
||||
public class Piece extends Shape{
|
||||
|
||||
public Piece() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Piece(boolean[][] matrix) {
|
||||
super(matrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the matrix of the piece. Used when the player right click
|
||||
* TODO: ALGORITHME INCORECTE, A REFAIRE <tonitch>
|
||||
*
|
||||
* @param times Set the amount of time the rotation should be executed. Should be set between 1 and 3.
|
||||
*/
|
||||
public void RotateRight(int times){
|
||||
while(times > 0) {
|
||||
boolean[][] temp_matrix = new boolean[width][height];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
temp_matrix[j][i] = matrix[i][j];
|
||||
}
|
||||
}
|
||||
times--;
|
||||
matrix = temp_matrix;
|
||||
}
|
||||
}
|
||||
}
|
40
app/src/main/java/school_project/Shape.java
Normal file
40
app/src/main/java/school_project/Shape.java
Normal file
@ -0,0 +1,40 @@
|
||||
package school_project;
|
||||
|
||||
|
||||
public class Shape {
|
||||
|
||||
protected boolean[][] matrix;
|
||||
protected int height, width;
|
||||
|
||||
public Shape() {
|
||||
matrix = new boolean[0][0];
|
||||
}
|
||||
|
||||
public Shape(boolean[][] matrix){
|
||||
this.setShape(matrix);
|
||||
}
|
||||
|
||||
public void setShape(boolean[][] matrix) throws IllegalArgumentException{
|
||||
height = matrix.length;
|
||||
width = matrix[0].length;
|
||||
|
||||
for (boolean[] row: matrix){
|
||||
if(row.length != width){
|
||||
throw new IllegalArgumentException("The argument should be a square matrix");
|
||||
}
|
||||
}
|
||||
this.matrix = matrix;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public boolean[][] getShape() {
|
||||
return matrix;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user