资源描述:
《c语言游戏源代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、C语言游戏源代码1、简单的开机密码程序#include"conio.h"#include"string.h"#include"stdio.h"voiderror(){window(12,10,68,10);textbackground(15);textcolor(132);clrscr();cprintf("fileorsystemerror!youcan'tenterthesystem!!!");while(1);/*若有错误不能通过程序*/}voidlook(){FILE*fauto,*fbak;char*pass="c:\windows\password
2、.exe";/*本程序的位置*/chara[25],ch;char*au="autoexec.bat",*bname="hecfback.^^^";/*bname是autoexec.bat的备份*/setdisk(2);/*setcurrentlydiskc:*/chdir("\");/*setcurrentlydirectory*/fauto=fopen(au,"r+");if(fauto==NULL){fauto=fopen(au,"w+");if(fauto==NULL)error();}fread(a,23,1,fauto);/*读取autoexec.
3、bat前23各字符*/a[23]=' ';if(strcmp(a,pass)==0)/*若读取的和pass指针一样就关闭文件,不然就添加*/fclose(fauto);else{fbak=fopen(bname,"w+");if(fbak==NULL)error();fwrite(pass,23,1,fbak);fputc('',fbak);rewind(fauto);while(!feof(fauto)){ch=fgetc(fauto);fputc(ch,fbak);}rewind(fauto);rewind(fbak);while(!feof(fbak)
4、){ch=fgetc(fbak);fputc(ch,fauto);}fclose(fauto);fclose(fbak);remove(bname);/*delbnamefile*/}}voidpass(){char*password="88888888";charinput[60];intn;while(1){window(1,1,80,25);textbackground(0);textcolor(15);clrscr();n=0;window(20,12,60,12);textbackground(1);textcolor(15);clrscr();cpri
5、ntf("password:");while(1){input[n]=getch();if(n>58){putchar(7);break;}/*若字符多于58个字符就结束本次输入*/if(input[n]==13)break;if(input[n]>=32&&input[n]<=122)/*若字符是数字或字母才算数*/{putchar('*');n++;}if(input[n]==8)/*删除键*/if(n>0){cprintf("bb");input[n]=' ';n--;}}input[n]=' ';if(strcmp(password,input)=
6、=0)break;else{putchar(7);window(30,14,50,14);textbackground(15);textcolor(132);clrscr();cprintf("passworderror!");getch();}}}main(){look();pass();}1、彩色贪吃蛇#include#include#defineN200#defineup0x4800#definedown0x5000#defineleft0x4b00#defineright0x4d00#defineesc0x011
7、b#defineY0x1579#definen0x316eintgamespeed;/*游戏速度*/inti,key,color;intscore=0;/*游戏分数*/charcai48H[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x04,0x00,0x
8、18,0x