C语言游戏源代码
1、简单的开机密码程序
#include "conio.h"
#include "string.h"
#include "stdio.h"
void error
{window12;10;68;10;
textbackground15;
textcolor132;
clrscr;
cprintf"file or system error you can't enter the system";
while1; /*若有错误不能通过程序*/
}
void look
{FILE *fauto;*fbak;
char *pass="c:\\windows\\"; /*本程序的位置*/
char a25;ch;
char *au="autoexec.bat";*bname="hecfback.^^^"; /*bname 是autoexec.bat 的备份*/
setdisk2; /*set currently disk c:*/
chdir"\\"; /*set currently directory \*/
fauto=fopenau;"r+";
if fauto==NULL
{fauto=fopenau;"w+";
if fauto==NULL error;}
freada;23;1;fauto; /*读取autoexec.bat前23各字符*/
a23='\0';
if strcmpa;pass==0 /*若读取的和pass指针一样就关闭文件;不然就添加*/
fclosefauto;
else
{fbak=fopenbname;"w+";
if fbak==NULL error;
fwritepass;23;1;fbak;
fputc'\n';fbak;
rewindfauto;
whilefeoffauto
{ch=fgetcfauto;
fputcch;fbak;}
rewindfauto;
rewindfbak;
whilefeoffbak
{ch=fgetcfbak;
fputcch;fauto;}
fclosefauto;
fclosefbak;
removebname; /*del bname file*/
}
}
void pass
char input60;
int n;
while1
{window1;1;80;25;
textbackground0;
textcolor15;
clrscr;
n=0;
window20;12;60;12;
textbackground1;
textcolor15;
clrscr;
cprintf"password:";
while1
{inputn=getch;
if n>58 {putchar7; break;} /*若字符多于58个字符就结束本次输入*/
if inputn==13 break;
if inputn>=32 && inputn<=122 /*若字符是数字或字母才算数*/
{putchar'*';
n++;}
if inputn==8 /*删除键*/
if n>0
{cprintf"\b \b";
inputn='\0';
n--;}
}
inputn='\0';
if strcmppassword;input==0
break;
else
{putchar7;
window30;14;50;14;
textbackground15;
textcolor132;
clrscr;
cprintf"password error";
getch;}
}
}
main
{look;
pass;
}
2、彩贪吃蛇
基础c语言代码#include <graphics.h>
#include <stdlib.h>
#define N 200
#define up 0x4800
#define down 0x5000
#define left 0x4b00
#define right 0x4d00
#define esc 0x011b
#define Y 0x1579
#define n 0x316e
int gamespeed; /* 游戏速度 */
int i; key; color;
int score = 0; /* 游戏分数 */
char cai48H =
{
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; 0x18; 0x00; 0x00; 0x00; 0x0E; 0x00;
0x1C; 0x00; 0x00; 0x00; 0x1C; 0x00; 0x1C; 0x00;
0x00; 0x00; 0x20; 0x00; 0x38; 0x00; 0x00; 0x00;
0x40; 0x00; 0x78; 0x00; 0x00; 0x01; 0x80; 0x40;
0x70; 0x00; 0x00; 0x03; 0x80; 0xC0; 0xE0; 0x00;
0x00; 0x07; 0x80; 0x80; 0xC0; 0x00; 0x00; 0x0E;
0x11; 0x81; 0xC0; 0x00; 0x00; 0x08; 0x61; 0x01;
0x80; 0x00; 0x00; 0x00; 0x23; 0x03; 0x04; 0x00;
0x00; 0x02; 0x02; 0x00; 0x06; 0x00; 0x00; 0x1E;
0x04; 0x00; 0x0F; 0x00; 0x00; 0x1C; 0x1F; 0x80;
0x1E; 0x00; 0x00; 0x08; 0x3F; 0x80; 0x3C; 0x00;
0x00; 0x00; 0xFF; 0x80; 0x38; 0x00; 0x00; 0x03;
0xFF; 0x80; 0x78; 0x00; 0x00; 0x0F; 0xF8; 0x00;
0xF0; 0x00; 0x00; 0x7F; 0xF0; 0x00; 0xE0; 0x00;
0x03; 0xFF; 0xFC; 0x01; 0x80; 0x00; 0x03; 0xC0;
0xFF; 0x01; 0x03; 0x80; 0x01; 0x01; 0xFF; 0x00;
0x03; 0x80; 0x00; 0x01; 0x3F; 0x00; 0x07; 0x80;
0x00; 0x02; 0x11; 0x00; 0x07; 0x00; 0x00; 0x00;
0x10; 0x00; 0x07; 0x00; 0x00; 0x00; 0x10; 0x00;
0x0E; 0x00; 0x00; 0x08; 0x10; 0x00; 0x1C; 0x00;
0x00; 0x30; 0x10; 0x00; 0x18; 0x00; 0x00; 0x70;
0x10; 0x00; 0x30; 0x00; 0x01; 0xE0; 0x10; 0x00;
0x70; 0x00; 0x03; 0x80; 0x10; 0x00; 0x60; 0x00;
0x00; 0x00; 0x30; 0x00; 0xE0; 0x00; 0x00; 0x00;
0xF0; 0x01; 0xC0; 0x00; 0x00; 0x00; 0x70; 0x03;
0xC0; 0x00; 0x00; 0x00; 0x10; 0x07; 0x80; 0x00;
0x00; 0x00; 0x00; 0x0F; 0x00; 0x00; 0x00; 0x00;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论