自创游戏,大家帮忙看看怎么样(剧情,地图内容可以改的)
程序代码:
#include<stdio.h> #include<windows.h> #include<conio.h> void color(short x) //自定义函根据参数改变颜色 { if(x>=0 && x<=15)//参数在0-15的范围颜色 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); //只有一个参数,改变字体颜色 else//默认的颜色白色 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); } int main() { int i,x,y,wz1=90,xz,sj1=6,sj2=10,jf=0,xz1; int wz[100]; char ch; char dt[10*10][20]={ "校门","街道","街道","街道","街道","街道","老奶奶","街道","街道","街道" ,"马路","马路","马路","马路","马路","斑马线","斑马线","马路","马路","马路" ,"马路","马路","马路","马路","马路","斑马线","斑马线","马路","马路","马路" ,"马路","马路","马路","马路","马路","斑马线","斑马线","马路","马路","马路" ,"马路","马路","马路","马路","马路","斑马线","斑马线","马路","马路","马路" ,"街道","草坪","草坪","街道","妇女","街道","街道","街道","街道","街道" ,"街道","草坪","草坪","街道","街道","街道","街道","街道","街道","街道" ,"街道","街道","街道","街道","街道","街道","街道","街道","树荫","树荫" ,"街道","草坪","草坪","街道","街道","街道","街道","树荫","孩童","树荫" ,"家门","草坪","草坪","街道","街道","街道","街道","树荫","树荫","大树" }; int sx[100]={ 9,1,1,1,1,1,7,1,1,1, 0,0,0,0,0,1,1,0,0,0, 0,0,0,0,0,1,1,0,0,0, 0,0,0,0,0,1,1,0,0,0, 0,0,0,0,0,1,1,0,0,0, 1,5,5,1,4,1,1,1,1,1, 1,5,5,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,5,5,1,1,1,1,1,3,1, 1,5,5,1,1,1,1,1,1,1 }; printf("nnnn"); printf("ttt---#上学路上#---nn"); printf("ttt1:进入游戏n"); printf("ttt 2:退出n"); scanf("%d",&xz); if(xz==1) system("cls"); else exit(0); printf("nnnn"); printf("ttttttt##游戏规则##nn"); printf("tttt小明是一位职校学生。这天,他早早的起来,准备去上学了。nn"); printf("ttt小明6:10从家里出发,7:00学校上课,请及时赶到学校,并在路途中帮助更多的人。nn"); printf("ttttt20秒后自动继续"); Sleep(20000); system("cls"); printf("nnnttttttt##操作方法##nn"); printf("ttttt 5,2,1,3+回车控制人物上下左右移动nn"); printf("tttttt △代表人物所处位置nn"); printf("tttt 建议将输出窗口放大,游戏体验更佳nn"); printf("tttttt20秒后自动继续"); Sleep(20000); system("cls"); for(i=0;i<10000;i++){ if(sx[wz1]==0) {system("color 04"); printf("nnnt你踏上马路,忽然一个车从你身边呼啸而过,吓到你赶紧后退一步。 分数-8n"); jf-=8;Sleep(5000); system("color 07"); if(wz1/10==4)wz1+=10; if(wz1/10==3)wz1+=20; if(wz1/10==2)wz1-=20; if(wz1/10==1)wz1-=10; system("cls"); } if(sx[wz1]==5) {system("color 04"); printf("nnnt你走在青绿的草坪上,小草都被你压垮了,你的良心受到了谴责。 分数-5n"); jf-=5;Sleep(5000);system("color 07"); system("cls"); } if(sx[wz1]==4) {printf("t“有小偷啊,快来抓小偷啊!”妇女焦急的喊道n"); printf("是否要帮助妇女抓小偷n"); printf("1:是tt2:否n"); scanf("%d",&xz1);system("cls"); if(xz1==1){system("color 01"); printf("你成功帮妇女抓住了小偷。 分数+10n"); printf("好不容易,你在街头处抓到了小偷,把钱包还给了妇女n"); printf("不知不觉,10分钟过去了"); jf+=10;wz1=59;sj2+=10; } if(xz1==0)printf("你听到了妇女的呼喊,没有做声,默默地走开了。"); sx[54]=1; Sleep(5000); system("color 07"); system("cls"); } if(sx[wz1]==7) {printf("t“咳咳。”老奶奶咳了两声,感觉十分虚弱n"); printf("是否要帮助老奶奶过马路n"); printf("1:是tt2:否n"); scanf("%d",&xz1);system("cls"); if(xz1==1){system("color 01"); printf("你成功帮老奶奶过了马路。 分数+10n"); printf("你把老奶奶送过了马路,又是7分钟过去了"); jf+=10;wz1=56;sj2+=7; } if(xz1==0)printf("你看了老奶奶一眼,没有做声,默默地走开了。"); sx[6]=1; Sleep(5000); system("color 07"); system("cls"); } if(sx[wz1]==3) {printf("t“哇呜呜呜呜呜,我的气球!”孩童哭出了声n"); printf("是否要帮助孩童去拿气球n"); printf("1:是tt2:否n"); scanf("%d",&xz1);system("cls"); if(xz1==1){system("color 01"); printf("你成功帮孩童拿到了气球。 分数+10n"); printf("当你把气球还给孩童时,已经过去8分钟了"); jf+=10;wz1=99;sj2+=8; } if(xz1==0)printf("你看了看孩童和树上的气球,没有做声,默默地走开了。"); sx[88]=1; Sleep(5000); system("color 07"); system("cls"); } if(sx[wz1]==9) {printf("nntt你终于到了学校n"); if(sj1>6&&jf>0) printf("nntt虽然你迟到了,但是帮助了人们,你感到很开心"); if(sj1==6&&jf<=0) printf("nntt虽然你没有迟到,但是心里却很不是滋味"); if(sj1==6&&jf>0) printf("nntt今天你不仅没有迟到,还帮助了人们,你感到很充实"); Sleep(5000); system("cls"); printf("nnttttt感谢游玩!"); Sleep(3000); return 0; } printf("ttt时间 %d:%dtt积分:%dnn",sj1,sj2,jf); for(x=0;x<10;x++) { for(y=x*10;y<(x+1)*10;y++) { printf("--"); if(sx[y]==0) color(8); if(sx[y]==5) color(10); if(sx[y]==9) color(4); if(sx[y]==3) color(13); if(sx[y]==4) color(13); if(sx[y]==7) color(13); printf("%6s",dt[y]); color(7); if(wz1==y) {color(3); printf("△"); color(7);} else printf(" "); printf("-"); } printf("n"); for(y=x*10;y<(x+1)*10;y++) printf(" | "); printf("n"); for(y=x*10;y<(x+1)*10;y++) printf(" | "); printf("n"); } printf("ntt"); switch(ch=getch()) { case 72: if(wz1/10!=0) wz1-=10; else {printf("这边没有路了"); Sleep(2000); }break; case 80: if(wz1/10!=9) wz1+=10; else {printf("这边没有路了"); Sleep(2000); }break; case 75: if(wz1/10==(wz1-1)/10) wz1--; else {printf("这边没有路了"); Sleep(2000); }break; case 77: if(wz1/10==(wz1+1)/10) wz1++; else {printf("这边没有路了"); Sleep(2000); }break; default: break; } system("cls"); sj2++; sj1=sj1+sj2/60; sj2=sj2%60; } return 0; }