嵌入式程序设计打地鼠游戏设计文档格式.docx

上传人:b****3 文档编号:18340827 上传时间:2022-12-15 格式:DOCX 页数:17 大小:111.47KB
下载 相关 举报
嵌入式程序设计打地鼠游戏设计文档格式.docx_第1页
第1页 / 共17页
嵌入式程序设计打地鼠游戏设计文档格式.docx_第2页
第2页 / 共17页
嵌入式程序设计打地鼠游戏设计文档格式.docx_第3页
第3页 / 共17页
嵌入式程序设计打地鼠游戏设计文档格式.docx_第4页
第4页 / 共17页
嵌入式程序设计打地鼠游戏设计文档格式.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

嵌入式程序设计打地鼠游戏设计文档格式.docx

《嵌入式程序设计打地鼠游戏设计文档格式.docx》由会员分享,可在线阅读,更多相关《嵌入式程序设计打地鼠游戏设计文档格式.docx(17页珍藏版)》请在冰豆网上搜索。

嵌入式程序设计打地鼠游戏设计文档格式.docx

voidWriteScoreFile();

//将玩家的游戏分数写到文件中

voidSortList();

//对玩家分数排序

voidInitData();

//初始化数据

voidEndGame();

//游戏结束

voidclearPicture();

//还原背景图

voiddrawPicture(intbmpNum);

//画图

voidchilkTrue(intx,inty);

//判定是否击中

BOOLCDadishuDlg:

:

OnInitDialog()

游戏初始化函数。

voidCMengSnakeDlg:

OnTimer(UINTnIDEvent)

计时器函数,自动根据时间变量来执行程序,随机为地鼠生成一个坐标,并绘制到地图上。

voidCDadishuDlg:

OnLButtonDown(UINTnFlags,CPointpoint)

消息处理函数,鼠标左键点击触发,主要用来打击地鼠。

OnPaint()

重绘函数,实现地图区域的绘制

游戏界面部分相关代码:

OOLCDadishuDlg:

{

CDialog:

OnInitDialog();

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'

smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);

//Setbigicon

SetIcon(m_hIcon,FALSE);

//Setsmallicon

CenterWindow(GetDesktopWindow());

//centertothehpcscreen

//TODO:

Addextrainitializationhere

HWNDhwndCB;

hwndCB=CommandBar_Create(AfxGetInstanceHandle(),GetSafeHwnd(),0);

CommandBar_InsertMenubar(hwndCB,AfxGetInstanceHandle(),IDR_MENU1,0);

returnTRUE;

//returnTRUEunlessyousetthefocustoacontrol

}

//还原背景图

clearPicture()

PDC=GetDC();

CDCbmpDC;

bmpDC.CreateCompatibleDC(PDC);

CBitmapbmp;

bmp.LoadBitmap(IDB_BITMAP3);

BITMAPbm;

bmp.GetBitmap(&

bm);

bmpDC.SelectObject(bmp);

intpx=40+randx*80+1;

intpy=40+randy*80+1;

PDC->

StretchBlt(px,py,78,78,&

bmpDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);

drawPicture(intbmpNum)

if(bmpNum==1)

bmp.LoadBitmap(IDB_BITMAP1);

else

bmp.LoadBitmap(IDB_BITMAP2);

//判定是否击中

chilkTrue(intx,inty)

intpx_min=40+randx*80;

intpx_max=40+(randx+1)*80;

intpy_min=40+randy*80;

intpy_max=40+(randy+1)*80;

if(x>

=px_min&

&

x<

=px_max&

y>

=py_min&

y<

=py_max){

scorce+=10;

drawPicture

(2);

}

