일반 테트리스 만들기
public class Blocks {
static final int BLOCKNUMBER = 7;
int [][] block = new int[4][4]; //블록을 위한 공간
int top = 0;
int bottom = 0;
int left = 0;
int right = 0;
int blockSize = 0;
int idx = 0;
public void makingBlock(){ //블록을 만들고 무작위로 리턴하는 메서드
idx = (int)(Math.random()*(BLOCKNUMBER));
switch (idx){
case 0:
/*
* 1 1
* 1 1
*/
block[1][1]=1;
block[1][2]=1;
block[2][1]=1;
block[2][2]=1;
top = 1;
bottom = 2;
left = 1;
right = 2;
blockSize =3;
break;
case 1:
/*
* 1 1
* 1 1
*/
block[2][1]=1;
block[2][2]=1;
block[1][2]=1;
block[1][3]=1;
top = 1;
bottom = 2;
left = 1;
right = 3;
blockSize = 3;
break;
case 2:
/*
* 1 1
* 1 1
*/
block[1][1]=1;
block[1][2]=1;
block[2][2]=1;
block[2][3]=1;
top = 1;
bottom = 2;
left = 1;
right = 3;
blockSize = 3;
break;
case 3:
/*
* 1 1 1
* 1
*/
block[1][1]=1;
block[1][2]=1;
block[1][3]=1;
block[2][1]=1;
top = 1;
bottom = 2;
left = 1;
right = 3;
blockSize = 3;
break;
case 4:
/*
* 1 1 1
* 1
*/
block[1][1]=1;
block[1][2]=1;
block[1][3]=1;
block[2][3]=1;
top = 1;
bottom = 2;
left = 1;
right = 3;
blockSize = 3;
break;
case 5:
/*
* 1 1 1
* 1
*/
block[1][1]=1;
block[1][2]=1;
block[1][3]=1;
block[2][2]=1;
top = 1;
bottom = 2;
left = 1;
right = 3;
blockSize = 3;
break;
case 6:
/*
* 1 1 1 1
*/
block[1][0]=1;
block[1][1]=1;
block[1][2]=1;
block[1][3]=1;
top = 1;
bottom = 1;
left= 0;
right = 3;
blockSize = 4;
break;
}
}
public int [][] turnBlock(int [][] blocks){
int [][]blockArray = new int[blocks.length][blocks[0].length];
for(int i = 0; i < blocks.length;i++){
for(int j = 0; j < blocks[0].length;j++){
blockArray[j][blocks.length -1 - i] = blocks[i][j];
}
}
return blockArray;
}
}