当前位置:编程学习 > C#/ASP.NET >>

在C#的俄罗斯方块游戏中如何处理一个小方块可以穿墙填补下面的空格,和竖行中同一颜色的方块可以消行

    case 7:
                    pos[1] = new Point(firstPos.X, firstPos.Y);
                    pos[2] = new Point(firstPos.X, firstPos.Y);
                    pos[3] = new Point(firstPos.X, firstPos.Y);
                    break;
private bool CanMove(int direction)
{
bool canMove=true;
if(direction==0)
{
foreach(Point p in this.pos)
{
if(p.X-1<0 || this.huji[p.X-1,p.Y])
{
canMove=false;
break;
}
}
}
else if(direction==1)
{
foreach(Point p in this.pos)
{
if(p.X+1>this.leftBorder || this.huji[p.X+1,p.Y])
{
canMove=false;
break;
}
}
}
else 
{
foreach(Point p in this.pos)
{
if(p.Y+1>this.bottomBorder || this.huji[p.X,p.Y+1])
{
canMove=false;
break;
}
}
}
return canMove;
}
private void DelRows()
{
int count=0;
int highRow=20;
int lowRow=-1;
int[] delRow={-1,-1,-1,-1};
foreach(Point p in this.pos)
{
if(p.Y==highRow || p.Y==lowRow)
continue;
int i;
for(i=0;i<this.huji.GetLength(0);i++)
if(huji[i,p.Y]==false)
break;
if(i==this.huji.GetLength(0))
{
delRow[count]=p.Y;
if(p.Y<highRow)
highRow=p.Y;
if(p.Y>lowRow)
lowRow=p.Y;
count++;
}
}

if(count>0)
{
//-----------------------------------------------------------------
Graphics gra=con.CreateGraphics();
foreach(Point p in this.lastPos)
{
gra.FillRectangle(new SolidBrush(con.BackColor),p.X*this.unitPix,p.Y*unitPix,25,25);
}
foreach(Point p in this.pos)
{
this.DrawOne(p.X,p.Y,this.color,gra);
}
foreach(int i in delRow)
{
if(i>0)
{
for(int j=0;j<this.huji.GetLength(0);j++)
{
gra.FillRectangle(new SolidBrush(Color.FromArgb(60,Color.Black)),j*this.unitPix,i*unitPix,25,25);
}
}
}
System.Threading.Thread.CurrentThread.Join(180);
    
//-----------------------------------------------------------------

if(count==2 && lowRow-highRow>1)
{
for(int i=lowRow;i>highRow+1;i--)
{
for(int j=0;j<this.huji.GetLength(0);j++)
{
this.huji[j,i]=this.huji[j,i-1];
this.iori[j,i]=this.iori[j,i-1];
}
}
for(int i=highRow;i>=count;i--)
{
for(int j=0;j<this.huji.GetLength(0);j++)
{
this.huji[j,i+1]=this.huji[j,i-1];
this.iori[j,i+1]=this.iori[j,i-1];
}
}
}
else if(count==3 && lowRow-highRow>2)
{
int midRow=-1;
foreach(int row in delRow)
{
if(row!=highRow && row!=lowRow)
{
midRow=row;
break;
}
}
for(int j=0;j<this.huji.GetLength(0);j++)
{
this.huji[j,lowRow]=this.huji[j,lowRow+highRow-midRow];
}
for(int i=highRow;i>=count;i--)
{
for(int j=0;j<this.huji.GetLength(0);j++)
{
this.huji[j,i+2]=this.huji[j,i-1];
this.iori[j,i+2]=this.iori[j,i-1];
}
}
}
else
{
for(int i=lowRow;i>=count;i--)
{
for(int j=0;j<this.huji.GetLength(0);j++)
{
this.huji[j,i]=this.huji[j,i-count];
this.iori[j,i]=this.iori[j,i-count];
}
}
}
for(int i=0;i<count;i++)
{
for(int j=0;j<this.huji.GetLength(0);j++)
{
this.huji[j,i]=false;
}
PlaySound.Sound.Play(@"\sound\security.wav");
}
con.Invalidate(new Rectangle(0,0,con.Width,(lowRow+1)*this.unitPix));
this.rowDelNum+=count;
}
}
各位高手不好意思,因为这里空间有限所以我没办法把整个文件呈现。所以请高手帮忙解决。(尽快) --------------------编程问答-------------------- 看到你第一个注释就晕了,你写篇blog来讨论吧。-_-\\\
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,