俄罗斯方块游戏代码分析Word格式文档下载.docx
《俄罗斯方块游戏代码分析Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块游戏代码分析Word格式文档下载.docx(57页珍藏版)》请在冰点文库上搜索。
{
Graphicsgraphics=Graphics.FromHwnd(winHandle);
Rectanglerectangle=newRectangle(SquareLocation.X,SquareLocation.Y,SquareSize.Width,SquareSize.Height);
graphics.FillRectangle(newSolidBrush(GameField.DefaultBackColor),rectangle);
}
publicvoidShow(System.IntPtrwinHandle)
GraphicsGameGraphics;
GraphicsPathgraphPath;
PathGradientBrushbrushSquare;
Color[]surroundColor;
RectanglerectSquare;
GameGraphics=Graphics.FromHwnd(winHandle);
graphPath=newGraphicsPath();
rectSquare=newRectangle(SquareLocation.X,SquareLocation.Y,SquareSize.Width,SquareSize.Height);
graphPath.AddRectangle(rectSquare);
brushSquare=newPathGradientBrush(graphPath);
brushSquare.CenterColor=foregroundColor;
brushSquare.SurroundColors=newColor[]{backgroundColor};
GameGraphics.FillPath(brushSquare,graphPath);
Square
squareLocation
squareSize
forgroundColor
backgroundColor
Hide
Show
Square.cs
2.Block对象(对应Block.cs)
组合块是由4个方块对象构成的。
其种类有7个。
Block对象包含9个字段:
Square[0]~Square[3],组合块类型blockType,,组合块的当前旋转方向机RoTation,等。
Block对象包含8个方法:
Hide()是隐藏组合块,Show()是显示组合块,Down()是组合块向下移动,类似还有Left(),Right(),Up()是对组合块进行旋转,Top()是返回组合块四个方块中最小的y坐标值。
Block
backColors
formColors
blockTpye
Random
Square[3]
Rotation
Down
Left
Right
Up
Top
block.cs
部分主要代码如下:
publicBlock(PointLocation,intnewblockType,Sizesize)
if(newblockType==7)
Randomrandom=newRandom();
this.blockType=random.Next(7);
//MessageBox.Show(this.blockType.ToString()+"
sdf"
);
else
this.blockType=newblockType;
this.size=size;
this.Location=Location;
square[0]=newSquare(Location,size,this.foreColors,this.backColors);
square[1]=newSquare(Location,size,this.foreColors,this.backColors);
square[2]=newSquare(Location,size,this.foreColors,this.backColors);
square[3]=newSquare(Location,size,this.foreColors,this.backColors);
switch(blockType)
{
case0:
{//Square型í
rotation.flag=0;
square[0].SquareLocation=newPoint(Location.X,Location.Y);
square[1].SquareLocation=newPoint(Location.X+size.Width,Location.Y);
square[2].SquareLocation=newPoint(Location.X,Location.Y+size.Height);
square[3].SquareLocation=newPoint(Location.X+size.Width,Location.Y+size.Height);
};
break;
case1:
{//Line型í
rotation.flag=rotation.North1;
square[0].SquareLocation=newPoint(Location.X,Location.Y);
square[1].SquareLocation=newPoint(Location.X,Location.Y+size.Height);
square[2].SquareLocation=newPoint(Location.X,Location.Y+size.Height*2);
square[3].SquareLocation=newPoint(Location.X,Location.Y+size.Height*3);
break;
case2:
{//J型í
rotation.flag=rotation.West1;
square[0].SquareLocation=newPoint(Location.X+size.Width,Location.Y);
square[1].SquareLocation=newPoint(Location.X+size.Width,Location.Y+size.Height);
square[2].SquareLocation=newPoint(Location.X+size.Width,Location.Y+size.Height*2);
square[3].SquareLocation=newPoint(Location.X,Location.Y+size.Height*2);
case3:
{//L型í
rotation.flag=rotation.East1;
square[3].SquareLocation=newPoint(Location.X+size.Width,Location.Y+size.Height*2);
case4:
{//T型í
rotation.flag=rotation.South1;
square[1].SquareLocation=newPoint(Location.X+size.Width,Location.Y);
square[2].SquareLocation=newPoint(Location.X+size.Width*2,Location.Y);
square[3].SquareLocation=newPoint(Location.X+size.Width,Location.Y+size.Height);
case5:
{//Z型í
square[1].SquareLocation=newPoint(Location.X+size.Width,Location.Y);
square[2].SquareLocation=newPoint(Location.X+size.Width,Location.Y+size.Height);
square[3].SquareLocation=newPoint(Location.X+size.Width*2,Location.Y+size.Height);
case6:
{//S型í
square[0].SquareLocation=newPoint(Location.X,Location.Y+size.Height);
square[2].SquareLocation=newPoint(Location.X+size.Width,Location.Y);
square[3].SquareLocation=newPoint(Location.X+size.Width*2,Location.Y);
default:
//rotation.North1=rotation.South1=1;
publicvoidHide(System.IntPtrwinHandle)
foreach(Squaresinsquare)
s.Hide(winHandle);
publicvoidShow(System.IntPtrwinHandle)
s.Show(winHandle);
publicboolDown()
if(GameField.IsEmpty(square[0].SquareLocation.X/GameField.SquareSize,square[0].SquareLocation.Y/GameField.SquareSize+1)&
&
GameField.IsEmpty(square[1].SquareLocation.X/GameField.SquareSize,square[1].SquareLocation.Y/GameField.SquareSize+1)&
GameField.IsEmpty(square[2].SquareLocation.X/GameField.SquareSize,square[2].SquareLocation.Y/GameField.SquareSize+1)&
GameField.IsEmpty(square[3].SquareLocation.X/GameField.SquareSize,square[3].SquareLocation.Y/GameField.SquareSize+1))
Hide(GameField.winHandle);
square[0].SquareLocation=newPoint(square[0].SquareLocation.X,square[0].SquareLocation.Y+GameField.SquareSize);
square[1].SquareLocation=newPoint(square[1].SquareLocation.X,square[1].SquareLocation.Y+GameField.SquareSize);
square[2].SquareLocation=newPoint(square[2].SquareLocation.X,square[2].SquareLocation.Y+GameField.SquareSize);
square[3].SquareLocation=newPoint(square[3].SquareLocation.X,square[3].SquareLocation.Y+GameField.SquareSize);
Show(GameField.winHandle);
returntrue;
foreach(Squaresinsquare)
GameField.StopSquare(s,s.SquareLocation.X/GameField.SquareSize,s.SquareLocation.Y/GameField.SquareSize);
returnfalse;
publicboolLeft()
if(GameField.IsEmpty(square[0].SquareLocation.X/GameField.SquareSize-1,square[0].SquareLocation.Y/GameField.SquareSize)&
GameField.IsEmpty(square[1].SquareLocation.X/GameField.SquareSize-1,square[1].SquareLocation.Y/GameField.SquareSize)&
GameField.IsEmpty(square[2].SquareLocation.X/GameField.SquareSize-1,square[2].SquareLocation.Y/GameField.SquareSize)&
GameField.IsEmpty(square[3].SquareLocation.X/GameField.SquareSize-1,square[3].SquareLocation.Y/GameField.SquareSize))
square[0].SquareLocation=newPoint(square[0].SquareLocation.X-GameField.SquareSize,square[0].SquareLocation.Y);
square[1].SquareLocation=newPoint(square[1].SquareLocation.X-GameField.SquareSize,square[1].SquareLocation.Y);
square[2].SquareLocation=newPoint(square[2].SquareLocation.X-GameField.SquareSize,square[2].SquareLocation.Y);
square[3].SquareLocation=newPoint(square[3].SquareLocation.X-GameField.SquareSize,square[3].SquareLocation.Y);
if((square[0].SquareLocation.X/GameField.SquareSize)<
0)
square[0].SquareLocation=newPoint(0,square[0].SquareLocation.Y);
returntrue;
publicboolRight()
if(GameField.IsEmpty(square[0].SquareLocation.X/GameField.SquareSize+1,square[0].SquareLocation.Y/GameField.SquareSize)&
GameField.IsEmpty(square[1].SquareLocation.X/GameField.SquareSize+1,square[1].SquareLocation.Y/GameField.SquareSize)&
GameField.IsEmpty(square[2].SquareLocation.X/GameField.SquareSize+1,square[2].SquareLocation.Y/GameField.SquareSize)&
GameField.IsEmpty(square[3].SquareLocation.X/GameField.SquareSize+1,square[3].SquareLocation.Y/GameField.SquareSize))
square[0].SquareLocation=newPoint(square[0].SquareLocation.X+GameField.SquareSize,square[0].SquareLocation.Y);
square[1].SquareLocation=newPoint(square[1].SquareLocation.X+GameField.SquareSize,square[1].SquareLocation.Y);
square[2].SquareLocation=newPoint(square[2].SquareLocation.X+GameField.SquareSize,square[2].SquareLocation.Y);
square[3].SquareLocation=newPoint(square[3].SquareLocation.X+GameField.SquareSize,square[3].SquareLocation.Y);
if((square[3].SquareLocation.X/GameField.SquareSize)>
15)
square[3].SquareLocation=newPoint(15*GameField.SquareSize,square[3].SquareLocation.Y);
publicvoidUp()