C語言 貪吃蛇 (WINDOWS C Snake)
資料來源: https://mp.weixin.qq.com/s?__biz=MjM5NTY1MjY0MQ==&mid=2650749388&idx=4&sn=01de3d789343c1147b694b4de37ab614&chksm=befeac82898925944967c23658422d
GITHUB: https://github.com/jash-git/WINDOWS-C-Snake
#include#include #include #include #include #include /*键盘输入获取*/ bool gameOver; bool stop = false; bool hit = false; /*游戏的边框大小*/ const int width = 50; const int height = 20; /*蛇的坐标,食物的坐标还有分数*/ int x,y,fruitX,fruitY,score; /*蛇每个点的坐标*/ int tailX[200],tailY[200]; /*蛇的默认长度*/ int ntail=3; typedef enum { STOP = 0, LEFT, RIGHT, UP, DOWN }Direction; Direction Dir; /*开始菜单*/ void menu() { int a; printf("------------------------------------------------------------------\n"); printf("| C_Scanke |\n"); printf("| 1) New Game |\n"); printf("| 2) Setting |\n"); printf("| 3) Exit |\n"); printf("------------------------------------------------------------------\n"); printf("---->Input :"); scanf("%d", &a); } /*初始化状态*/ void setup() { gameOver = false; /*根据当前时间设置“随机数种子”*/ srand(time(NULL)); Dir = STOP; /*贪吃蛇的位置,固定在中间*/ x= width/2; y= height/2; /*食物的位置,位置是随机的*/ fruitX = rand()%width; fruitY = rand()%height; score = 0; } /*绘制界面*/ void draw() { if(stop == true) { return; } system("cls");/*清除屏幕*/ printf("分数:%d",score); printf("\n"); /*第一行*/ int i; for(i= 0 ;i