俄罗斯方块游戏课设报告.docx

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

俄罗斯方块游戏课设报告.docx

《俄罗斯方块游戏课设报告.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块游戏课设报告.docx(48页珍藏版)》请在冰点文库上搜索。

俄罗斯方块游戏课设报告.docx

俄罗斯方块游戏课设报告

j

成绩评定表

学生姓名

班级学号

专业

计算机科学与技术

课程设计题目

俄罗斯方块游戏

 

 

组长签字:

成绩

 

日期

2014年1月14日

课程设计任务书

学院

信息科学与工程学院

专业

计算机科学与技术

学生姓名

班级学号

课程设计题目

俄罗斯方块游戏

实践教学要求与任务:

本系统为一个用C#实现的为我们所熟悉的简单的俄罗斯方块游戏,该系统的具体功能如下:

(1)能简便的开始游戏,游戏中的方块的功能与日常我们所熟悉的游戏的功能一致,各种块的设置也一致,包括块的旋转,加速下降,平移,满行消去,到顶游戏结束功能;

(2)能够自定义游戏中功能键的具体按键,设置游戏的级别,即方块下降的速等,并在设置后立即生效,在游戏中立刻体现,在下次程序运行时读取上次设置的游戏环境;

(3)显示下一方块提示信息,以及游戏数据的统计,如速度,按键速度,分数行者等等;

(4)游戏有级别设置,级别越高,方块下降的速度越快,当到达一定分数后进入下一级别;

 

工作计划与进度安排:

第19周:

软件设计,编码调试,书写课设报告,答辩。

指导教师:

2013年12月26日

专业负责人:

2013年12月27日

学院教学副院长:

2013年12月28日

 

 

一、要求和规范

1、需求分析

本系统为一个用C#实现的为我们所熟悉的简单的俄罗斯方块游戏,该系统的具体功能如下:

【1】能简便的开始游戏,游戏中的方块的功能与日常我们所熟悉的游戏的功能一致,各种块的设置也一致,包括块的旋转,加速下降,平移,满行消去,到顶游戏结束功能;

【2】能够自定义游戏中功能键的具体按键,设置游戏的级别,即方块下降的速度等,并在设置后立即生效,在游戏中立刻体现,在下次程序运行时读取上次设置的游戏环境;

【3】显示下一方块提示信息,以及游戏数据的统计,如速度,按键速度,分数行者等等;

【4】游戏有级别设置,级别越高,方块下降的速度越快,当到达一定分数后进入下一级别;

2、界面要求

要求界面简洁美观,简单易用。

3.设计环境

本程序选择VisualStudio2010作为实验环境。

二、设计思路

1、用面向对象的方法分析系统

对于俄罗斯方块来说,我们可以定义一个类,专门来描述俄罗斯方块,在这个类中,包含与之相关的方法、属性和字段,通过封装,实现其业务逻辑。

其中,每一个俄罗斯方块都有相同的特征,由4个小正方形构成,有旋转,移动,下落的动作,行被填满除去构成行的小正方体块。

基中块的形状类型有7种:

田、一、L、倒L、Z、倒Z、上。

在主窗口中,通过调用俄罗斯方块类来实现程序的表示层,在该窗口中通过两个Panel控件来实现方块叠放窗口和下一方块信息窗口;调用设置窗口,保存设计窗口类传回的信息,并设置到游戏中去,保存在配置文件中;

2、概要设计

根据设计思路,可以为系统设计三个类,实现俄罗斯方块其本块的类RussiaBlock继承Object类,主窗体类MainForm类。

3、流程图

 

 

 

4、软件开发过程

1、新项目的建立

打开VisualC#.NET2005,从主菜单中选择“文件”/“新建”/“项目”,在弹出的“新建项目”对话框中,在左侧“已安装的模板”中选择VisaulC#/Windows,在中间位置选择“windows应用程序”,在“名称”中输入项目名称“RussiaBlock”,最后按确定按钮,建立新项目。

如图1所示

图1.建立新项目“RussiaBlock”

在编辑器右侧文件树上,鼠标右键单击Form1.cs,选择“重命名(M)”,修改名称为:

MainForm.cs

 

2、主界面的建立

从工具箱中选择合适的控件,加入窗体中。

例如:

添加Label控件,修改右下侧属性列表中(Name)为Label1,属性Text为手速:

如图2所

其余控件按下表1所列添加。

 

图2.Label控件的添加

控件类型

属性名称

属性值

1

Label

(name)

Lable1

Text

手速:

ForeColor

Red

2

Label

(name)

Lable2

Text

块数:

ForeColor

Red

3

Label

(name)

Lable3

Text

行数:

ForeColor

Red

4

Label

(name)

Lable4

Text

级别:

ForeColor

Red

5

panel

(name)

panel1

size

251,501

ForeColor

Black

Location

12,12

6

panel

(name)

Panel2

size

81,48

