C语言游戏源代码

上传人:微*** 文档编号:89420164 上传时间:2022-05-13 格式:DOCX 页数:27 大小:78KB
收藏 版权申诉 举报 下载
C语言游戏源代码_第1页
第1页 / 共27页
C语言游戏源代码_第2页
第2页 / 共27页
C语言游戏源代码_第3页
第3页 / 共27页
资源描述:

《C语言游戏源代码》由会员分享,可在线阅读,更多相关《C语言游戏源代码(27页珍藏版)》请在装配图网上搜索。

1、C语言游戏源代码1、 简单的开机密码程序#include conio.h#include string.h#include stdio.hvoid error()window(12,10,68,10);textbackground(15);textcolor(132);clrscr();cprintf(file or system error! you cant enter the system!);while(1); /* 若有错误不能通过程序 */ void look()FILE *fauto,*fbak;char *pass=c:windowspassword.exe; /* 本程序的位

2、置*/char a25,ch;char *au=autoexec.bat,*bname=hecfback.AAA;/*bname 是autoexec.bat 的备份 */setdisk(2); /*set currently disk c:*/chdir(); /*set currently directory */fauto=fopen(au,r+);if (fauto=NULL) fauto=fopen(au,w+);if (fauto=NULL) error();fread(a,23,1,fauto); /* 读取 autoexec.bat 前 23 各字符 */ a23=0;if (s

3、trcmp(a,pass)=0) /* 若读取的和pass 指针一样就关闭文件,不然就添加 */fclose(fauto);elsefbak=fopen(bname,w+);if (fbak=NULL) error();fwrite(pass,23,1,fbak);fputc(n,fbak);rewind(fauto);while(!feof(fauto) ch=fgetc(fauto);fputc(ch,fbak); rewind(fauto); rewind(fbak);while(!feof(fbak)ch=fgetc(fbak);fputc(ch,fauto);fclose(fauto

4、);fclose(fbak);remove(bname); /*del bname file*/void pass()char *password=88888888;char input60;int n;while(1)window(1,1,80,25);textbackground(0);textcolor(15);clrscr();n=0;window(20,12,60,12);textbackground(1);textcolor(15);clrscr();cprintf(password:);while(1)若字符多于58 个字符就结束本次输若字符是数字或字母才算数*/inputn=g

5、etch();if (n58) putchar(7); break; /*入 */if (inputn=13) break;if (inputn=32 & inputn0)cprintf(b b);inputn=0;n-;inputn=0;if (strcmp(password,input)=0)break;elseputchar(7);window(30,14,50,14);textbackground(15);textcolor(132);clrscr();cprintf(password error!);getch(); main() look(); pass();2、 彩色贪吃蛇#in

6、clude #include #define N 200#define up 0x4800#define down 0x5000#define left 0x4b00#define right 0x4d00#define esc 0x011b#define Y 0x1579#define n 0x316eint gamespeed; /*游戏速度*/int i, key, color;int score = 0; /*游戏分数*/char cai48H = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0

7、0, 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, 0x0

8、1, 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, 0x8

9、0, 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, 0x8

10、0, 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

11、, 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, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70

12、, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ;char she48H = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0

13、x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0

14、x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x02, 0x00, 0x07, 0x86, 0x00, 0x00, 0x02, 0x00, 0x18, 0x03, 0x00, 0x00, 0x02, 0x00, 0x00, 0x07, 0x80, 0x00, 0x03, 0xF0, 0x00, 0x07, 0x80, 0x00, 0x0F, 0xFC, 0x00, 0x0C, 0x00, 0x00, 0x7E, 0x3F, 0x80, 0x00, 0x00, 0x01, 0

15、xFE, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xE2, 0x39, 0x8C, 0x00, 0x00, 0x00, 0xC2, 0x30, 0x08, 0x00, 0x00, 0x00, 0xC2, 0x60, 0x08, 0x00, 0x00, 0x00, 0xC3, 0xE0, 0x08, 0x60, 0x00, 0x00, 0x7F, 0xE0, 0x01, 0xE0, 0x00, 0x00, 0x3F, 0x80, 0x1F, 0xE0, 0x00, 0x00, 0x1E, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x1E, 0x00, 0

16、x1F, 0x00, 0x00, 0x00, 0x02, 0x38, 0x1E, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x1C, 0x00, 0x20, 0x00, 0x07, 0xFC, 0x18, 0x00, 0x20, 0x00, 0x1F, 0x0C, 0x10, 0x00, 0x20, 0x00, 0x7C, 0x04, 0x10, 0x00, 0x60, 0x01, 0xF0, 0x00, 0x10, 0x00, 0x60, 0x01, 0xE0, 0x00, 0x08, 0x00, 0xF0, 0x00, 0x80, 0x00, 0x08, 0x03, 0

17、xF0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x01, 0xFF, 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, 0

18、x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,;char tun48H =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,

19、0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8,

20、0x00, 0x40, 0x00, 0x00, 0x00, 0x06, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0xFC, 0x3C, 0x00,

21、0x00, 0x00, 0x0F, 0xF8, 0x0E, 0x00, 0x00, 0x00, 0x04, 0x70, 0x07, 0x00, 0x00, 0x00, 0x00, 0x60, 0x03, 0x80, 0x00, 0x00, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x30, 0x00, 0x00, 0x01, 0x00, 0x3C, 0x18, 0x00, 0x00, 0x02, 0x03, 0xFF, 0x0C, 0x00, 0x00, 0x0C, 0x7F, 0xFF, 0x8E, 0x00, 0x00,

22、0x18, 0xFF, 0xFF, 0xC7, 0x80, 0x00, 0x78, 0xFE, 0x07, 0x87, 0xE0, 0x01, 0xF0, 0x70, 0x07, 0x03, 0xF8, 0x07, 0xE0, 0x70, 0x0E, 0x03, 0xFE, 0x00, 0x00, 0x38, 0x1E, 0x01, 0xFE, 0x00, 0x00, 0x3F, 0xFE, 0x00, 0x0C, 0x00, 0x00, 0x1F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x0F,

23、0xFE, 0x00, 0x00, 0x00, 0x00, 0x04, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

24、0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ;char dan48H = 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, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0x0

25、0, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x80, 0x00, 0x00, 0x03, 0xFF, 0x80, 0x40, 0x00, 0x00, 0x01, 0xF1, 0x80, 0x40, 0x00, 0x00, 0x01, 0x81, 0x80, 0xE0, 0x00, 0x00, 0x00, 0x01, 0x93, 0xF0, 0x00,0x00, 0x00, 0x01, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x21, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x21, 0xF8, 0x00, 0x00, 0x00

26、, 0x00, 0x61, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x61, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x02, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x04, 0x02, 0x1F, 0x00, 0x00, 0x00, 0x08, 0x03

27、, 0x01, 0xC0, 0x00, 0x00, 0x38, 0x03, 0x00, 0x7C, 0x00, 0x00, 0xF8, 0x07, 0xF8, 0x3F, 0xC0, 0x01, 0xF0, 0x3F, 0xFE, 0x3F, 0xF8, 0x03, 0xC1, 0xFF, 0x0F, 0x1F, 0xF8, 0x00, 0x01, 0xE3, 0x0F, 0x0F, 0xF0, 0x00, 0x01, 0xC3, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x83, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xC7, 0xF8, 0x00

28、, 0x00, 0x00, 0x00, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x03, 0x80, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xF8, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x07, 0xFF, 0x81, 0xE0, 0x00, 0x00

29、, 0x07, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x60, 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, 0x00, 0x00, 0x00, 0x00, 0x00, ;char zuo16H =0x

30、18, 0xC0, 0x18, 0xC0, 0x19, 0x80, 0x31, 0xFE, 0x33, 0xFE, 0x76, 0xC0, 0xF0, 0xFC, 0xB0, 0xFC, 0x30, 0xC0, 0x30, 0xC0, 0x30, 0xFE, 0x30, 0xFE, 0x30, 0xC0, 0x30, 0xC0, 0x30, 0xC0, 0x00, 0x00, ;char zhe16H = 0x03, 0x00, 0x03, 0x0C, 0x1F, 0xCC, 0x1F, 0xD8, 0x03, 0x30, 0xFF, 0xFE, 0xFF, 0xFE, 0x03, 0x00,

31、 0x0F, 0xF8, 0x3F, 0xF8, 0xEC, 0x18, 0xCF, 0xF8, 0x0C, 0x18, 0x0F, 0xF8, 0x0F, 0xF8, 0x00, 0x00, ;char tian16H =0x00, 0x00, 0x3F, 0xFC, 0x3F, 0xFC, 0x31, 0x8C,0x31, 0x8C, 0x31, 0x8C, 0x3F, 0xFC, 0x3F, 0xFC, 0x31, 0x8C, 0x31, 0x8C, 0x31, 0x8C, 0x3F, 0xFC, 0x3F, 0xFC, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x0

32、0,;char xue16H =0x33, 0x18, 0x19, 0x98, 0x08, 0xB0, 0x7F, 0xFC, 0x7F, 0xFC, 0x60, 0x0C, 0x1F, 0xF0, 0x1F, 0xF0, 0x00, 0xC0, 0x7F, 0xFC, 0x7F, 0xFC, 0x01, 0x80, 0x01, 0x80, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, ;char ke16H =0x00, 0x00, 0x0C, 0x18, 0xFD, 0x98, 0xF8, 0xD8, 0x18, 0x58, 0xFE, 0x18, 0xFE, 0

33、x98, 0x18, 0xD8, 0x3C, 0x58, 0x7E, 0x1E, 0xDB, 0xFE, 0x9B, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, ;struct Food/* 定义结构体存储食物的属性*/ int x; /* 食物的坐标*/int y;int yes; /* 值为 0 表示屏幕上没有食物,值为 1 表示屏幕上有食物 */ int color; /* 食物颜色 */ food;struct Snake/* 定义结构体存储蛇的属性*/int xN; /* 每一节蛇的坐标 */int yN;int col

34、orN;/* 存储每一节蛇的颜色*/int node; /* 蛇的节数 */int direction; /* 蛇移动的方向 */int life; /* 蛇的生命,如果为1 ,蛇死,游戏结束*/ snake;void init(void)/* 图形驱动 */ int driver = DETECT, mode = 0; registerbgidriver(EGAVGA_driver);initgraph(&driver, &mode, );汉字点阵 void drawmat(char *mat, int matsize, int x, int y, int color) /*/int i,

35、j, k, m;m = (matsize - 1) / 8 + 1;for(j = 0; j matsize; j+)for(i = 0; i m; i+)for(k = 0; k k)putpixel(x+ i * 8 + k, y + j, color);void showword(void)/* 调用汉字点阵输出程序,显示标题和作者信息*/drawmat(cai48H, 48, 249, -4, 7);drawmat(she48H, 48, 329, -4, 7);drawmat(tun48H, 48, 409, -4, 7);drawmat(dan48H, 48, 489, -4, 7

36、);drawmat(cai48H, 48, 250, -5, 4);drawmat(she48H, 48, 330, -5, 4);drawmat(tun48H, 48, 410, -5, 4);drawmat(dan48H, 48, 490, -5, 4);/* 作者 田学科 */drawmat(zuo16H, 16, 515, 465, 7);drawmat(zhe16H, 16, 530, 465, 7);drawmat(tian16H, 16, 550, 465, 7);drawmat(xue16H, 16, 565, 465, 7);drawmat(ke16H, 16, 580, 4

37、65, 7);void draw(void)/* 画出四周的墙*/if(color = 15)color = 0;setcolor(+color);setlinestyle(SOLID_LINE, 0, 1);for(i = 30; i = 600; i += 10)rectangle(i, 40, i + 10, 49);rectangle(i, 451, i + 10, 460);for(i = 40; i 450; i += 10)rectangle(30, i, 39, i + 10);rectangle(601, i, 610, i + 10);void prscore(void)/

38、* 打印游戏分数 */char str10;setfillstyle(SOLID_FILL, YELLOW);bar(50, 10, 200, 30);setcolor(6);settextstyle(0, 0, 2);sprintf(str, score:%d, score); outtextxy(55, 15, str); void gameover(void)画出蛇死时的位置 */snake.yi, snake.xi+10,cleardevice(); /* 清屏函数 */for(i = 0; i snake.node; i+) /*setcolor(snake.colori); rec

39、tangle(snake.xi,snake.yi + 10);prscore(); /* 显示分数 */draw();showword();settextstyle(0, 0, 6);setcolor(7);outtextxy(103, 203, GAME OVER);setcolor(RED);outtextxy(100, 200, GAME OVER);void gameplay(void)/* 玩游戏的具体过程*/int flag, flag1;randomize();prscore();gamespeed = 50000;food.yes = 0; /* food.yes=0 表示屏幕

40、上没有食物 */snake.life = 1; /* snake.life=1表示蛇是活着的 */snake.direction = 4; /* 表示蛇的初始方向为向右*/snake.node = 2; /* 蛇的初始化为两节*/snake.color0 = 2; /* 两节蛇头初始化为绿色*/snake.color1 = 2;snake.x0 = 100;snake.y0 = 100;snake.x1 = 110;snake.y1 = 100;food.color = random(15) + 1;while(1)while(1)if(food.yes = 0) /* 如果蛇活着*/whil

41、e(1)flag = 1;food.yes = 1;food.x = random(56) * 10 + 40;food.y = random(40) * 10 + 50;for(i = 0; i 0; i-)snake.xi = snake.xi-1;snake.yi = snake.yi-1; switch(snake.direction)case 1:snake.y0 -= 10;break;case 2:snake.y0 += 10;break;case 3:snake.x0 -= 10;break;case 4:snake.x0 += 10;break;for(i = 3; i sn

42、ake.node; i+)= snake.y0)if(snake.xi = snake.x0 & snake.yigameover();snake.life = 0;break;if(snake.x0 590 | snake.y0 440)gameover(); snake.life = 0;if(snake.life = 0) break;if(snake.x0 = food.x & snake.y0 = food.y) /* 蛇吃掉食*/setcolor(0);rectangle(food.x, food.y, food.x + 10, food.y + 10);snake.xsnake.

43、node = -20;snake.ysnake.node = -20;snake.colorsnake.node = food.color; snake.node+;food.yes = 0;food.color = random(15) + 1;score += 10;prscore();if(score % 100 = 0 & score != 0) for(i = 0; i snake.node; i+) /*画出蛇 */setcolor(snake.colori);rectangle(snake.xi,snake.yi, snake.xi + 10, snake.yi + 10);so

44、und(200);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);nosound();gamespeed -= 5000; draw(); elsesound(500);delay(500); nosound();for(i = 0; i snake.node; i+) /*画出蛇 */setcolor(snake.colori);rectangle(snake.xi,snake.yi,snake.xi + 10, snake.yi + 10);delay(gamespeed);dela

45、y(gamespeed);flag1 = 1;setcolor(0);rectangle(snake.xsnake.node-1,snake.ysnake.node-1,snake.xsnake.node-1 + 10, snake.ysnake.node-1 + 10);if(kbhit() & flag1 = 1) /* 如果没按有效键就重新开始循环 */flag1 = 0;key = bioskey(0);if(key = esc)exit(0);else if(key = up & snake.direction != 2) snake.direction = 1;else if(ke

46、y = down &snake.direction!= 1)snake.direction = 2;else if(key = left &snake.direction!= 4)snake.direction = 3;else if(key = right & snake.direction !=3)snake.direction = 4;if(snake.life = 0) /* 如果蛇死了就退出循环*/break;void main(void)while(1)color = 0;init();cleardevice();showword();draw();gameplay();setco

47、lor(15);settextstyle(0, 0, 2);outtextxy(200, 400, CONTINUE(Y/N)?);while(1)key = bioskey(0);if(key = Y | key = n | key = esc) break;if(key = n | key = esc) break;closegraph();3、 c 语言实现移动 xx 系统#include #define GRID-SIZE5#define SELECTED-1/* 低于矩阵中所有元素*/#define TRAFFIC-FILE“ traffic.dat ” /* 关于交通数据的文件*/

48、#define NUM-TRANSMITTERS 10/* 可用的发射器数量*/void get-traffic-data(int mutersGRID-SIZEGRID-SIZE,int salesforceGRID-SIZEGRID-SIZE,int weekends GRID-SIZEGRID-SIZE;voide print-matrixGRID-SIZEGRID-SIZE;int main(void)上午 8 : 30 的交通数据 */上午 11: 00 的交通数据intmutersGRID-SIZEGRID-SIZE;/*intsalesforceGRID-SIZEGRID-SIZ

49、E; /*/intintweekendGRID-SIZEGRID-SIZE;/* 周末交通数据*/muter-weight,/* 通勤人员数据的权重因营销人员数据的权重因子 */;/* 周末数据的权重因子*/* 每个发射器的位置*/* 和数据中当前的最大值 */* 矩阵的循环计数器 */* 发射器的循环计数器*/子*/sale-weight,/*weekend-weightint location-i , location-j ;intcurrent-max;inti , j ,tr ;/* 填入并显示交通数据*/Get-traffic-data ( muters , salesforce ,

50、 weekend) ;Printf (“8: 30 A.M.WEEKDAY TRAFFIC DATA 、 nn ”)print-matrix(muters);printf( “ nn WEEKEND TRAFFIC DATAnn ” );print-matrix(salesforce);printf( “ nn WEEKEND TRAFFIC DATAnn ” ); printf_matrix(weekeng);/* 请用户输入权重因子 */printf( “ nnPlease input the following value:n” );printf( “ Weight (an interg

51、er=0) for the 8:30 A.M.muter data” )scanf( “ %d” ,&muter_weight);printf( “ weight(an integer=0) for the weekeng data” );scanf( “ %d” ,&weekend_weight);scanf( “ %d” ,&weekend_weight);/* 计算并显示加权后求和的数据*/for (i=0;iGRID_SIZE;+i)for (j=0;jGRID_SIZE;+j)summed_dataij=muter_weight*muterij+salesforce_weight*s

52、alesforceij+weekend_weight*weekendij;printf( “ nnThe weighted,summed data is :nn” );printf_matrix(summed_data);/*在summed_data矩阵中找出NUM_TRANSMITTERS最大值,将坐标临时存储在location_i 和 location_j 中,然后把最后的结果坐标输出 */printf( “ nnLocations of the %d transmitters:nn” ,NUM_TRANSMITTERS);for (tr=1;tr=NUM_TRANSMITTERS;+tr

53、)current_max=SELECTED ; /* 以一个过低的值为起点开始查找 */for (i=0;iGRID_SIZE;+i)for(j=0;jGRID_SIZE;+j)if(current_maxsummed_dataij) current_max=summed_dataij) location_i=i;location_j=j;/* 将选中的单元赋一较低的值以避免下次再选中这一元素,显示查找结果*/summed_datalocation_ilocation_j=SELECTED;printf( “ Transmitter %3d:at location %3d %3dn” ,tr,

54、location_i,location_j);return (0);/*把TRAFFIC_FILE中的交通数据填充到 3个GRID_SIZEX GRID_SIZE数组中*/voidget_traffic_data(int mutersGRID_SIZE , /* 输出 */int salesforceGRID_SIZEGRID_SIZE,/*输出 */int weekendGRID_SIZEGRID_SIZE , /* 输出 */int i,j;/* 循环计数器 */FILE *fp;/* 文件指针 */fq=fopen(TRAFFIC_FILE, “r ” );for(i=0 ; iGRID

55、_SIZE;+i)for(j=0;jGRID_SIZE;+j)fscanf(fp,“ %d” ,&mntersij;for(i=0;iGRID_SIZE;+j)for(j=0;jGRID_SIZE;+j)fscanf(fq,“ %d” , &weekendij);fclose(fq);/* 显示一个GRID SIZEX GRID SIZE整数矩阵的内容*/voidprint_matrix(int matrixGRID_SIZEGRID_SIZE)int i,j;for(i=0;iGRID_SIZE;+j) for(j=0;jGRID_SIZE;+J)/* 循环计数器 */printf(prin

56、tf(“ %3d” ,matrixij);n ” );4、 扑克牌游戏/*Copyright(C) 2004-2005 vision,math,NJU.File Name: guess_card.cppAuthor: vision Description:Version: 1.0Data: 23-2-2004给你 9 张牌 , 然后让你在心中记住那张牌, 然后电脑分组让你猜你记住的牌在第几组 , 然后猜出你记住的那张牌Other: 出自儿童时的一个小魔术History: 修改历史*/#include #include #include #include #include #define CAR

57、DSIZE 52#define SUITSIZE 13/* 扑克牌结构*/typedef struct Card/*/*牌的总张数*/一色牌的张数*/char val;/* 扑克牌面上的大小*/int kind :4; /* 扑克牌的花色*/Card;/*Function:Description:/ riffle/ 洗牌 , 然后随机的得到 9 张牌 , 要求九张牌不能有重复.Calls:Called By:Table Accessed: /Table Updated:Input:大小Output:Return:Others:Bug:待修订/ main() 被修改的表(此项仅对于牵扯到数据库操

58、作的程序)/ 被修改的表(此项仅对于牵扯到数据库操作的程序)/Card card/ void/ 此函数修改/ 此函数有*/void riffle(Card *cards, int size);/*Function:Description:Calls:Called By:Table Accessed: /Table Updated:Input:组的大小Output:Return:Others:/ show/ 显示数组的内容/ main()被修改的表(此项仅对于牵扯到数据库操作的程序)/ 被修改的表(此项仅对于牵扯到数据库操作的程序)/Card *card/ void/*/void show(const Card *cards, int size);/*Function:Description:

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!