|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include"snake.h"
#include<time.h>
void main()
{
printf(" ========欢迎使用贪吃蛇游戏======== \n\n");
printf("1.按w(上),s(下),A(左),D(右)键控制蛇的移动方向\n");
printf("2.按ESC键退出游戏\n");
printf("3.蛇移动过程中,蛇头碰到蛇身或碰到墙壁,则游戏失败\n");
printf("4.按任意键游戏开始。。。\n");
_getch();
char c;
srand((unsigned)time(NULL));//初始化随机种子
Snake snake, *head, *rear;
head = rear = &snake;
Food *food = (Food*)malloc(sizeof(Food));
while (1) {
loop:c = intitSnakeFood(head, food);
while (1)
{
if (isSnakeEatFood(head, food))
{
rear = snakeGrow(head);
creatFood(food);
avoidOverlap(head, food);
}
if (_kbhit())
c = setCurKeyButton(c);
if (c == 'x')
{
puts("用户终止!\nGameover\n");
}
snakeMove(head, rear, c);
if (isFailure(head))
{
puts("游戏失败!\n");
break;
}
drawpicture(head, food);
Sleep(100);
}
printf("\n谢谢使用!再见!\n");
getchar();
} |
|