else{

Total--;

scorce-=10;

clearPicture();

if(Total==0)

{

EndGame();

TS*ts=newTS;

ts->

m_Value=scorce;

DoModal();

//

CPaintDCdc(this);

//devicecontextforpainting

Addyourmessagehandlercodehere

CDC*pDC=newCClientDC(this);

CPenpen;

//画笔

pen.CreatePen(PS_SOLID,1,RGB(0,0,0));

CPen*poldpen=pDC->

SelectObject(&

pen);

pDC->

Rectangle(40,40,280,280);

SelectObject(poldpen);

//new出来的一般都需要delete来回收内存。

deletepDC;

//DonotcallCDialog:

OnPaint()forpaintingmessages

//鼠标点击事件

OnLButtonDown(UINTnFlags,CPointpoint)

Addyourmessagehandlercodehereand/orcalldefault

if(!

start)

return;

chilkTrue(point.x,point.y);

OnLButtonDown(nFlags,point);

OnTimer(UINTnIDEvent)

switch(nIDEvent)

case1:

clearPicture();

randx=rand()%3;

randy=rand()%3;

drawPicture

(1);

break;

case2:

m_score=scorce;

UpdateData(FALSE);

case3:

_time++;

chartemp[10];

CStringtime;

intsecond=_time%60;

intminut=_time/60%60;

inthour=_time/3600%24;

_itoa(hour,temp,10);

if(hour>

9)

time+=temp;

else

time=time+"

0"

+temp;

_itoa(minut,temp,10);

if(minut>

"

_itoa(second,temp,10);

if(second>

m_time=time;

OnTimer(nIDEvent);

InitData()

Total=10;

start=true;

SetTimer(1,timer,NULL);

scorce=0;

SetTimer(2,100,NULL);

_time=0;

SetTimer(3,1000,NULL);

EndGame()

KillTimer

(1);

KillTimer

(2);

KillTimer(3);

start=false;

//重新开始

OnMENUITEMRestart()

Addyourcommandhandlercodehere

EndGame();

InitData();

//开始游戏

OnMENUITEMStart()

OnMENUITEMSeachRecord()

SerachRecord*sr=newSerachRecord;

sr->

保存记录的相关代码:

Userlist[11];

intUserListLength=0;

/////////////////////////////////////////////////////////////////////////////

//TSmessagehandlers

voidTS:

ReadScoreFile()

CStringfilename="

\\scores.dat"

;

HANDLEhFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

SetFilePointer(hFile,0,NULL,FILE_BEGIN);

Userus;

DWORDaa;

inti=0;

do{

ZeroMemory(&

us,sizeof(us));

if(ReadFile(hFile,&

us,sizeof(us),&

aa,NULL))

if(aa!

=0)

list[i++]=us;

}while(aa==sizeof(us));

UserListLength=i;

CloseHandle(hFile);

//写到文件里

WriteScoreFile()

inti;

//文件句柄

HANDLEhFile=CreateFile(filename,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

//设置文件开始处

//将数据写到文件

for(i=0;

i<

UserListLength&

10;

i++)

WriteFile(hFile,&

list[i],sizeof(list[i]),&

aa,NULL);

//安分数从大到小排序

SortList()

inti,j,k;

UserListLength-1;

k=i;

for(j=i+1;

j<

UserListLength;

j++)

if(list[j].score>

list[k].score)

k=j;

if(k!

=i)

{

Usertemp=list[k];

list[k]=list[i];

list[i]=temp;

}

OnOK()

Addextravalidationhere

UpdateData(TRUE);

ReadScoreFile();

//将值更新到变量

wcscpy(us.name,m_UserName);

us.score=m_Value;

list[UserListLength]=us;

UserListLength++;

SortList();

if(list[i].name==us.name&

list[i].score==us.score&

i>

=10)

AfxMessageBox(_T("

对不起你的名次最低,没有突破前10名"

));

return;

WriteScoreFile();

OnOK();

查看记录相关代码

voidSerachRecord:

DoDataExchange(CDataExchange*pDX)

DoDataExchange(pDX);

//{{AFX_DATA_MAP(SerachRecord)

DDX_Control(pDX,IDC_LIST1,m_list);

CRectrt;

m_list.GetClientRect(&

rt);

m_list.InsertColumn(0,_T("

名次"

),LVCFMT_LEFT,(int)(rt.Width()*0.35));

m_list.InsertColumn(1,_T("

得分"

m_list.InsertColumn(2,_T("

姓名"

),LVCFMT_LEFT,(int)(rt.Width()*0.3));

//}}AFX_DATA_MAP

BEGIN_MESSAGE_MAP(SerachRecord,CDialog)

//{{AFX_MSG_MAP(SerachRecord)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//SerachRecordmessagehandlers

m_list.DeleteAllItems();

UserusList[10];

usList[i++]=us;

for(intj=i-1;

j>

=0;

j--)

m_list.InsertItem(0,_T("

test"

chartemp[10];

_itoa(j+1,temp,10);

CStringnum=temp;

m_list.SetItemText(0,0,num);

m_list.SetItemText(0,2,usList[j].name);

_itoa(usList[j].score,temp,10);

CStringsc=temp;

m_list.SetItemText(0,1,sc);

//CDialog:

5系统测试

5.1运行界面

1游戏开始界面

2.中间游戏进行界面

3.游戏结束界面

4.刷新显示记录:

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

当前位置:首页 > 考试认证 > 公务员考试

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

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