可视化程序设计.docx

上传人:b****8 文档编号:30241416 上传时间:2023-08-13 格式:DOCX 页数:21 大小:18.68KB
下载 相关 举报
可视化程序设计.docx_第1页
第1页 / 共21页
可视化程序设计.docx_第2页
第2页 / 共21页
可视化程序设计.docx_第3页
第3页 / 共21页
可视化程序设计.docx_第4页
第4页 / 共21页
可视化程序设计.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

可视化程序设计.docx

《可视化程序设计.docx》由会员分享,可在线阅读,更多相关《可视化程序设计.docx(21页珍藏版)》请在冰豆网上搜索。

可视化程序设计.docx

可视化程序设计

 

《可视化程序设计》

——课程设计报告

题目:

俄罗斯游戏方块

班级:

04级本一班

成员:

吴晓娟(0419411046)

赵粉娟(0419411035)

白冰(0419411034)

专业:

计算机科学与技术

日期:

2008-1-07

一、设计内容

创建一个单文档应用程序,设计一个简单的俄罗斯方块游戏,能够完成俄罗斯方块游戏的基本功能。

二、设计目的

通过本实验来巩固本学期中所学的Vc++中的类的使用,菜单资源的添加及使用,学会进行消息影射,能够实现对键盘消息进行响应。

三、设计要求

要求通过键盘上的左右方向键来控制游戏中方块的左右移动,通过键盘上的向上键来改变方块的排列方向,同过向下的键来使方块直接移动到下面。

通过在菜单栏里面的skill下的1,2,3,4来选择游戏的难度。

四、设计原理

先在菜单资源中添加和修改相应的资源,并对其进行消息映射,再在CView中添加相应的函数和变量完成相应的设置以实现其功能。

主要是通过键盘消息响应实现各个方块的移动和变化。

通过计时器实现游戏难度的设置。

用数组的方式来表示游戏中的格子,每种不同排列的方块用不同的颜色来表示。

方块移动时使用填充和绘制的方式来实现。

五、设计步骤

1)创建MFC单文档应用程序。

2)添加和修改菜单资源,并进行消息映射。

3)利用ClassWizard添加成员变量。

4)利用ClassWizard添加成员函数及结构体point。

六、设计总结

通过本次实验,巩固和更深的理解了本学期所学的知识,理解了类的定义,资源的添加和消息映射,对键盘消息的响应有了更好的掌握,

七、主要源码

具体代码如下:

添加的成员变量如下:

COLORREFtempcolor,color[20][10];voidmyDraw();inttime;voidStar();

intcount;voidIsover();intdop();intIsbottom();intIsout(intw);intround(intas);

voidclean(intb);intindex;intR;intL;intH;intcor[20][10];intJ;

CBitmap*m_pbmpContents;//togetafasterupdateifflickerfreeison

intK;BOOLflag,flag2;intY;intX;intk;pointaa[4],bb[4],dd[4];

添加成员函数及其代码如下:

intCFanView:

:

OnCreate(LPCREATESTRUCTlpCreateStruct)

//初始化游戏界面

{if(CView:

:

OnCreate(lpCreateStruct)==-1)

return-1;

flag2=0;

k=0;

time=500;

K=0;

Y=0;

for(inti=0;i<20;i++)

{for(intj=0;j<11;j++)

{cor[i][j]=0;

}

}

count=0;

R=0;

L=0;

H=0;

index=0;

flag=0;

Star();

SetTimer(IDC_TIMER,time,NULL);

return0;

}

//设置定时器

voidCFanView:

:

OnTimer(UINTnIDEvent)

{Y=1;

if(K)

{if(Isbottom())

{flag=1;

clean(0);

R=R+2;

for(inta=0;a<4;a++)

{aa[a].x++;

}

myDraw();

}

elseif(K)

{Isover();

Star();

flag=1;

}

}

Y=0;

CView:

:

OnTimer(nIDEvent);

}

voidCFanView:

:

clean(intb)

{for(inta=0;a<4;a++)

{cor[aa[a].x][aa[a].y]=0;

dd[a].x=aa[a].x;

dd[a].y=aa[a].y;

}

}

intCFanView:

:

round(intas)

{inttempx=0,tempy=0,a,d=0,h=0;

inttemp2=0,temp1=0;

for(a=0;a<4;a++)

{bb[a].x=aa[a].x;

bb[a].y=aa[a].y;

}

if(index==1)

{temp1=aa[2].x;

temp2=aa[2].y;

h=2;

}

else

{temp1=aa[1].x;

temp2=aa[1].y;

h=1;

}

for(a=0;a<4;a++)

{if(a!

=h)

{tempx=(aa[a].x-temp1);

tempy=(aa[a].y-temp2);

aa[a].x=tempy+temp1;

aa[a].y=-tempx+temp2;

if((cor[aa[a].x][aa[a].y]==2)||(aa[a].y>9)||(aa[a].y<0)||(aa[a].x>19)||(aa[a].x<0))

{for(intd=0;d<4;d++)

{aa[d].x=bb[d].x;

aa[d].y=bb[d].y;

}

return0;

}

}

}

return1;

}

