package game.pieces;

/**
 *
 * @author givanse
 */
public class Board {
    
    private final int width;
    private final int height;
    private final boolean coordinates[][];
    private final Square squares[][];
    
    public enum SwapDirection {LEFT, RIGHT, UP, DOWN};
    public static int WIDTH_IN_SQUARES = 12;  // number of squares 
    public static int HEIGHT_IN_SQUARES = 18; // number of squares
    
    public Board() {
        this(Board.WIDTH_IN_SQUARES, Board.HEIGHT_IN_SQUARES);
    }
    
    public Board(int widthInSquares, int heightInSquares) {
        this.width = widthInSquares;
        this.height = heightInSquares;
        this.coordinates = new boolean[this.width][this.height];
        this.squares = new Square[this.width][this.height];
    }
    
    public Board(Square[][] squares) {
        this.squares = squares;
        this.width = this.squares[0].length;
        this.height = this.squares.length;
        this.coordinates = new boolean[this.width][this.height];
         for(int x = 0; x < this.width ; x++)
            for(int y = 0; y < this.height; y++) {
                this.updatePosition(x, y, this.isPositionAvailable(x, y));
            }
    }
    
    /* Public methods */
    
    public void update() {
        
    }
    
    public Square[][] getSquares() {
        return this.squares;
    }
    
    public boolean isPositionAvailable(int x, int y) {
        return false;
    }
    
    public void updatePosition(int x, int y, boolean isAvailable) {
        this.coordinates[x][y] =  isAvailable;
    }
    
    public boolean isValidSwap(int x, int y, SwapDirection dir) {
        return true;
    }
    
    public void deleteCompletedTetrisShapes() {
        
    }
    
    public void moveDownLooseRows() {
        
    }
}

@@ -15,16 +15,108 @@
 ieces;%0A%0A
+import game.pieces.Square.SquareType;%0Aimport java.util.ArrayList;%0Aimport java.util.Random;%0A%0A
 /**%0A *%0A 
@@ -248,27 +248,34 @@
 boolean 
-coordinates
+availabilityMatrix
 %5B%5D%5B%5D;%0A  
@@ -306,24 +306,103 @@
 quares%5B%5D%5B%5D;%0A
+    private final ArrayList%3CSquare%3E fallingSquares = new ArrayList%3CSquare%3E(2);%0A
     %0A    pub
@@ -676,32 +676,444 @@
 ES);%0A    %7D%0A    %0A
+    public Board(Square%5B%5D%5B%5D squares) %7B%0A        this(squares%5B0%5D.length, squares.length); %0A         for(int x = 0; x %3C this.width ; x++)%0A            for(int y = 0; y %3C this.height; y++) %7B%0A                /* Update all the positions of the availabilityMatrix. */%0A                this.updatePosition(x, y, this.isPositionAvailable(x, y));%0A                this.squares%5Bx%5D%5By%5D = squares%5Bx%5D%5By%5D;%0A            %7D%0A    %7D%0A    %0A
     public Board
@@ -1241,35 +1241,42 @@
        this.
-coordinates
+availabilityMatrix
  = new boole
@@ -1372,163 +1372,344 @@
     
-%7D%0A    %0A    public Board(Square%5B%5D%5B%5D squares) %7B%0A        this.squares = squares;%0A        this.width = this.squares%5B0%5D.length;%0A        this.height = this.squar
+    this.generateRandomFallingPair();%0A    %7D%0A    %0A    private void generateRandomFallingPair() %7B%0A        Random random = new Random(System.currentTimeMillis());%0A        int randomX = random.nextInt(this.width);%0A        int constantY = 0;%0A        SquareType sqrTypes%5B%5D = SquareType.values();%0A        int randomType = random.nextInt(sqrTyp
 es.l
@@ -1713,16 +1713,17 @@
 s.length
+)
 ;%0A      
@@ -1728,63 +1728,119 @@
     
-this.coordinates = new boolean%5Bthis.width%5D%5Bthis.height%5D
+Square square1 = new Square(randomX, constantY, sqrTypes%5BrandomType%5D);%0A        this.fallingSquares.add(square1)
 ;%0A  
@@ -1849,185 +1849,247 @@
     
- 
-for(int x = 0; x %3C this.width ; x++)%0A            for(int y = 0; y %3C this.height; y++) %7B%0A                this.updatePosition(x, y, this.isPositionAvailable(x, y));%0A            %7D
+randomX = (randomX == this.width-1) ? randomX - 1 : randomX + 1;%0A        randomType = random.nextInt(sqrTypes.length);%0A        Square square2 = new Square(randomX, constantY, sqrTypes%5BrandomType%5D);%0A        this.fallingSquares.add(square2);
 %0A   
@@ -2253,32 +2253,136 @@
     %0A    public 
+ArrayList%3CSquare%3E getFallingSquares() %7B%0A        return this.fallingSquares;%0A    %7D%0A    %0A    public final 
 boolean isPositi
@@ -2445,32 +2445,38 @@
     %0A    public 
+final 
 void updatePosit
@@ -2533,19 +2533,26 @@
 his.
-coordinates
+availabilityMatrix
 %5Bx%5D%5B

generate a random pair of falling squares