求java编的俄罗斯方块代码! 最好是网络版的!单机版的也好啊!谢谢诶啊
1个回答
展开全部
其实java做的俄罗斯方块游戏的源码网上有很多的,我给你一个单击版的吧,希望你喜欢,并且能研究一下,代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Els extends JFrame implements KeyListener,Runnable
{
public Els()
{
setSize(240,320);
setUndecorated(true);
int H=(int) (this.getToolkit().getScreenSize().height);
int W=(int) (this.getToolkit().getScreenSize().width);
setLocation(W/2-120,H/2-160);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
super.paint(g);
Graphics2D g2=(Graphics2D)g;
g2.setColor(Color.darkGray.brighter().brighter());
//绘制小框格
for(int m=192;m<=232;m+=10)
{
g2.drawLine(m, 52, m,92);
}
for(int m=52;m<=92;m+=10)
{
g2.drawLine(192, m, 232, m);
}
//绘制大框格
for(int m=0;m<=180;m+=15)
{
g2.drawLine(m, 0, m, 300);
}
for(int m=0;m<=300;m+=15)
{
g2.drawLine(0, m, 180, m);
}
//将值不非0的格子涂黑
for(int i=1;i<13;i++)
{
for(int j=0;j<20;j++)
{
g2.setColor(Color.DARK_GRAY);
if (o[i][j]!=0) g2.fillRect(15*i-13, 15*j+2, 13, 13);
}
}
//在小框格中绘制下一个的模型
switch(nextMODE)
{
case 0: g2.fillRect(204, 54, 8, 8);
g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 1: g2.fillRect(194, 64, 8, 8);
g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
break;
case 2: g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 84, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 3: g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(224, 74, 8, 8);
break;
case 4: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 5: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
g2.fillRect(224, 74, 8, 8);
break;
case 6: g2.fillRect(204, 54, 8, 8);
g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
break;
case 7: g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(224, 74, 8, 8);
g2.fillRect(224, 64, 8, 8);
break;
case 8: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 84, 8, 8);
break;
case 9: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
break;
case 10: g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 84, 8, 8);
break;
case 11: g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
break;
case 12: g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 13: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(224, 74, 8, 8);
break;
case 14: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
break;
}
g2.setColor(Color.black);
g2.drawLine(180, 0, 180, 300);
g2.setColor(Color.DARK_GRAY);
g2.drawString("LEVEL", 194, 10);
g2.drawString(""+LEVEL, 210, 28);
g2.drawString("NEXT", 196, 45);
g2.drawString("SCORE",193, 110);
g2.drawString(""+SCORE,205, 130);
g2.drawString("Xiong", 205, 160);
g2.drawString("Xuan", 205, 180);
}
//方块下落的方法
public void down()
{
Y++;
switch(MODE)
{
case 0: o[X+2][Y]=1;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+2][Y+3]++;
o[X+2][Y-1]=0;
break;
case 1: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
o[X][Y]=0;
o[X+1][Y]=0;
o[X+2][Y]=0;
o[X+3][Y]=0;
break;
case 2: o[X+2][Y]=1;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+1][Y+2]++;
o[X+2][Y-1]=0;
o[X+1][Y+1]=0;
break;
case 3: o[X][Y]=1;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X][Y-1]=0;
//o[X][Y]=0;
o[X+1][Y]=0;
o[X+2][Y]=0;
break;
case 4: o[X+1][Y]=1;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
break;
case 5: o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X][Y-1]=0;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
break;
case 6: o[X+1][Y]=1;
o[X+1][Y+1]=1;
o[X+1][Y+2]++;
o[X+2][Y+2]++;
o[X+1][Y-1]=0;
//o[X+1][Y]=0;
//o[X+1][Y+1]=0;
o[X+2][Y+1]=0;
break;
case 7: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y]=1;
o[X][Y]=0;
o[X+1][Y]=0;
//o[X+2][Y]=0;
o[X+2][Y-1]=0;
break;
case 8: o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
//o[X+2][Y]=0;
//o[X+2][Y+1]=0;
break;
case 9: o[X+1][Y]=1;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
o[X+3][Y-1]=0;
//o[X+1][Y]=0;
break;
case 10:o[X+1][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+1][Y-1]=0;
//o[X+1][Y]=0;
o[X+2][Y]=0;
//o[X+2][Y+1]=0;
break;
case 11:o[X+2][Y]=1;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y-1]=0;
o[X+3][Y-1]=0;
o[X+1][Y]=0;
//o[X+2][Y]=0;
break;
case 12:o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]=1;
o[X+1][Y]=0;
//o[X+2][Y]=0;
//o[X+1][Y+1]=0;
o[X+2][Y-1]=0;
break;
case 13:o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
//o[X+2][Y]=0;
o[X+3][Y]=0;
break;
case 14:o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
break;
}
//如果碰撞,则自动上升一格
for(int i=0;i<13;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) up();
}
}
}
//方块上升的方法
public void up()
{
Y--;
switch(MODE)
{
case 0: o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+2][Y+3]=1;
o[X+2][Y+4]--;
break;
case 1: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
o[X][Y+2]--;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
o[X+3][Y+2]--;
break;
case 2: o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+1][Y+2]++;
o[X+2][Y+3]--;
o[X+1][Y+3]--;
break;
case 3: o[X][Y]++;
o[X][Y+1]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X][Y+2]--;
//o[X][Y]=0;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
break;
case 4: o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]=1;
o[X+1][Y+3]--;
o[X+2][Y+1]--;
break;
case 5: o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+2]--;
break;
case 6: o[X+1][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]=1;
o[X+2][Y+2]++;
o[X+1][Y+3]--;
//o[X+1][Y]=0;
//o[X+1][Y+1]=0;
o[X+2][Y+3]--;
break;
case 7: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y]++;
o[X][Y+2]--;
o[X+1][Y+2]--;
//o[X+2][Y]=0;
o[X+2][Y+2]--;
break;
case 8: o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+1][Y+1]--;
o[X+2][Y+3]--;
//o[X+2][Y]=0;
//o[X+2][Y+1]=0;
break;
case 9: o[X+1][Y]++;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
//o[X+1][Y]=0;
break;
case 10:o[X+1][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+2][Y+2]=1;
o[X+1][Y+2]--;
//o[X+1][Y]=0;
o[X+2][Y+3]--;
//o[X+2][Y+1]=0;
break;
case 11:o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]--;
o[X+1][Y+2]--;
o[X+3][Y+1]--;
//o[X+2][Y]=0;
break;
case 12:o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+1][Y+2]=1;
o[X+2][Y]++;
o[X+2][Y+2]--;
//o[X+2][Y]=0;
//o[X+1][Y+1]=0;
o[X+1][Y+3]--;
break;
case 13:o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+3][Y+1]++;
o[X+1][Y+1]--;
o[X+2][Y+2]--;
//o[X+2][Y]=0;
o[X+3][Y+2]--;
break;
case 14:o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
break;
}
for(int i=0;i<20;i++)
{
if (o[1][i]==1&&
o[2][i]==1&&
o[3][i]==1&&
o[4][i]==1&&
o[5][i]==1&&
o[6][i]==1&&
o[7][i]==1&&
o[8][i]==1&&
o[9][i]==1&&
o[10][i]==1&&
o[11][i]==1&&
o[12][i]==1
)
{for(int k=1;k<=12;k++)
{
for(int j=i;j>=1;j--)
{
o[k][j]=o[k][j-1];
}
}
SCORE++;
if(SCORE==5)LEVEL++;
if(SCORE==10)LEVEL++;
}
}
X=5;Y=0;
MODE=nextMODE;
down();
repaint();
nextMODE=(int)(Math.random()*14);
}
public void left()
{
X--;
switch(MODE)
{
case 0:
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
o[X+3][Y]--;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
o[X+3][Y+3]--;
break;
case 1:
o[X][Y+1]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+3][Y+1]=1;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
//o[X+3][Y+1]=0;
o[X+4][Y+1]--;
break;
case 2:
//if(X==-2)X++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]=1;
o[X+1][Y+2]++;
o[X+3][Y]--;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
//o[X+2][Y+2]=0;
break;
case 3: //if(X==-1)X++;
o[X][Y]++;
o[X][Y+1]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+1][Y]--;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
break;
case 4: //if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
//o[X+2][Y]=0;
o[X+3][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
break;
case 5: //if(X==-1)X++;
o[X][Y]++;
o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+2][Y+1]++;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
o[X+3][Y]--;
o[X+3][Y+1]--;
break;
case 6: //if(X==-2)X++;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y+2]=1;
o[X+2][Y]--;
o[X+2][Y+1]--;
//o[X+2][Y+2]=0;
o[X+3][Y+2]--;
break;
case 7: //if(X==-1)X++;
o[X][Y+1]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+2][Y]++;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
o[X+3][Y]--;
break;
case 8: //if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
//o[X+2][Y]=0;
o[X+3][Y]--;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
break;
case 9: //if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+3][Y]=1;
o[X+1][Y+1]++;
//o[X+2][Y]=0;
//o[X+3][Y]=0;
o[X+4][Y]--;
o[X+2][Y+1]--;
break;
case 10://if(X==-2)X++;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+2][Y]--;
//o[X+3][Y+1]=0;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
break;
case 11://if(X==-2)X++;
o[X+2][Y]++;
o[X+3][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
//o[X+3][Y]=0;
o[X+4][Y]--;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
break;
case 12://if(X==-2)X++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+1][Y+2]++;
o[X+2][Y]++;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
o[X+2][Y+2]--;
o[X+3][Y]--;
break;
case 13://if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X+3][Y+1]=1;
//o[X+2][Y]=0;
o[X+3][Y]--;
//o[X+3][Y+1]=0;
o[X+4][Y+1]--;
break;
case 14://if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
//o[X+2][Y]=0;
o[X+3][Y]--;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
break;
}
for(int i=0;i<13;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) right();
}
}
}
public void right()
{
X++;
switch(MODE)
{
case 0:
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X+1][Y+3]--;
break;
case 1: //if(X==11)X--;
o[X][Y+1]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+3][Y+1]++;
o[X-1][Y+1]--;
//o[X][Y+1]=0;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
break;
case 2: //if(X==10)X--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+1][Y+2]=1;
o[X+1][Y]--;
o[X+1][Y+1]--;
//o[X+1][Y+2]=0;
o[X][Y+2]--;
break;
case 3:
o[X][Y]++;
o[X][Y+1]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X-1][Y]--;
o[X-1][Y+1]--;
//o[X][Y+1]=0;
//o[X+1][Y+1]=0;
break;
case 4: //if(X==10)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X][Y+1]--;
o[X][Y+2]--;
break;
case 5://if(X==10)X--;
o[X][Y]=1;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X-1][Y]--;
//o[X][Y]=0;
//o[X+1][Y]=0;
o[X+1][Y+1]--;
break;
case 6: //if(X==9)X--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]=1;
o[X+2][Y+2]++;
o[X][Y]--;
o[X][Y+1]--;
o[X][Y+2]--;
//o[X+1][Y+2]=0;
break;
case 7: //if(X==10)X--;
o[X][Y+1]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+2][Y]++;
o[X-1][Y+1]--;
//o[X][Y+1]=0;
//o[X+1][Y+1]=0;
o[X+1][Y]--;
break;
case 8: //if(X==10)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
break;
case 9: //if(X==11)X--;
o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X][Y]--;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
o[X][Y+1]--;
break;
case 10://if(X==10)X--;
o[X+1][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X][Y]--;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
o[X+1][Y+2]--;
break;
case 11://if(X==11)X--;
o[X+2][Y]=1;
o[X+3][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+1][Y]--;
//o[X+2][Y]=0;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
break;
case 12://if(X==10)X--;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]++;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
o[X][Y+2]--;
o[X+1][Y]--;
break;
case 13://if(X==11)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+3][Y+1]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X+1][Y+1]--;
//o[X+2][Y+1]=0;
break;
case 14://if(X==10)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
break;
}
for(int i=0;i<14;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) left();
}
}
}
public void change()
{
switch(MODE)
{
case 0: o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y+3]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=1;
break;
case 1: o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
MODE=0;
break;
case 2: o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
MODE=5;
break;
case 3: o[X][Y]--;
o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+1][Y+2]++;
MODE=2;
break;
case 4: o[X+1][Y]--;
o[X+2][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=3;
break;
case 5: o[X][Y]--;
o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
MODE=4;
break;
case 6: o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y]++;
MODE=7;
break;
case 7: o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=8;
break;
case 8: o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
MODE=9;
break;
case 9: o[X+1][Y]--;
o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y+2]++;
MODE=6;
break;
case 10:o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=11;
break;
case 11:o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=10;
break;
case 12:o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=13;
break;
case 13:o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]++;
MODE=12;
break;
case 14:o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
break;
}
for(int i=0;i<14;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) changeback();
}
}
}
public void changeback()
{
switch(MODE)
{
case 0:o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y+3]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=1;
break;
case 1:o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
MODE=0;
break;
case 2:o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=3;
break;
case 3:o[X][Y]--;
o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
MODE=4;
break;
case 4:o[X+1][Y]--;
o[X+2][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
MODE=5;
break;
case 5:o[X][Y]--;
o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+1][Y+2]++;
MODE=2;
break;
case 6:o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
MODE=9;
break;
case 7:o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y+2]++;
MODE=6;
break;
case 8:o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y]++;
MODE=7;
break;
case 9:o[X+1][Y]--;
o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=8;
break;
case 10:o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=11;
break;
case 11:o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=10;
break;
case 12:o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=13;
break;
case 13:o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]++;
MODE=12;
break;
case 14:o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
break;
}
}
不好意思,如果全部代码都发上来的话,就超过了10000字了,所以后面
的代码都发不了了,如果你要的话,留一下你的邮箱,我给你发过去
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Els extends JFrame implements KeyListener,Runnable
{
public Els()
{
setSize(240,320);
setUndecorated(true);
int H=(int) (this.getToolkit().getScreenSize().height);
int W=(int) (this.getToolkit().getScreenSize().width);
setLocation(W/2-120,H/2-160);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
super.paint(g);
Graphics2D g2=(Graphics2D)g;
g2.setColor(Color.darkGray.brighter().brighter());
//绘制小框格
for(int m=192;m<=232;m+=10)
{
g2.drawLine(m, 52, m,92);
}
for(int m=52;m<=92;m+=10)
{
g2.drawLine(192, m, 232, m);
}
//绘制大框格
for(int m=0;m<=180;m+=15)
{
g2.drawLine(m, 0, m, 300);
}
for(int m=0;m<=300;m+=15)
{
g2.drawLine(0, m, 180, m);
}
//将值不非0的格子涂黑
for(int i=1;i<13;i++)
{
for(int j=0;j<20;j++)
{
g2.setColor(Color.DARK_GRAY);
if (o[i][j]!=0) g2.fillRect(15*i-13, 15*j+2, 13, 13);
}
}
//在小框格中绘制下一个的模型
switch(nextMODE)
{
case 0: g2.fillRect(204, 54, 8, 8);
g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 1: g2.fillRect(194, 64, 8, 8);
g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
break;
case 2: g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 84, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 3: g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(224, 74, 8, 8);
break;
case 4: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 5: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
g2.fillRect(224, 74, 8, 8);
break;
case 6: g2.fillRect(204, 54, 8, 8);
g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
break;
case 7: g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(224, 74, 8, 8);
g2.fillRect(224, 64, 8, 8);
break;
case 8: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 84, 8, 8);
break;
case 9: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
break;
case 10: g2.fillRect(204, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 84, 8, 8);
break;
case 11: g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(224, 64, 8, 8);
break;
case 12: g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(204, 84, 8, 8);
break;
case 13: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(214, 74, 8, 8);
g2.fillRect(224, 74, 8, 8);
break;
case 14: g2.fillRect(204, 64, 8, 8);
g2.fillRect(214, 64, 8, 8);
g2.fillRect(204, 74, 8, 8);
g2.fillRect(214, 74, 8, 8);
break;
}
g2.setColor(Color.black);
g2.drawLine(180, 0, 180, 300);
g2.setColor(Color.DARK_GRAY);
g2.drawString("LEVEL", 194, 10);
g2.drawString(""+LEVEL, 210, 28);
g2.drawString("NEXT", 196, 45);
g2.drawString("SCORE",193, 110);
g2.drawString(""+SCORE,205, 130);
g2.drawString("Xiong", 205, 160);
g2.drawString("Xuan", 205, 180);
}
//方块下落的方法
public void down()
{
Y++;
switch(MODE)
{
case 0: o[X+2][Y]=1;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+2][Y+3]++;
o[X+2][Y-1]=0;
break;
case 1: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
o[X][Y]=0;
o[X+1][Y]=0;
o[X+2][Y]=0;
o[X+3][Y]=0;
break;
case 2: o[X+2][Y]=1;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+1][Y+2]++;
o[X+2][Y-1]=0;
o[X+1][Y+1]=0;
break;
case 3: o[X][Y]=1;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X][Y-1]=0;
//o[X][Y]=0;
o[X+1][Y]=0;
o[X+2][Y]=0;
break;
case 4: o[X+1][Y]=1;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
break;
case 5: o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X][Y-1]=0;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
break;
case 6: o[X+1][Y]=1;
o[X+1][Y+1]=1;
o[X+1][Y+2]++;
o[X+2][Y+2]++;
o[X+1][Y-1]=0;
//o[X+1][Y]=0;
//o[X+1][Y+1]=0;
o[X+2][Y+1]=0;
break;
case 7: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y]=1;
o[X][Y]=0;
o[X+1][Y]=0;
//o[X+2][Y]=0;
o[X+2][Y-1]=0;
break;
case 8: o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
//o[X+2][Y]=0;
//o[X+2][Y+1]=0;
break;
case 9: o[X+1][Y]=1;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
o[X+3][Y-1]=0;
//o[X+1][Y]=0;
break;
case 10:o[X+1][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+1][Y-1]=0;
//o[X+1][Y]=0;
o[X+2][Y]=0;
//o[X+2][Y+1]=0;
break;
case 11:o[X+2][Y]=1;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y-1]=0;
o[X+3][Y-1]=0;
o[X+1][Y]=0;
//o[X+2][Y]=0;
break;
case 12:o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]=1;
o[X+1][Y]=0;
//o[X+2][Y]=0;
//o[X+1][Y+1]=0;
o[X+2][Y-1]=0;
break;
case 13:o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
//o[X+2][Y]=0;
o[X+3][Y]=0;
break;
case 14:o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+1][Y-1]=0;
o[X+2][Y-1]=0;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
break;
}
//如果碰撞,则自动上升一格
for(int i=0;i<13;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) up();
}
}
}
//方块上升的方法
public void up()
{
Y--;
switch(MODE)
{
case 0: o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+2][Y+3]=1;
o[X+2][Y+4]--;
break;
case 1: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
o[X][Y+2]--;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
o[X+3][Y+2]--;
break;
case 2: o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+1][Y+2]++;
o[X+2][Y+3]--;
o[X+1][Y+3]--;
break;
case 3: o[X][Y]++;
o[X][Y+1]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X][Y+2]--;
//o[X][Y]=0;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
break;
case 4: o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]=1;
o[X+1][Y+3]--;
o[X+2][Y+1]--;
break;
case 5: o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+2]--;
break;
case 6: o[X+1][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]=1;
o[X+2][Y+2]++;
o[X+1][Y+3]--;
//o[X+1][Y]=0;
//o[X+1][Y+1]=0;
o[X+2][Y+3]--;
break;
case 7: o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y]++;
o[X][Y+2]--;
o[X+1][Y+2]--;
//o[X+2][Y]=0;
o[X+2][Y+2]--;
break;
case 8: o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]=1;
o[X+1][Y+1]--;
o[X+2][Y+3]--;
//o[X+2][Y]=0;
//o[X+2][Y+1]=0;
break;
case 9: o[X+1][Y]++;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]=1;
o[X+1][Y+2]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
//o[X+1][Y]=0;
break;
case 10:o[X+1][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+2][Y+2]=1;
o[X+1][Y+2]--;
//o[X+1][Y]=0;
o[X+2][Y+3]--;
//o[X+2][Y+1]=0;
break;
case 11:o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]--;
o[X+1][Y+2]--;
o[X+3][Y+1]--;
//o[X+2][Y]=0;
break;
case 12:o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+1][Y+2]=1;
o[X+2][Y]++;
o[X+2][Y+2]--;
//o[X+2][Y]=0;
//o[X+1][Y+1]=0;
o[X+1][Y+3]--;
break;
case 13:o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+3][Y+1]++;
o[X+1][Y+1]--;
o[X+2][Y+2]--;
//o[X+2][Y]=0;
o[X+3][Y+2]--;
break;
case 14:o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
break;
}
for(int i=0;i<20;i++)
{
if (o[1][i]==1&&
o[2][i]==1&&
o[3][i]==1&&
o[4][i]==1&&
o[5][i]==1&&
o[6][i]==1&&
o[7][i]==1&&
o[8][i]==1&&
o[9][i]==1&&
o[10][i]==1&&
o[11][i]==1&&
o[12][i]==1
)
{for(int k=1;k<=12;k++)
{
for(int j=i;j>=1;j--)
{
o[k][j]=o[k][j-1];
}
}
SCORE++;
if(SCORE==5)LEVEL++;
if(SCORE==10)LEVEL++;
}
}
X=5;Y=0;
MODE=nextMODE;
down();
repaint();
nextMODE=(int)(Math.random()*14);
}
public void left()
{
X--;
switch(MODE)
{
case 0:
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
o[X+3][Y]--;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
o[X+3][Y+3]--;
break;
case 1:
o[X][Y+1]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+3][Y+1]=1;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
//o[X+3][Y+1]=0;
o[X+4][Y+1]--;
break;
case 2:
//if(X==-2)X++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]=1;
o[X+1][Y+2]++;
o[X+3][Y]--;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
//o[X+2][Y+2]=0;
break;
case 3: //if(X==-1)X++;
o[X][Y]++;
o[X][Y+1]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+1][Y]--;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
break;
case 4: //if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
//o[X+2][Y]=0;
o[X+3][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
break;
case 5: //if(X==-1)X++;
o[X][Y]++;
o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+2][Y+1]++;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
o[X+3][Y]--;
o[X+3][Y+1]--;
break;
case 6: //if(X==-2)X++;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y+2]=1;
o[X+2][Y]--;
o[X+2][Y+1]--;
//o[X+2][Y+2]=0;
o[X+3][Y+2]--;
break;
case 7: //if(X==-1)X++;
o[X][Y+1]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+2][Y]++;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
o[X+3][Y]--;
break;
case 8: //if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
//o[X+2][Y]=0;
o[X+3][Y]--;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
break;
case 9: //if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+3][Y]=1;
o[X+1][Y+1]++;
//o[X+2][Y]=0;
//o[X+3][Y]=0;
o[X+4][Y]--;
o[X+2][Y+1]--;
break;
case 10://if(X==-2)X++;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+2][Y+2]++;
o[X+2][Y]--;
//o[X+3][Y+1]=0;
o[X+3][Y+1]--;
o[X+3][Y+2]--;
break;
case 11://if(X==-2)X++;
o[X+2][Y]++;
o[X+3][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
//o[X+3][Y]=0;
o[X+4][Y]--;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
break;
case 12://if(X==-2)X++;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
o[X+1][Y+2]++;
o[X+2][Y]++;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
o[X+2][Y+2]--;
o[X+3][Y]--;
break;
case 13://if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+2][Y+1]++;
o[X+3][Y+1]=1;
//o[X+2][Y]=0;
o[X+3][Y]--;
//o[X+3][Y+1]=0;
o[X+4][Y+1]--;
break;
case 14://if(X==-2)X++;
o[X+1][Y]++;
o[X+2][Y]=1;
o[X+1][Y+1]++;
o[X+2][Y+1]=1;
//o[X+2][Y]=0;
o[X+3][Y]--;
//o[X+2][Y+1]=0;
o[X+3][Y+1]--;
break;
}
for(int i=0;i<13;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) right();
}
}
}
public void right()
{
X++;
switch(MODE)
{
case 0:
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X+1][Y+3]--;
break;
case 1: //if(X==11)X--;
o[X][Y+1]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
o[X+3][Y+1]++;
o[X-1][Y+1]--;
//o[X][Y+1]=0;
//o[X+1][Y+1]=0;
//o[X+2][Y+1]=0;
break;
case 2: //if(X==10)X--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+1][Y+2]=1;
o[X+1][Y]--;
o[X+1][Y+1]--;
//o[X+1][Y+2]=0;
o[X][Y+2]--;
break;
case 3:
o[X][Y]++;
o[X][Y+1]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X-1][Y]--;
o[X-1][Y+1]--;
//o[X][Y+1]=0;
//o[X+1][Y+1]=0;
break;
case 4: //if(X==10)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X][Y+1]--;
o[X][Y+2]--;
break;
case 5://if(X==10)X--;
o[X][Y]=1;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X-1][Y]--;
//o[X][Y]=0;
//o[X+1][Y]=0;
o[X+1][Y+1]--;
break;
case 6: //if(X==9)X--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]=1;
o[X+2][Y+2]++;
o[X][Y]--;
o[X][Y+1]--;
o[X][Y+2]--;
//o[X+1][Y+2]=0;
break;
case 7: //if(X==10)X--;
o[X][Y+1]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+2][Y]++;
o[X-1][Y+1]--;
//o[X][Y+1]=0;
//o[X+1][Y+1]=0;
o[X+1][Y]--;
break;
case 8: //if(X==10)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
break;
case 9: //if(X==11)X--;
o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X][Y]--;
//o[X+1][Y]=0;
//o[X+2][Y]=0;
o[X][Y+1]--;
break;
case 10://if(X==10)X--;
o[X+1][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X][Y]--;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
o[X+1][Y+2]--;
break;
case 11://if(X==11)X--;
o[X+2][Y]=1;
o[X+3][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+1][Y]--;
//o[X+2][Y]=0;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
break;
case 12://if(X==10)X--;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]++;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
o[X][Y+2]--;
o[X+1][Y]--;
break;
case 13://if(X==11)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+2][Y+1]=1;
o[X+3][Y+1]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X+1][Y+1]--;
//o[X+2][Y+1]=0;
break;
case 14://if(X==10)X--;
o[X+1][Y]=1;
o[X+2][Y]++;
o[X+1][Y+1]=1;
o[X+2][Y+1]++;
o[X][Y]--;
//o[X+1][Y]=0;
o[X][Y+1]--;
//o[X+1][Y+1]=0;
break;
}
for(int i=0;i<14;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) left();
}
}
}
public void change()
{
switch(MODE)
{
case 0: o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y+3]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=1;
break;
case 1: o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
MODE=0;
break;
case 2: o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
MODE=5;
break;
case 3: o[X][Y]--;
o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+1][Y+2]++;
MODE=2;
break;
case 4: o[X+1][Y]--;
o[X+2][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=3;
break;
case 5: o[X][Y]--;
o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
MODE=4;
break;
case 6: o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y]++;
MODE=7;
break;
case 7: o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=8;
break;
case 8: o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
MODE=9;
break;
case 9: o[X+1][Y]--;
o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y+2]++;
MODE=6;
break;
case 10:o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=11;
break;
case 11:o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=10;
break;
case 12:o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=13;
break;
case 13:o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]++;
MODE=12;
break;
case 14:o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
break;
}
for(int i=0;i<14;i++)
{
for(int j=0;j<21;j++)
{
if (o[i][j]==2) changeback();
}
}
}
public void changeback()
{
switch(MODE)
{
case 0:o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y+3]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=1;
break;
case 1:o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+2][Y+3]++;
MODE=0;
break;
case 2:o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=3;
break;
case 3:o[X][Y]--;
o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
MODE=4;
break;
case 4:o[X+1][Y]--;
o[X+2][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X][Y]++;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
MODE=5;
break;
case 5:o[X][Y]--;
o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
o[X+1][Y+2]++;
MODE=2;
break;
case 6:o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y+2]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
MODE=9;
break;
case 7:o[X][Y+1]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y+2]++;
MODE=6;
break;
case 8:o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X][Y+1]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y]++;
MODE=7;
break;
case 9:o[X+1][Y]--;
o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=8;
break;
case 10:o[X+1][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+2][Y+2]--;
o[X+2][Y]++;
o[X+3][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
MODE=11;
break;
case 11:o[X+2][Y]--;
o[X+3][Y]--;
o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y]++;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+2][Y+2]++;
MODE=10;
break;
case 12:o[X+1][Y+1]--;
o[X+2][Y+1]--;
o[X+1][Y+2]--;
o[X+2][Y]--;
o[X+1][Y]++;
o[X+2][Y]++;
o[X+2][Y+1]++;
o[X+3][Y+1]++;
MODE=13;
break;
case 13:o[X+1][Y]--;
o[X+2][Y]--;
o[X+2][Y+1]--;
o[X+3][Y+1]--;
o[X+1][Y+1]++;
o[X+2][Y+1]++;
o[X+1][Y+2]++;
o[X+2][Y]++;
MODE=12;
break;
case 14:o[X+1][Y]=1;
o[X+2][Y]=1;
o[X+1][Y+1]=1;
o[X+2][Y+1]=1;
break;
}
}
不好意思,如果全部代码都发上来的话,就超过了10000字了,所以后面
的代码都发不了了,如果你要的话,留一下你的邮箱,我给你发过去
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询