俄罗斯方块游戏代码分析Word格式文档下载.docx

上传人:b****4 文档编号:6378483 上传时间:2023-05-06 格式:DOCX 页数:57 大小:27.53KB
下载 相关 举报
俄罗斯方块游戏代码分析Word格式文档下载.docx_第1页
第1页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第2页
第2页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第3页
第3页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第4页
第4页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第5页
第5页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第6页
第6页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第7页
第7页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第8页
第8页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第9页
第9页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第10页
第10页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第11页
第11页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第12页
第12页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第13页
第13页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第14页
第14页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第15页
第15页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第16页
第16页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第17页
第17页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第18页
第18页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第19页
第19页 / 共57页
俄罗斯方块游戏代码分析Word格式文档下载.docx_第20页
第20页 / 共57页
亲,该文档总共57页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

俄罗斯方块游戏代码分析Word格式文档下载.docx

《俄罗斯方块游戏代码分析Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块游戏代码分析Word格式文档下载.docx(57页珍藏版)》请在冰点文库上搜索。

俄罗斯方块游戏代码分析Word格式文档下载.docx

{

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()

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 计算机硬件及网络

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2