ForeColor

Black

Location

16,8(放入panel3中)

7

panel

(name)

Panel3

size

112,72

ForeColor

Black

Location

300,12

8

button

(name)

button1

Text

开始

9

button

(name)

Button4

Text

暂停

10

timer

(name)

Timer1

Interval

200

11

TextBox

(name)

TextBox1

size

1,21

Location

388,338

 

表1.添加控件数据

主界面完成后效果如图3所示。

 

图3.主界面示意图

3、程序的编写

(1)为工程添加新类,名称:

Block.cs

双击新类Block.cs,进入编辑代码,添加引用

usingSystem.Drawing;

usingSystem.Windows.Forms;

(2)编辑类SnakeNode中代码,如下内容:

namespaceRussiaBlock

{

publicclassBlock

{

publicBlock(Controlcon,intleftBorder,intbottomBorder,intunitPix,intshapeNO,PointfirstPos,Colorcolor)

{

this.con=con;

this.leftBorder=leftBorder;

this.bottomBorder=bottomBorder;

this.unitPix=unitPix;

this.SetPos(shapeNO,firstPos);

this.color=color;

this.huji=newbool[leftBorder+1,bottomBorder+1];

this.iori=newColor[leftBorder+1,bottomBorder+1];

this.lastPos=newPoint[4];

}

privateintshapeNO;//形状号

privateControlcon;//绘图控件

privatePoint[]pos;//当前位置

privatePoint[]lastPos;//上一次位置

privateintleftBorder;//左边界

privateintbottomBorder;//下边界

privateintunitPix;//每块象素数

privateintblockNum=0;

privateintrowDelNum=0;

privatebool[,]huji;

privateColor[,]iori;

privateColorcolor;//当前块颜色

publicvoidEraseLast()

{

foreach(Pointpinthis.lastPos)

{

this.con.Invalidate(newRectangle(p.X*unitPix,p.Y*unitPix,unitPix+1,unitPix+1));

}

}

privatevoidSetLastPos()

{

for(inti=0;i

{

this.lastPos[i]=this.pos[i];

}

}

privatevoidSetPos(intshapeNO,PointfirstPos)

{

this.shapeNO=shapeNO;

this.pos=newPoint[4];

pos[0]=firstPos;

switch(shapeNO)

{

case1:

pos[1]=newPoint(firstPos.X+1,firstPos.Y);

pos[2]=newPoint(firstPos.X,firstPos.Y+1);

pos[3]=newPoint(firstPos.X+1,firstPos.Y+1);

break;

case2:

pos[1]=newPoint(firstPos.X+1,firstPos.Y);

pos[2]=newPoint(firstPos.X+2,firstPos.Y);

pos[3]=newPoint(firstPos.X+3,firstPos.Y);

break;

case3:

pos[1]=newPoint(firstPos.X+1,firstPos.Y);

pos[2]=newPoint(firstPos.X+1,firstPos.Y+1);

pos[3]=newPoint(firstPos.X+2,firstPos.Y);

break;

case4:

pos[1]=newPoint(firstPos.X+1,firstPos.Y);

pos[2]=newPoint(firstPos.X+1,firstPos.Y+1);

pos[3]=newPoint(firstPos.X+2,firstPos.Y+1);

break;

case5:

pos[1]=newPoint(firstPos.X+1,firstPos.Y);

pos[2]=newPoint(firstPos.X+1,firstPos.Y-1);

pos[3]=newPoint(firstPos.X+2,firstPos.Y-1);

break;

case6:

pos[1]=newPoint(firstPos.X,firstPos.Y+1);

pos[2]=newPoint(firstPos.X+1,firstPos.Y);

pos[3]=newPoint(firstPos.X+2,firstPos.Y);

break;

default:

pos[1]=newPoint(firstPos.X+1,firstPos.Y);

pos[2]=newPoint(firstPos.X+2,firstPos.Y);

pos[3]=newPoint(firstPos.X+2,firstPos.Y+1);

break;

}

}

privateboolCanMove(intdirection)

{

boolcanMove=true;

if(direction==0)

{

foreach(Pointpinthis.pos)

{

if(p.X-1<0||this.huji[p.X-1,p.Y])

{

canMove=false;

break;

}

}

}

elseif(direction==1)

{

foreach(Pointpinthis.pos)

{

if(p.X+1>this.leftBorder||this.huji[p.X+1,p.Y])

{

canMove=false;

break;

}

}

}

else

{

foreach(Pointpinthis.pos)

{

if(p.Y+1>this.bottomBorder||this.huji[p.X,p.Y+1])

{

canMove=false;

break;

}

}

}

returncanMove;

}

privateboolCanRotate(Point[]pos)

{

boolcanRotate=true;

foreach(Pointpinpos)

{

if(p.X<0||p.X>this.leftBorder||p.Y<0||p.Y>this.bottomBorder||this.huji[p.X,p.Y])

{

canRotate=false;

break;

}

}

if(canRotate==true)

this.SetLastPos();

returncanRotate;

}

privatevoidDelRows()

{

intcount=0;

inthighRow=20;

intlowRow=-1;

int[]delRow={-1,-1,-1,-1};

foreach(Pointpinthis.pos)

{

if(p.Y==highRow||p.Y==lowRow)

continue;

inti;

for(i=0;i

if(huji[i,p.Y]==false)

break;

if(i==this.huji.GetLength(0))

{

delRow[count]=p.Y;

if(p.Y

highRow=p.Y;

if(p.Y>lowRow)

lowRow=p.Y;

count++;

}

}

if(count>0)

{

//-----------------------------------------------------------------

Graphicsgra=con.CreateGraphics();

foreach(Pointpinthis.lastPos)

{

gra.FillRectangle(newSolidBrush(con.BackColor),p.X*this.unitPix,p.Y*unitPix,25,25);

}

foreach(Pointpinthis.pos)

{

this.DrawOne(p.X,p.Y,this.color,gra);

}

foreach(intiindelRow)

{

if(i>0)

{

for(intj=0;j

{

gra.FillRectangle(newSolidBrush(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(inti=lowRow;i>highRow+1;i--)

{

for(intj=0;j

{

this.huji[j,i]=this.huji[j,i-1];

this.iori[j,i]=this.iori[j,i-1];

}

}

for(inti=highRow;i>=count;i--)

{

for(intj=0;j

{

this.huji[j,i+1]=this.huji[j,i-1];

this.iori[j,i+1]=this.iori[j,i-1];

}

}

}

elseif(count==3&&lowRow-highRow>2)

{

intmidRow=-1;

foreach(introwindelRow)

{

if(row!

=highRow&&row!

=lowRow)

{

midRow=row;

break;

}

}

for(intj=0;j

{

this.huji[j,lowRow]=this.huji[j,lowRow+highRow-midRow];

}

for(inti=highRow;i>=count;i--)

{

for(intj=0;j

{

this.huji[j,i+2]=this.huji[j,i-1];

this.iori[j,i+2]=this.iori[j,i-1];

}

}

}

else

{

for(inti=lowRow;i>=count;i--)

{

for(intj=0;j

{

this.huji[j,i]=this.huji[j,i-count];

this.iori[j,i]=this.iori[j,i-count];

}

}

}

for(inti=0;i

{

for(intj=0;j

{

this.huji[j,i]=false;

}

}

con.Invalidate(newRectangle(0,0,con.Width,(lowRow+1)*this.unitPix));

this.rowDelNum+=count;

}

}

publicvoidFixBlock()

{

this.blockNum++;

foreach(Pointpinthis.pos)

{

this.huji[p.X,p.Y]=true;

this.iori[p.X,p.Y]=this.color;

}

this.DelRows();

}

publicboolGeneBlock(intshapeNO,PointfirstPos,Colorcolor)

{

this.SetLastPos();

this.EraseLast();

this.SetPos(shapeNO,firstPos);

if(!

this.CanRotate(this.pos))

{

this.pos=null;

returnfalse;

}

else

{

this.color=color;

returntrue;

}

}

publicboolRotate()

{

boolrotated=true;

Point[]temp={pos[0],pos[1],pos[2],pos[3]};

switch(this.shapeNO)

{

case1:

rotated=false;

break;

case2:

temp[0].Offset(2,2);

temp[1].Offset(1,1);

temp[3].Offset(-1,-1);

if(this.CanRotate(temp))

{

this.pos[0].Offset(2,2);

this.pos[1].Offset(1,1);

this.pos[3].Offset(-1,-1);

this.shapeNO=8;

}

else

rotated=false;

break;

case3:

temp[0].Offset(1,-1);

if(this.CanRotate(temp))

{

this.pos[0].Offset(1,-1);

this.shapeNO=9;

}

else

rotated=false;

break;

case4:

temp[0].Offset(2,0);

temp[1].Offset(0,2);

if(this.CanRotate(temp))

{

this.pos[0].Offset(2,0);

this.pos[1].Offset(0,2);

this.shapeNO=12;

}

else

{

rotated=false;

}

break;

case5:

temp[2].Offset(-1,0);

temp[3].Offset(-1,2);

if(this.CanRotate(temp))

{

this.pos[2].Offset(-1,0);

this.pos[3].Offset(-1,2);

this.shapeNO=13;

}

else

{

rotated=false;

}

break;

case6:

temp[0].Offset(1,1);

temp[1].Offset(2,0);

temp[3].Offset(-1,-1);

if(this.CanRotate(temp))

{

this.pos[0].Offset(1,1);

this.pos[1].Offset(2,0);

this.pos[3].Offset(-1,-1);

this.shapeNO=14;

}

else

{

rotated=false;

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

当前位置:首页 > 工程科技

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

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