c++小学期投色子代码.doc_第1页
c++小学期投色子代码.doc_第2页
c++小学期投色子代码.doc_第3页
c++小学期投色子代码.doc_第4页
c++小学期投色子代码.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

投色子:#include #include #include #include colorConsole.h/投筛子void rolldice(HANDLE hOutput,int n,int col,int row,WORD wColors);void main(void) int i;HANDLE handle;WORD wColors1;int row,col;/初始化handle = initiate();/生成个不同骰子wColors0=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;row=col=2;for (i=0;i6;i+)rolldice(handle,i+1,col,row+6*i,wColors);/打印屏幕底部菜单 WORD wMenuColors1;wMenuColors0=FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY;textout(handle,1,24,wMenuColors,1, game rules:);textout(handle,11,24,wMenuColors,1,start/stop=ENTER;);textout(handle,34,24,wMenuColors,1,change=space;);textout(handle,53,24,wMenuColors,1,exit=q.);bool flag=false;int count=1;int sum=0;/随机数的种子srand( (unsigned)time( NULL );col=15;row=8;/游戏开始while(1) if (_kbhit()int ch=_getch();if (ch=13) flag=!flag; if (!flag)wColors0=FOREGROUND_RED|FOREGROUND_INTENSITY; rolldice(handle,i+1,row,col,wColors);/记录游戏者和点数char buf20;itoa(count,buf,10); textout(handle,1,13+2*count,wMenuColors,1,buf);textout(handle,3,13+2*count,wMenuColors,1,点数:);sum+=i+1;itoa(sum,buf,10);textout(handle,9,13+2*count,wMenuColors,1,buf);else if (ch=32)/更换游戏者sum=0;count+;else if (ch=q | ch=Q) break; if (flag)/随机投筛子i=rand() % 6;wColors0=FOREGROUND_RED|FOREGROUND_INTENSITY; rolldice(handle,i+1,row,col,wColors);Sleep(100);wColors0=0;rolldice(handle,i+1,row,col,wColors); void rolldice(HANDLE hOutput,int n,int col ,int row,WORD wColors)switch(n)case 1: textout(hOutput,row+1,col+1,wColors,1,); break;case 2:textout(hOutput,row+1,col, wColors,1,); textout(hOutput,row+1,col+2,wColors,1,); break;case 3:textout(hOutput,row, col+2,wColors,1,); textout(hOutput,row+1,col+1,wColors,1,);textout(hOutput,row+2,col, wColors,1,); break;case 4:textout(hOutput,row, col, wColors,1,); textout(hOutput,row, col+2,wColors,1,);textout(hOutput,row+2,col, wColors,1,);textout(hOutput,row+2,col+2,wColors,1,); break;case 5:textout(hOutput,row, col, wColors,1,); textout(hOutput,row, col+2,wColors,1,); textout(hOutput,row+1,col+1,wColors,1,);textout(hOutput,row+2,col, wColors,1,);textout(hOutput,row+2,col+2,wColors,1,); break;case 6:textout(hOutput,row, col, wColors,1,); textout(hOutput,row, col+1,wColors,1,); textout(hOutput,row, col+2,wColors,1,); textout(hOutput,row+2,col, wColors,1,);textout(hOutput,row+2,col+1,wColors,1,);textout(hOutput,row+2,col+2,wColors,1,); break; default:cout投掷骰子失败!endl;贪吃蛇:#include#include#include#includeusing namespace std;/ 刷新当前屏幕inline void Refresh(char q22, int grade, int gamespeed) system(cls); / 清屏 int i,j; cout endl; for(i=0;i22;i+) cout t; for(j=0;j22;j+) coutqij ; / 输出贪吃蛇棋盘 if(i=0) cout t等级为: grade; if(i=4) cout t自动前进时间; if(i=6) cout t间隔为: gamespeed ms; coutendl; int main() char tcsQipan2222; / 贪吃蛇棋盘是一个二维数组(如*22,包括墙壁) int i,j; for(i=1;i=20;i+) for(j=1;j=20;j+) tcsQipanij= ; / 初始化贪吃蛇棋盘中间空白部分 for(i=0;i=21;i+) tcsQipan0i = tcsQipan21i = -; /初始化贪吃蛇棋盘上下墙壁 for(i=1;i=20;i+) tcsQipani0 = tcsQipani21 = |; /初始化贪吃蛇棋盘左右墙壁 int tcsZuobiao2100; /蛇的坐标数组 for(i=0; i4; i+) tcsZuobiao0i = 1; tcsZuobiao1i = i + 1; int head = 3,tail = 0; for(i=1;i=3;i+) tcsQipan1i=*; /蛇身 tcsQipan14=#; /蛇头 int x1, y1; / 随机出米 srand(time(0); do x1=rand()%20+1; y1=rand()%20+1; while(tcsQipanx1y1!= ); tcsQipanx1y1=*; coutnntt贪吃蛇游戏即将开始!=0;i-) start=clock(); while(clock()-start0) cout nntt进入倒计时: i endl; else Refresh(tcsQipan,grade,gamespeed); int timeover; char direction = 77; / 初始情况下,向右运动 int x,y; while(1) timeover = 1; start = clock(); while(timeover=(clock()-start=gamespeed)&!kbhit(); /如果有键按下或时间超过自动前进时间间隔则终止循环 if(timeover) getch();direction = getch(); switch(direction) case 72: x= tcsZuobiao0head-1; y= tcsZuobiao1head;break; / 向上 case 80: x= tcsZuobiao0head+1; y= tcsZuobiao1head;break; / 向下 case 75: x= tcsZuobiao0head; y= tcsZuobiao1head-1;break; / 向左 case 77: x= tcsZuobiao0head; y= tcsZuobiao1head+1; / 向右 if(!(direction=72|direction=80|direction=75 |direction=77) / 按键非方向键 cout tGame over! endl;return 0; if(x=0 | x=21 |y=0 | y=21) / 碰到墙壁 cout tGame over! endl;return 0; if(tcsQipanxy!= &!(x=x1&y=y1) / 蛇头碰到蛇身 cout tGame over! =8) length -= 8; grade +; if(gamespeed=200) gamespeed = 550 - grade * 50; / 改变自动前进时间间隔 tcsQipanxy= #; tcsQipantcsZuobiao0headtcsZuobiao1head = *; head = (head+1)%100; tcsZuobiao0head = x; tcsZuobiao1head = y; do x1=rand()%20+1; y1=rand()%20+1; while(tcsQipanx1y1!= ); tcsQipanx1y1=*; Refresh(tcsQipan,grade,gamespeed); else / 不吃米 tcsQipan tcsZuobiao0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论