intCFanView:

:

Isout(intw)

{if(w==2)

{for(inta=0;a<4;a++)

{if((aa[a].y>=9)||(cor[aa[a].x][aa[a].y+1]==2))

{return1;

}

}

}

if(w==1)

{for(inta=0;a<4;a++)

{if((aa[a].y<=0)||(cor[aa[a].x][aa[a].y-1]==2))

{return2;

}

}

}

return3;

}

intCFanView:

:

Isbottom()

{for(inta=0;a<4;a++)

{if(aa[a].x==19)

{for(intc=0;c<4;c++)

{cor[aa[c].x][aa[c].y]=2;

color[aa[c].x][aa[c].y]=tempcolor;

flag2=1;

}

k=0;

return0;

}

if(cor[aa[a].x+1][aa[a].y]==2)

{for(intc=0;c<4;c++)

{cor[aa[c].x][aa[c].y]=2;

color[aa[c].x][aa[c].y]=tempcolor;

flag2=1;

}

k=0;

return0;

}

}

return1;

}

intCFanView:

:

dop()

{for(intu=0;u<20;u++)

{for(inta=0;a<4;a++)

{if(cor[aa[a].x+1][aa[a].y]==2)

{for(intc=0;c<4;c++)

{cor[aa[c].x][aa[c].y]=2;

color[aa[c].x][aa[c].y]=tempcolor;

flag2=1;

}

//flag=1;

return0;

}

}

for(a=0;a<4;a++)

{if(aa[a].x==19)

{for(intc=0;c<4;c++)

{cor[aa[c].x][aa[c].y]=2;

color[aa[c].x][aa[c].y]=tempcolor;

flag2=1;

}

//flag=1;

return0;

}

}

for(into=0;o<4;o++)

{aa[o].x=aa[o].x+1;

}

}

return1;

}

voidCFanView:

:

Isover()

{intflagover=0,n=0;

for(inta=19;a>=0;a--)

{flagover=0;

for(intb=0;b<10;b++)

{if(cor[a][b]==2)

{flagover++;

}

}

if(flagover==10)

{count=count+100;

for(b=0;b<10;b++)

{cor[a][b]=0;

color[a][b]=RGB(255,255,255);

}

for(intt=a;t>0;t--)

{for(b=0;b<10;b++)

{if(cor[t-1][b]==2)

{cor[t][b]=2;

color[t][b]=color[t-1][b];

flag2=1;

cor[t-1][b]=0;

color[t-1][b]=RGB(255,255,255);

}

}

}

a=a+1;

}

}

for(a=0;a<9;a++)

{if(cor[0][a]==2)

{KillTimer(IDC_TIMER);

MessageBox("游戏结束");

//clean

(1);

count=0;

for(inti=0;i<20;i++)

{for(intj=0;j<10;j++)

{cor[i][j]=0;

flag2=1;

}

}

SetTimer(IDC_TIMER,time,NULL);

}

}

CMainFrame*frame=(CMainFrame*)AfxGetMainWnd();

UINTnID,nStyle;

intcxwidth;

frame->m_wndStatusBar.GetPaneInfo(0,nID,nStyle,cxwidth);

frame->m_wndStatusBar.SetPaneInfo(0,nID,SBPS_STRETCH|SBPS_NORMAL,cxwidth);

CStringcs;

frame->m_wndStatusBar.SetPaneText(0,cs);

}

//初始设置游戏的七个方块

voidCFanView:

:

Star()

{for(inti=0;i<4;i++)

{aa[i].x=0;

aa[i].y=0;

}

R=0;

H=5;

index=rand()%7;

switch(index)

{case1:

aa[0].x=R;

aa[0].y=H;

aa[1].x=R;

aa[1].y=H+1;

aa[2].x=R;

aa[2].y=H-1;

aa[3].x=R;

aa[3].y=H-2;

tempcolor=RGB(80,154,175);

cor[R][H]=1;

cor[R][H+1]=1;

cor[R][H-1]=1;

cor[R][H-2]=1;*/

break;

case2:

aa[0].x=R;

aa[0].y=H;

aa[1].x=R;

aa[1].y=H+1;

aa[2].x=R+1;

aa[2].y=H+1;

aa[3].x=R+1;

aa[3].y=H+2;

tempcolor=RGB(43,213,140);

break;

case3:

aa[0].x=R;

aa[0].y=H;

aa[1].x=R;

aa[1].y=H+1;

aa[2].x=R-1;

aa[2].y=H+1;

aa[3].x=R-1;

aa[3].y=H+2;

tempcolor=RGB(233,149,22);

break;

case4:

aa[0].x=R;

aa[0].y=H;

aa[1].x=R;

aa[1].y=H+1;

aa[2].x=R;

aa[2].y=H+2;

aa[3].x=R+1;

aa[3].y=H+2;

tempcolor=RGB(210,23,191);

break;

case5:

aa[0].x=R;

aa[0].y=H;

aa[1].x=R;

aa[1].y=H+1;

aa[2].x=R;

aa[2].y=H+2;

aa[3].x=R-1;

aa[3].y=H+2;

tempcolor=RGB(9,24,225);

break;

case6:

aa[0].x=R;

aa[0].y=H;

aa[1].x=R+1;

aa[1].y=H;

aa[2].x=R+1;

aa[2].y=H+1;

aa[3].x=R+1;

aa[3].y=H-1;

tempcolor=RGB(5,228,211);

break;

case0:

aa[0].x=R;

aa[0].y=H;

aa[1].x=R;

aa[1].y=H+1;

aa[2].x=R+1;

aa[2].y=H;

aa[3].x=R+1;

aa[3].y=H+1;

tempcolor=RGB(77,68,70);

break;

}

myDraw();

K=1;

}

