📄 myeluosi.java
字号:
threepoint1.setBackground(Color.magenta);
threepoint2.setBackground(Color.magenta);
threepoint3.setBackground(Color.magenta);
threepoint1.setEnabled(false);
threepoint2.setEnabled(false);
threepoint3.setEnabled(false);
ClearRows();
getRandomDiamonds();
}
else if(threey2==660||!c.getComponentAt(threex2,threey2).isEnabled()){
threepoint1.setBackground(Color.magenta);
threepoint2.setBackground(Color.magenta);
threepoint3.setBackground(Color.magenta);
threepoint1.setEnabled(false);
threepoint2.setEnabled(false);
threepoint3.setEnabled(false);
ClearRows();
getRandomDiamonds();
}
else if(threey3==660||!c.getComponentAt(threex3,threey3).isEnabled()){
threepoint1.setBackground(Color.magenta);
threepoint2.setBackground(Color.magenta);
threepoint3.setBackground(Color.magenta);
threepoint1.setEnabled(false);
threepoint2.setEnabled(false);
threepoint3.setEnabled(false);
ClearRows();
getRandomDiamonds();
}
DefineOver();
}
};
thread.start();
KeyAdapter k;
threepoint1.addKeyListener(k = new KeyAdapter(){
public void keyPressed(KeyEvent e){
int key = e.getKeyCode();
x = threepoint1.getX();y = threepoint1.getY();
x2 = threepoint2.getX();y2 = threepoint2.getY();
x3 = threepoint3.getX();y3 = threepoint3.getY();
int xx2,yy2,xx3,yy3;
//使twopoint相应移动
if(e.getKeyText(key).equals("Right")){
xx3 = x3;
xx2 = x2;
xx = x;
x+=60;
x2+=60;
x3+=60;
int threey1 = threepoint1.getY();
int threex1 = threepoint1.getX()+60;
int threey2 = threepoint2.getY();
int threex2 = threepoint2.getX()+60;
int threey3 = threepoint3.getY();
int threex3 = threepoint3.getX()+60;
if( x>=0&&x<=600&&x2>=0&&x2<=600&&x3>=0&&x3<=600&&
c.getComponentAt(threex1,threey1).isEnabled()&&
c.getComponentAt(threex2,threey2).isEnabled()&&
c.getComponentAt(threex3,threey3).isEnabled() )
{
threepoint1.setLocation(x,y);
threepoint2.setLocation(x2,y2);
threepoint3.setLocation(x3,y3);
}
else{
x = xx;
x2 = xx2;
x3 = xx3;
}
}
else if(e.getKeyText(key).equals("Left")){
xx3 = x3;
xx2 = x2;
xx = x;
x-=60;
x2-=60;
x3-=60;
int threey1 = threepoint1.getY();
int threex1 = threepoint1.getX()-60;
int threey2 = threepoint2.getY();
int threex2 = threepoint2.getX()-60;
int threey3 = threepoint3.getY();
int threex3 = threepoint3.getX()-60;
if( x>=0&&x<=600&&x2>=0&&x2<=600&&x3>=0&&x3<=600&&
c.getComponentAt(threex1,threey1).isEnabled()&&
c.getComponentAt(threex2,threey2).isEnabled()&&
c.getComponentAt(threex3,threey3).isEnabled() )
{
threepoint1.setLocation(x,y);
threepoint2.setLocation(x2,y2);
threepoint3.setLocation(x3,y3);
}
else{
x = xx;
x2 = xx2;
x3 = xx3;
}
}
else if(e.getKeyText(key).equals("Down")){
yy3 = y3;
yy2 = y2;
yy = y;
y+=60;
y2+=60;
y3+=60;
if(y<=600&&y2<=600&&y3<=600){
threepoint1.setLocation(x,y);
threepoint2.setLocation(x2,y2);
threepoint3.setLocation(x3,y3);
}
else{
y = yy;
y2 = yy2;
y3 = yy3;
}
}
//快速下降
else if(e.getKeyText(key).equals("F")){
int threex1 = threepoint1.getX();
int threey1 = threepoint1.getY();
int threex2 = threepoint2.getX();
int threey2 = threepoint2.getY();
int threex3 = threepoint3.getX();
int threey3 = threepoint3.getY();
while(c.getComponentAt(threex1,threey1+60).isEnabled()&&
c.getComponentAt(threex2,threey2+60).isEnabled()&&
c.getComponentAt(threex3,threey3+60).isEnabled()&&
threey1<600&&threey2<600&&threey3<600){
threey1+=60;threey2+=60;threey3+=60;
}
threepoint1.setLocation(threex1,threey1);
threepoint2.setLocation(threex2,threey2);
threepoint3.setLocation(threex3,threey3);
x=threex1;y=threey1;
x2=threex2;y2=threey2;
x3=threex3;y3=threey3;
}
//找一正方区域再进行变形
else if(e.getKeyText(key).equals("Space")){
int[] xx = new int[4];
int[] yy = new int[4];
xx[1] = threepoint1.getX();
xx[2] = threepoint2.getX();
xx[3] = threepoint3.getX();
yy[1] = threepoint1.getY();
yy[2] = threepoint2.getY();
yy[3] = threepoint3.getY();
int left = xx[1]<xx[2] ? xx[1]:xx[2];
left = left<xx[3] ? left:xx[3];
int right = xx[1]>xx[2] ? xx[1]:xx[2];
right = right>xx[3] ? right:xx[3];
int top = yy[1]<yy[2] ? yy[1]:yy[2];
top = top<yy[3] ? top:yy[3];
int bottom = yy[1]>yy[2] ? yy[1]:yy[2];
bottom = bottom>yy[3] ? bottom:yy[3];
int max = (bottom-top)>(right-left) ? (bottom-top):(right-left);
//判断是否可以变形
if(left>=0&&right<=600&&bottom>=max&&bottom<=600){
if(xx[1]==left&&yy[1]==bottom-max&&max!=120){
threepoint1.setLocation(left,bottom);
x = left; y = bottom;
}
else if(xx[1]==left&&yy[1]==bottom&&max!=120){
threepoint1.setLocation(left+max,bottom);
x = left+max; y = bottom;
}
else if(xx[1]==left+max&&yy[1]==bottom&&max!=120){
threepoint1.setLocation(left+max,bottom-max);
x = left+max; y = bottom-max;
}
else if(xx[1]==left+max&&yy[1]==bottom-max&&max!=120){
threepoint1.setLocation(left,bottom-max);
x = left; y = bottom-max;
}
else if(max==120&&top==bottom){
threepoint1.setLocation(left+60,bottom);
threepoint2.setLocation(left+60,bottom-60);
threepoint3.setLocation(left+60,bottom-120);
x = left+60; y = bottom;
x2 = left+60; y2 = bottom-60;
x3 = left+60; y3 = bottom-120;
}
else if(max==120&&left==right&&left>0&&right<600){
threepoint1.setLocation(left-60,bottom);
threepoint2.setLocation(left,bottom);
threepoint3.setLocation(left+60,bottom);
x = left-60; y = bottom;
x2 = left; y2 = bottom;
x3 = left+60; y3 = bottom;
}
if(xx[2]==left&&yy[2]==bottom-max&&max!=120){
threepoint2.setLocation(left,bottom);
x2 = left; y2 = bottom;
}
else if(xx[2]==left&&yy[2]==bottom&&max!=120){
threepoint2.setLocation(left+max,bottom);
x2 = left+max; y2 = bottom;
}
else if(xx[2]==left+max&&yy[2]==bottom&&max!=120){
threepoint2.setLocation(left+max,bottom-max);
x2 = left+max; y2 = bottom-max;
}
else if(xx[2]==left+max&&yy[2]==bottom-max&&max!=120){
threepoint2.setLocation(left,bottom-max);
x2 = left; y2 = bottom-max;
}
if(xx[3]==left&&yy[3]==bottom-max&&max!=120){
threepoint3.setLocation(left,bottom);
x3 = left; y3 = bottom;
}
else if(xx[3]==left&&yy[3]==bottom&&max!=120){
threepoint3.setLocation(left+max,bottom);
x3 = left+max; y3 = bottom;
}
else if(xx[3]==left+max&&yy[3]==bottom&&max!=120){
threepoint3.setLocation(left+max,bottom-max);
x3 = left+max; y3 = bottom-max;
}
else if(xx[3]==left+max&&yy[3]==bottom-max&&max!=120){
threepoint3.setLocation(left,bottom-max);
x3 = left; y3 = bottom-max;
}
}
}
}
});
}
/*---------------------------------------------------------------------------*/
//四点
public void getFourPoints(int r){
final JButton fourpoint1 = new JButton("1");
final JButton fourpoint2 = new JButton("2");
final JButton fourpoint3 = new JButton("3");
final JButton fourpoint4 = new JButton("4");
if(r == 0){ //四横点
fourpoint1.setBounds(180,0,60,60);
fourpoint2.setBounds(240,0,60,60);
fourpoint3.setBounds(300,0,60,60);
fourpoint4.setBounds(360,0,60,60);
this.setTitle("俄罗斯方块 四横点"+" 现在积分:"+(scores*11));
}
else if(r==1){//四竖点
fourpoint1.setBounds(300,0,60,60);
fourpoint2.setBounds(300,60,60,60);
fourpoint3.setBounds(300,120,60,60);
fourpoint4.setBounds(300,180,60,60);
this.setTitle("俄罗斯方块 四竖点"+" 现在积分:"+(scores*11));
}
else if(r==2){//左三右下一
fourpoint1.setBounds(240,0,60,60);
fourpoint2.setBounds(240,60,60,60);
fourpoint3.setBounds(240,120,60,60);
fourpoint4.setBounds(300,120,60,60);
this.setTitle("俄罗斯方块 四点之左三右下一"+" 现在积分:"+(scores*11));
}
else if(r==3){//横三右下一
fourpoint1.setBounds(240,0,60,60);
fourpoint2.setBounds(300,0,60,60);
fourpoint3.setBounds(360,0,60,60);
fourpoint4.setBounds(360,60,60,60);
this.setTitle("俄罗斯方块 四点之横三右下一"+" 现在积分:"+(scores*11));
}
else if(r==4){//左上两点右下两点
fourpoint1.setBounds(240,0,60,60);
fourpoint2.setBounds(240,60,60,60);
fourpoint3.setBounds(300,60,60,60);
fourpoint4.setBounds(300,120,60,60);
this.setTitle("俄罗斯方块 四点之左上两点右下两点"+" 现在积分:"+(scores*11));
}
else if(r==5){//左下两点右上两点
fourpoint1.setBounds(240,60,60,60);
fourpoint2.setBounds(240,120,60,60);
fourpoint3.setBounds(300,0,60,60);
fourpoint4.setBounds(300,60,60,60);
this.setTitle("俄罗斯方块 四点之左下两点右上两点"+" 现在积分:"+(scores*11));
}
else{ //田格
fourpoint1.setBounds(240,0,60,60);
fourpoint2.setBounds(300,0,60,60);
fourpoint3.setBounds(240,60,60,60);
fourpoint4.setBounds(300,60,60,60);
this.setTitle("俄罗斯方块 四点之田格"+" 现在积分:"+(scores*11));
}
fourpoint1.setBackground(Color.red);
fourpoint2.setBackground(Color.red);
fourpoint3.setBackground(Color.red);
fourpoint4.setBackground(Color.red);
c.add(fourpoint1);
c.add(fourpoint2);
c.add(fourpoint3);
c.add(fourpoint4);
fourpoint1.requestFocus();
final Thread thread=new Thread(){
public void run(){
x = fourpoint1.getX();
y = fourpoint1.getY();
y2 = fourpoint2.getY();
x2 = fourpoint2.getX();
y3 = fourpoint3.getY();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -