加点逻辑

This commit is contained in:
iridiumR 2022-05-07 14:25:22 +08:00
parent ede662b491
commit 4aae506847
2 changed files with 85 additions and 10 deletions

View file

@ -1,8 +1,82 @@
#include "snake.h"
Body head[40]={{0,0},0,-1};
static Body snake[40] = {{0, 0}, 0};
static unsigned char len = 0;
void snake_init()
{
snake[len].d.x = 63;
snake[len].d.y = 31;
snake[len].m = R;
len++;
}
void body_move(Body b)
{
switch(b.m)
{
case R:
b.d.x++;
break;
case L:
b.d.x--;
break;
case U:
b.d.y--;
break;
case D:
b.d.y++;
break;
}
}
void snake_move()
{
int i = 0;
for(; i <= len; i++)
{
body_move(snake[i]);
}
for(i = 1; i <= len; i++)
{
snake[i].m = snake[i - 1].m;
}
}
void body_add()
{
len++
snake[len].m = snake[len - 1].m;
snake[len].d.x = snake[len - 1].d.x;
snake[len].d.x = snake[len - 1].d.x;
switch(snake[len].m)
{
case R:
snake[len].d.x--;
break;
case L:
snake[len].d.x++;
break;
case U:
snake[len].d.y++;
break;
case D:
snake[len].d.y--;
break;
}
}
void test()
{
int i = 0;
for(; i < 15; i++)
body_add();
}

View file

@ -2,10 +2,11 @@
#include <stdio.h>
#define bool char
typedef enum
{
N=0,U, D, L, R
} MOVE_STATE;
#define MOVE_STATE char
#define R 0
#define U 1
#define L 2
#define D 3
struct DOT
@ -13,14 +14,14 @@ struct DOT
unsigned char x;
unsigned char y;
} ;
typedef struct DOT Dot;
struct BODY
{
dot d;
MOVE_STATE ms;
char id;
Dot d;
MOVE_STATE m;
};
typedef struct BODY Body;
typedef struct DOT Dot;