📄 square.java
字号:
package iiist2;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import iiist1.GameKe;
import iiist1.GameKe.Screen;
public class Square
{
private static final int col = 24;
private static final int row = 13;
private int [][] fSquare; // frist crate square
private int [][] bSquare; // second crate square
private int [][] pSquare;
private int [][] rSquare ; // rotation square
private int [][] sSquare; // prepare square
private int rotaCol;
private int rotaRow;
private int ssquare;
private int fsquare;
private int score;
private int state;
public Square ()
{
fSquare = new int [col][row]; // frist crate square
bSquare = new int [col][row]; // second crate square
pSquare = new int [col][row];
rSquare = new int [col][row]; // rotation square
sSquare = new int [3][5];
for(int i=0;i<col;i++)
{
for(int j=0;j<row;j++)
{
fSquare[i][j]=0;
bSquare[i][j]=0;
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<5;j++)
{
sSquare[i][j]=0;
}
}
}
public void createFirstSquare()
{
fsquare = ssquare;
rotaRow=6;
rotaCol=0;
switch(fsquare)
{
case 0:
fSquare[0][4]=1;fSquare[0][5]=1;fSquare[0][6]=1;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=0;fSquare[1][7]=0;fSquare[1][8]=0;
break;
case 1:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=1;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=0;fSquare[1][8]=0;
break;
case 2:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=0;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 3:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=0;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 4:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=1;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 5:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=1;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 6:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=1;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=0;fSquare[1][8]=0;
break;
case 7:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=1;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=1;fSquare[1][7]=0;fSquare[1][8]=0;
break;
case 8:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=1;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=0;fSquare[1][7]=0;fSquare[1][8]=0;
break;
case 9:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=0;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 10:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=1;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=0;fSquare[1][7]=0;fSquare[1][8]=0;
break;
case 11:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=1;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 12:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=1;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 13:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=0;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=0;fSquare[1][8]=0;
break;
case 14:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=0;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
break;
case 15:
fSquare[0][4]=0;fSquare[0][5]=0;fSquare[0][6]=0;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
fSquare[2][4]=0;fSquare[2][5]=1;fSquare[2][6]=0;fSquare[2][7]=0;fSquare[2][8]=0;
break;
case 16:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=0;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
fSquare[2][4]=0;fSquare[2][5]=0;fSquare[2][6]=0;fSquare[2][7]=1;fSquare[2][8]=0;
break;
case 17:
fSquare[0][4]=1;fSquare[0][5]=1;fSquare[0][6]=0;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=1;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
fSquare[2][4]=0;fSquare[2][5]=0;fSquare[2][6]=0;fSquare[2][7]=0;fSquare[2][8]=0;
break;
case 18:
fSquare[0][4]=1;fSquare[0][5]=1;fSquare[0][6]=1;fSquare[0][7]=0;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=1;fSquare[1][7]=1;fSquare[1][8]=0;
fSquare[2][4]=0;fSquare[2][5]=0;fSquare[2][6]=0;fSquare[2][7]=0;fSquare[2][8]=0;
break;
case 19:
fSquare[0][4]=0;fSquare[0][5]=1;fSquare[0][6]=1;fSquare[0][7]=1;fSquare[0][8]=0;
fSquare[1][4]=0;fSquare[1][5]=0;fSquare[1][6]=1;fSquare[1][7]=0;fSquare[1][8]=0;
fSquare[2][4]=0;fSquare[2][5]=0;fSquare[2][6]=1;fSquare[2][7]=0;fSquare[2][8]=0;
break;
}
ssquare = (new GameKe()).rand(0,7+state);
}
public void createSecondSquare()
{
switch (ssquare)
{
case 0:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=1;sSquare[0][3]=1;sSquare[0][0]=1;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=0;sSquare[1][3]=0;sSquare[1][0]=0;
break;
case 1:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=1;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=0;sSquare[1][4]=0;
break;
case 2:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=0;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 3:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=0;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 4:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=1;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 5:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=1;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 6:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=1;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=0;sSquare[1][4]=0;
break;
case 7:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=1;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=1;sSquare[1][3]=0;sSquare[1][4]=0;
break;
case 8:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=1;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=0;sSquare[1][3]=0;sSquare[1][4]=0;
break;
case 9:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=0;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 10:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=1;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=0;sSquare[1][3]=0;sSquare[1][4]=0;
break;
case 11:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=1;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 12:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=1;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 13:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=0;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=0;sSquare[1][4]=0;
break;
case 14:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=0;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
break;
case 15:
sSquare[0][0]=0;sSquare[0][1]=0;sSquare[0][2]=0;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
sSquare[2][0]=0;sSquare[2][1]=1;sSquare[2][2]=0;sSquare[2][3]=0;sSquare[2][4]=0;
break;
case 16:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=0;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
sSquare[2][0]=0;sSquare[2][1]=0;sSquare[2][2]=0;sSquare[2][3]=1;sSquare[2][4]=0;
break;
case 17:
sSquare[0][0]=1;sSquare[0][1]=1;sSquare[0][2]=0;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=1;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
sSquare[2][0]=0;sSquare[2][1]=0;sSquare[2][2]=0;sSquare[2][3]=0;sSquare[2][4]=0;
break;
case 18:
sSquare[0][0]=1;sSquare[0][1]=1;sSquare[0][2]=1;sSquare[0][3]=0;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=1;sSquare[1][3]=1;sSquare[1][4]=0;
sSquare[2][0]=0;sSquare[2][1]=0;sSquare[2][2]=0;sSquare[2][3]=0;sSquare[2][4]=0;
break;
case 19:
sSquare[0][0]=0;sSquare[0][1]=1;sSquare[0][2]=1;sSquare[0][3]=1;sSquare[0][4]=0;
sSquare[1][0]=0;sSquare[1][1]=0;sSquare[1][2]=1;sSquare[1][3]=0;sSquare[1][4]=0;
sSquare[2][0]=0;sSquare[2][1]=0;sSquare[2][2]=1;sSquare[2][0]=0;sSquare[2][4]=0;
break;
}
}
public void showFirstSquare(Graphics2D g2d)
{
for (int c=0;c<col ;c++ )
{
for (int r=0;r<row ;r++ )
{
if(fSquare[c][r]==1)
{
g2d.setColor(Color.GREEN);
g2d.drawRect(272+r*18, 53+ c*18, 18,18);
g2d.setFont(new Font("黑体",1,15));
g2d.setColor(Color.ORANGE);
g2d.drawString("淼",274+r*18,68+c*18);
}
}
}
}
public void showSecondSquare(Graphics2D g2d, Screen s)
{
for (int c=0;c<3 ;c++ )
{
for (int r=0;r<5 ;r++ )
{
if(sSquare[c][r]==1)
{
g2d.setColor(Color.GREEN);
g2d.drawRect(542+r*18, 270+ c*18, 18,18);
g2d.setFont(new Font("黑体",1,15));
g2d.setColor(Color.ORANGE);
g2d.drawString("淼",545+r*18,285+c*18);
}
}
}
}
public void mergeSquare()
{
for (int c=0;c<col ;c++ )
{
for (int r=0;r<row ;r++ )
{
if(fSquare[c][r]==1)
{
bSquare[c][r]=1;
fSquare[c][r]=0;
}
}
}
}
public void showMergeSquare(Screen s, Graphics2D g2d)
{
for (int c=0;c<col ;c++ )
{
for (int r=0;r<row ;r++ )
{
if(bSquare[c][r]==1)
{
g2d.setColor(Color.GREEN);
g2d.drawRect(272+r*18, 53+ c*18, 18,18);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -