资源描述:
《c++小学期投色子代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、投色子:#include#include#include#include"colorConsole.h"//投筛子voidrolldice(HANDLEhOutput,intn,intcol,introw,WORDwColors[]);voidmain(void){inti;HANDLEhandle;WORDwColors[1];introw,col;//初始化handle=initiate();//生成个不同骰子wColors[0]=FOREGROUND_GREEN
2、FOREGROUND_RED
3、FOREGROUND_INTENSITY;
4、row=col=2;for(i=0;i<6;i++)rolldice(handle,i+1,col,row+6*i,wColors);//打印屏幕底部菜单WORDwMenuColors[1];wMenuColors[0]=FOREGROUND_RED
5、FOREGROUND_BLUE
6、FOREGROUND_INTENSITY;textout(handle,1,24,wMenuColors,1,"gamerules:");textout(handle,11,24,wMenuColors,1,"start/stop=ENTER;");textout(handle,34,24,wMenuColors,
7、1,"change=space;");textout(handle,53,24,wMenuColors,1,"exit=q.");boolflag=false;intcount=1;intsum=0;//随机数的种子srand((unsigned)time(NULL));col=15;row=8;//游戏开始while(1){if(_kbhit()){intch=_getch();if(ch==13){flag=!flag;if(!flag){wColors[0]=FOREGROUND_RED
8、FOREGROUND_INTENSITY;rolldice(handle,i+1,row,col,w
9、Colors);//记录游戏者和点数charbuf[20];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);}}elseif(ch==32)//更换游戏者{sum=0;count++;}elseif(ch=='q'
10、
11、ch=='Q')break;}if(flag)//随机
12、投筛子{i=rand()%6;wColors[0]=FOREGROUND_RED
13、FOREGROUND_INTENSITY;rolldice(handle,i+1,row,col,wColors);Sleep(100);wColors[0]=0;rolldice(handle,i+1,row,col,wColors);}}}voidrolldice(HANDLEhOutput,intn,intcol,introw,WORDwColors[]){switch(n){case1:textout(hOutput,row+1,col+1,wColors,1,"●");break;case2:texto
14、ut(hOutput,row+1,col,wColors,1,"●");textout(hOutput,row+1,col+2,wColors,1,"●");break;case3:textout(hOutput,row,col+2,wColors,1,"●");textout(hOutput,row+1,col+1,wColors,1,"●");textout(hOutput,row+2,col,wColors,1,"●");break;case4:textout(hOutput,row,col,wColors,1,"●");textout(hOutput,row,col+2,wColors
15、,1,"●");textout(hOutput,row+2,col,wColors,1,"●");textout(hOutput,row+2,col+2,wColors,1,"●");break;;case5:textout(hOutput,row,col,wColors,1,"●");textout(hOutput,row,col+2,wColors,1,"●");textout(hOutput