欢迎来到天天文库
浏览记录
ID:60215412
大小:21.50 KB
页数:5页
时间:2020-12-03
《最新C++编写的小游戏.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、__________________________________________________#includeusingnamespacestd;constcharMOUSE='*';constcharWAY='';constcharWALL='@';constcharPASS='.';constcharIMPASS='X';classGame{public:Game(size_tuWidth,size_tuHeight):m_uWidth(uWidth),m_uHeight(uHeight),m
2、_pcMaze(newchar[uWidth*uHeight]),m_mouse(0,1){srand(time(NULL));char(*pcMaze)[m_uWidth]=reinterpret_cast(m_pcMaze);for(size_ti=0;i3、4、(i==m_uHeight-2&&j>m_uWidth-5))pcMaze[i][j]=WAY;elseif(5、i==06、7、i==m_uHeight-18、9、j==010、11、j==m_uWidth-1)pcMaze[i][j]=WALL;elsepcMaze[i][j]=rand()%4?WAY:WALL;}~Game(void){if(m_pcMaze){delete[]m_pcMaze;m_pcMaze=NULL;}}voidRun(void){for(Show();!Quit()&&Step(););}private:classMouse{public:Mouse(size_tx,size_ty):m_x(x),m_y(y){}si12、ze_tGetX(void){returnm_x;}size_tGetY(void){returnm_y;}voidStepRight(void){m_x++;m_brain.Remember(EDIR_RIGHT);}voidStepDown(void){m_y++;m_brain.Remember(EDIR_DOWN);收集于网络,如有侵权请联系管理员删除__________________________________________________}voidStepLeft(void){m_x--;m_brain13、.Remember(EDIR_LEFT);}voidStepUp(void){m_y--;m_brain.Remember(EDIR_UP);}voidStepBack(void){switch(m_brain.Recollect()){caseEDIR_RIGHT:m_x--;break;caseEDIR_DOWN:m_y--;break;caseEDIR_LEFT:m_x++;break;caseEDIR_UP:m_y++;break;}}private:typedefenumtag_Direction{EDIR_RI14、GHT,EDIR_DOWN,EDIR_LEFT,EDIR_UP,EDIR_STILL}EDIR;classBrain{public:Brain(void):m_pMemory(NULL){}~Brain(void){for(Step*pStep=m_pMemory,*pLast;pStep;pStep=pLast){pLast=pStep->m_pLast;deletepStep;}}voidRemember(EDIReDir){m_pMemory=newStep(eDir,m_pMemory);收集于网络,如有侵权请联系15、管理员删除__________________________________________________}EDIRRecollect(void){EDIReDir=EDIR_STILL;if(m_pMemory){Step*pStep=m_pMemory;m_pMemory=m_pMemory->m_pLast;eDir=pStep->m_eDir;deletepStep;}returneDir;}private:classStep{public:Step(EDIReDir,Step*pLast):m_eDir(eD16、ir),m_pLast(pLast){}EDIRm_eDir;Step*m_pLast;};Step*m_pMemory;};size_tm_x;size_tm_y;Brainm_brain;};voidShow(void){char(*pcMaze)[m_uWidth]=reinterpret_cas
3、
4、(i==m_uHeight-2&&j>m_uWidth-5))pcMaze[i][j]=WAY;elseif(
5、i==0
6、
7、i==m_uHeight-1
8、
9、j==0
10、
11、j==m_uWidth-1)pcMaze[i][j]=WALL;elsepcMaze[i][j]=rand()%4?WAY:WALL;}~Game(void){if(m_pcMaze){delete[]m_pcMaze;m_pcMaze=NULL;}}voidRun(void){for(Show();!Quit()&&Step(););}private:classMouse{public:Mouse(size_tx,size_ty):m_x(x),m_y(y){}si
12、ze_tGetX(void){returnm_x;}size_tGetY(void){returnm_y;}voidStepRight(void){m_x++;m_brain.Remember(EDIR_RIGHT);}voidStepDown(void){m_y++;m_brain.Remember(EDIR_DOWN);收集于网络,如有侵权请联系管理员删除__________________________________________________}voidStepLeft(void){m_x--;m_brain
13、.Remember(EDIR_LEFT);}voidStepUp(void){m_y--;m_brain.Remember(EDIR_UP);}voidStepBack(void){switch(m_brain.Recollect()){caseEDIR_RIGHT:m_x--;break;caseEDIR_DOWN:m_y--;break;caseEDIR_LEFT:m_x++;break;caseEDIR_UP:m_y++;break;}}private:typedefenumtag_Direction{EDIR_RI
14、GHT,EDIR_DOWN,EDIR_LEFT,EDIR_UP,EDIR_STILL}EDIR;classBrain{public:Brain(void):m_pMemory(NULL){}~Brain(void){for(Step*pStep=m_pMemory,*pLast;pStep;pStep=pLast){pLast=pStep->m_pLast;deletepStep;}}voidRemember(EDIReDir){m_pMemory=newStep(eDir,m_pMemory);收集于网络,如有侵权请联系
15、管理员删除__________________________________________________}EDIRRecollect(void){EDIReDir=EDIR_STILL;if(m_pMemory){Step*pStep=m_pMemory;m_pMemory=m_pMemory->m_pLast;eDir=pStep->m_eDir;deletepStep;}returneDir;}private:classStep{public:Step(EDIReDir,Step*pLast):m_eDir(eD
16、ir),m_pLast(pLast){}EDIRm_eDir;Step*m_pLast;};Step*m_pMemory;};size_tm_x;size_tm_y;Brainm_brain;};voidShow(void){char(*pcMaze)[m_uWidth]=reinterpret_cas
此文档下载收益归作者所有