//为广大编程游戏爱好者提供一个参考的游戏源代码
#include<stdio.h>
#include<conio.h>#include<windows.h>
#include<time.h>
#define framex 5
#define framey 5
#define wide 20
#define high 20
int i,j,a[2];
//将光标移动到指定位置
void gotoxy(HANDLE hout,int x,int y){
//COORD是WindowsAPI中定义的一种结构,表示一个字符在控制台屏幕上的坐标
COORD pos;
pos.X=x;
pos.Y=y;
//SetConsoleCursorPosition是API中定位光标位置的函数。
SetConsoleCursorPosition(hout,pos);
}
//游戏封面
void cover (HANDLE hout){
gotoxy(hout,framex+wide,framey);
printf("snake——贪吃蛇游戏");
gotoxy(hout,framex+wide,framey+5);
printf("开始游戏前请关闭中文输入法");
gotoxy(hout,framex+wide*2,framey+20);
printf( "游戏制作者:Joe");
gotoxy(hout,framex+wide*2,framey+22);
char a;
a=getchar();
system("cls");
}
//定义蛇的结构体
struct Snake{
int x[100];
int y[100];
int speed;
int length;
int count;
};
//定义食物的结构体
struct Food{
int x;
int y;
};
//制作框架
void makeframe(struct Snake snake){
//定义显示器变量句柄
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(hout,framex+wide*2+5,framey);
printf( " 贪吃蛇游戏");
gotoxy(hout,framex+wide*2+5,framey+3);
printf("使用方向键或wasd移动");
gotoxy(hout,framex+wide*2+5,framey+5);
printf("长按方向键可加速");
gotoxy(hout,framex+wide*2+5,framey+7);
printf("按任意键暂停,方向键继续");
//打印上边框
for(i=0;i<wide*2+1;i++){
gotoxy(hout,framex+i,framey);
printf("*");
}
//打印下边框
for(i=0;i<wide*2+2;i++){ <