贪吃蛇游戏是一款经典的益智游戏,有PC和手机等多平台版本。既简单又耐玩。该游戏通过控制蛇头方向吃蛋,从而使得蛇变得越来越长。
贪吃蛇玩法
用键盘上下左右控制蛇的方向,寻找吃的东西,每吃一口就能得到一定的积分,而且蛇的身子会越吃越长,身子越长玩的难度就越大,不能碰墙,不能咬到自己的身体,更不能咬自己的尾巴,看最终分数判定输赢。
贪吃蛇算法
伪代码框架
输出字符矩阵
WHILE not 游戏结束 DO
ch=等待输入
CASE ch DO
‘A’:左前进一步,break
‘D’:右前进一步,break
‘W’:上前进一步,break
‘S’:下前进一步,break
END CASE
输出字符矩阵
END WHILE
输出 Game Over!!!
创新玩法算法
# include <stdio.h>
# include <string.h>
# include <windows.h>
# include <stdlib.h>
# include <conio.h>
# include <time.h>
# include <math.h>
# define MAP_ROW 40
# define MAP_LINE 100
# define LENTH 5
int head_x = MAP_ROW / 2, head_y = MAP_LINE / 2, tail_x, tail_y;
char map[MAP_ROW][MAP_LINE];
int snake[MAP_ROW][MAP_LINE];
char direct = 'a';
int food_x, food_y;
void Map();
void Snake();
void gotoxy(int , int );
int Judgewall();
int Judgefood();
int judgeself=1;
int score = 0;
void Food();
void Key();
void Run();
int main()
{
int a;
gotoxy(MAP_LINE / 3, MAP_ROW / 2);
printf("Please choose the speed");
gotoxy(MAP_LINE / 3, MAP_ROW / 2 + 1);
printf("5 is easy and 1 is hard");
scanf_s("%d", &a);
getchar();
gotoxy(0, 0);
memset(