/*********************
*****最简单贪吃蛇****
-------------------------------------
****by_狂奔小兔****
********************/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define H 15
#define W 30
#define N 10
void move();
void start();
void draw();
void getturn();
void turn(char direction);
void judge();
void getfood();
void over();
int a, b, x, y, l = 0, n, i, j;
int x1, y1;
char *head, *tail, *tt, map[H][W];
char *belly[H * W], *food;
char left, right, front, back;
int main()
{
start();
}
void start()
{
for (i = 0; i != H; ++i)
for (j = 0; j != W; ++j)
{
if ((i == 0) || (i == H - 1) || (j == 0) || (j == W - 1))
map[i][j] = '9';
else
map[i][j] = '0';
}
x = W / 2, y = H / 2;
head = &map[y][x + 1];
belly[l] = &map[y][x];
tail = &map[y][x - 1];
*head = '1';
*belly[0] = '2';
*tail = '3';
left = 'w', right = 's';
front = 'd', back = 'a';
turn(front);
getfood();
draw();
while (1)
{
usleep(1000000/N);
getturn();
move();
judge();
clrscr();
draw();
}
}
void getturn()
{
char t, t1;
while (kbhit())
{
t = getch();
if (t == left)
{
turn(left);
left = back;
back = right;
right = front;
front = t;
goto gett;
}
else if (t == right)
{
turn(right);
right = back;
back = left;
left = front;
front = t;
goto gett;
}
}
turn(front);
gett:;
while (kbhit())
t = getch();
}