天天达

文本文档简单贪吃蛇代码

 

    以下是一个简单的贪吃蛇游戏的文本文档代码示例: ```c #include<stdio.h> #include<stdlib.h> #include<time.h> #include"pcc32.h" #include"jkey32.h" #include"mmsystem.h" #pragmacomment(lib,"winmm.lib") #pragmacomment(lib,"libpcc32.a") #pragmacomment(lib,"libjkey32.a") //定义地图的尺寸及坐标(均使用双字符长度) #define MAP_WIDTH 24 #define MAP_HEIGHT 16 #define MAP_BASE_X 8 #define MAP_BASE_Y 3 //定义蛇的相关参数 #define SNAKE_MIN_LEN 2 //蛇的最小长度 #define BARS 4 //每一个障碍物的方块最大数量 //定义地图块的状态,分别为^[空格|蛇头|蛇身|食物|奖励|边框|障碍]^ #define BS_SPACE 0 #define BS_SHEAD 1 #define BS_SBODY 2 #define BS_STAIL 3 #define BS_FOOD 4 #define BS_REWARD 5 #define BS_BLOCK 6 #define BS_BAR 7 //定义各对象的颜色,颜色定义详见^[pcc32.h]^,顺序同上 PCCOLOR myColors = {ORANGE, RED_ORANGE, RED, LIGHT_GREEN, YELLOW, MEDIUM_BLUE, LIGHT_BLUE, WHITE, TEAL, DARKER_GREY, LIGHT_PURPLE}; //定义各对象的形状,顺序同上 char mySharps = {"□", "◆", "■", "+", "★", "★", "¤", "¤"}; //定义蛇的运动方向^[上|下|左|右]^ #define DIR_UP 1 #define DIR_DOWN 2 #define DIR_LEFT 3 #define DIR_RIGHT 4 typedef struct _SnakeBody //定义表示蛇身(其中一节)坐标(x,y)的结构体 { uint8 x,