为了方便编写,分为“snakeGame”、“sankeAI”、“sankeHead.h"三个文件。 “sankeHead.h" 1#include <unistd.h>2#include <stdlib.h>3#include <curses.h>4#include 5typedefenum{null=-2,stop=-1,left=0,right=1,up=2,down=3}movtype;6typedefenum{air,food,wall}coltype;7typedefstruct{8coltype ...
C语言贪吃蛇再进化! 嗯,这是终结版,虽然还有一些地方不完善,但我感觉也没必要完善。只是纠结于AI的自动寻物还是有问题,桑心。GCC编译命令 gcc -Wall -D_REENTRANT -o "%e" "%f" -lncurses -lpthread snakeGame.c 1#include"snakeAI.c"2#defineCTRL_TIMES 1000//AI每秒显示的最大步数3#defineWINDOW_W 404#...
typedef struct Snake { pSnakeNode _pSnake;//维护整条蛇的指针pSnakeNode _pFood;//维护⻝物的指针enum DIRECTION _Dir;//蛇头的⽅向,默认是向右enum GAME_STATUS _Status;//游戏状态int _Socre;//游戏当前获得分数int _foodWeight;//默认每个⻝物10分int _SleepTime;//每⾛⼀步休眠时间}Snake,...
(); //初始化蛇 void InitSnake(); //随机生成食物 void RandFood(); //判断得分与结束 void JudgeFunc(int x, int y); //打印蛇与覆盖蛇 void DrawSnake(int flag); //移动蛇 void MoveSnake(int x, int y); //执行按键 void run(int x, int y); //游戏主体逻辑函数 void Game(); int...
printf("\tWelcome to the mini Snake game.(press any key to continue)\n"); getch(); system("cls"); printf("\tGame Play Instructions:\n"); printf("\n-> Use arrow keys to move the snake.\n\n-> You will be provided food blobs at the several coordinates of the screen which you...
snake *head, *food;//蛇头指针,食物指针 snake *q;//遍历蛇的时候用到的指针 int endgamestatus = 0; //游戏结束的情况,1:撞到墙;2:咬到自己;3:主动退出游戏。 //声明全部函数// void Pos(); void creatMap(); void initsnake(); int biteself(); ...
#include<graphics.h>#include<stdlib.h>#include<conio.h>#include#include<stdio.h>#include"snake.h"intscore=0;intgamespeed=100;//蛇运行速度staticvoidInit(void);/*图形驱动*/staticvoidClose(void);/*图形结束*/staticvoidGame_interface(void);/*游戏界面*/staticvoidGameOver(void);/*结束游戏*/sta...
//蛇的方向enum DIRECT{UP = 1,DOWN,LEFT,RIGHT};//蛇的状态——游戏状态//正常、撞墙、撞到自己、正常退出enum GAME_STATE{OK,KILL_WALL,KILL_SELF,NORMAL_END};//贪吃蛇的相关信息typedef struct Snake{pSnakenode psnake; //指向蛇头部的指针pSnakenode pfood; //指向食物的指针enum DIRECT dir;//蛇...
//贪吃蛇typedef struct Snake{pSnakeNode _pSnake;//指向蛇头的指针pSnakeNode _pFood;//指向食物节点的指针enumDIRECTION_dir;//蛇的方向enumGAME_STATUS_status;//游戏的状态int _food_weight;//一个食物的分数int _score;//总成绩int _sleep_time;//休息时间,时间越短,速度越快,时间越长、速度越慢}Sna...
}snake; int key = 'w';//初始化方向 void gotoxy(int x, int y); void drawmap(); void keydown(); void creatvirus(); int snakestatus(); void startgame(); int menuselect(); void goodbye(); void introduce(); void edition(); ...