//根据时间来设置游戏的难易程度

voidCFanView:

:

On1()

{time=1000;

}

voidCFanView:

:

OnUpdate1(CCmdUI*pCmdUI)

{if(time==1000)

{pCmdUI->SetCheck

(1);

}

else

{pCmdUI->SetCheck(0);

}

}

voidCFanView:

:

On2()

{time=300;

}

voidCFanView:

:

OnUpdate2(CCmdUI*pCmdUI)

{if(time==300)

{pCmdUI->SetCheck

(1);

}

else

{pCmdUI->SetCheck(0);

}

}

voidCFanView:

:

On3()

{time=60;

}

voidCFanView:

:

OnUpdate3(CCmdUI*pCmdUI)

{if(time==60)

{pCmdUI->SetCheck

(1);

}

else

{pCmdUI->SetCheck(0);

}

}

//键盘响应消息映射

voidCFanView:

:

OnKeyDown(UINTnChar,UINTnRepCnt,UINTnFlags)

{if(!

Y)

{K=0;

switch(nChar)

{caseVK_LEFT:

caseVK_NUMPAD4:

if(!

(Isout

(1)==2))

{flag=1;

clean(0);

H--;

for(inta=0;a<4;a++)

{aa[a].y--;

}

//Invalidate();

}

break;

caseVK_RIGHT:

caseVK_NUMPAD6:

if(!

(Isout

(2)==1))

{flag=1;

clean(0);

H++;

for(inta=0;a<4;a++)

{aa[a].y++;

}

//Invalidate();

}

break;

caseVK_DOWN:

caseVK_NUMPAD2:

clean(0);

dop();

Isover();

Star();

break;

caseVK_UP:

caseVK_NUMPAD8:

caseVK_NUMPAD5:

clean(0);

k++;

round(k);

//Invalidate();

break;

}

K=1;

}

myDraw();

//OnPaint();

CView:

:

OnKeyDown(nChar,nRepCnt,nFlags);

}

voidCFanView:

:

OnPaint()

{CPaintDCpdc(this);//devicecontextforpainting

//ShowWindow(SW_HIDE);

COLORREFclrTopLeft=RGB(68,71,140);

COLORREFclrBottomRight=RGB(70,166,152);

COLORREFclrTopLeft2=:

:

GetSysColor(COLOR_BTNHILIGHT);

COLORREFclrBottomRight2=:

:

GetSysColor(COLOR_BTNSHADOW);

CRectrect;

CMemDCdc(&pdc);

registerconstUINTwide=20;

registerconstUINThight=20;

//painttheboarditself

if(flag)

{for(inta=0;a<4;a++)

{cor[aa[a].x][aa[a].y]=1;

}

for(intx=0;x<20;x++)

{for(intj=0;j<10;j++)

{if(cor[x][j]==1)

{dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft);

dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft,clrBottomRight);

}

}

}

}

for(intx=0;x<20;x++)

{for(intj=0;j<10;j++)

{dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft2);

dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft,clrTopLeft2);

}

}

for(x=0;x<20;x++)

{for(intj=0;j<10;j++)

{if((cor[x][j]==1)||(cor[x][j]==2))

{dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft);

dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft,clrBottomRight);

}

}

}

}

//游戏过程中界面的变化过程

voidCFanView:

:

myDraw()

{CDC*dc=GetDC();

COLORREFclrTopLeft=RGB(68,71,140);

COLORREFclrBottomRight=RGB(70,166,152);

COLORREFclrTopLeft2=:

:

GetSysColor(COLOR_BTNHILIGHT);

COLORREFclrBottomRight2=:

:

GetSysColor(COLOR_BTNSHADOW);

registerconstUINTwide=20;

registerconstUINThight=20;

//painttheboarditself

for(inta=0;a<4;a++)

{dc->FillSolidRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft2);

dc->Draw3dRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft2,clrBottomRight2);

dc->FillSolidRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft2);

dc->Draw3dRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft,clrTopLeft2);

}

if(flag)

{for(inta=0;a<4;a++)

{cor[aa[a].x][aa[a].y]=1;

}

for(intx=0;x<20;x++)

{for(intj=0;j<10;j++)

{if(cor[x][j]==1)

{dc->FillSolidRect(100+20+j*20,x*20,wide,hight,tempcolor);

dc->Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft,tempcolor);

}

}

}

}

if(flag2)

{for(intx=0;x<20

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

当前位置:首页 > 求职职场 > 职业规划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1