snakegame
2021-06-16 18:32:39 0 举报
guet C语言大作业
作者其他创作
大纲/内容
判断是否吃到食物???void food_slect()
return 1; break;
i--
case 's': \tcase 'S': \tcase 80 :
case 'w': \tcase 'W': \tcase 72 :
yes
定义触碰检测char touch_scan()
cleardevice()
no
food.food_flag!=0
在窗口中显示蛇void show_snake()
case left: if (snake.snake_xy.x[0] == 0)\treturn 1; break;
i=1
i < snake.snake_length
snake.snake_dir = up; break;
No
snake.snake_dir != left
case right: snake.snake_xy.x[0] = snake.snake_xy.x[0] + 10;\t\tbreak;
初始蛇的位置和长度void snake init()
i++
snake.snake_dir = left; break;
case down:
snake.snake_dir = down; break;
开始
case 'd': \tcase 'D': \tcase 77 :
struct Snake{ struct point snake_xy; char snake_dir; int snake_length;}snake;
snake.snake_dir != up
case left:
case 'a': \tcase 'A': \tcase 75 :
(snake.snake_xy.x[0]+10 == snake.snake_xy.x[i] && snake.snake_xy.y[0] == snake.snake_xy.y[i]) || (snake.snake_xy.x[0] == snake.snake_xy.x[i] && snake.snake_xy.y[0] == snake.snake_xy.y[i])
定义蛇的移动void move_snake()
struct Food{\tint food_x;\tint food_y;\tchar food_flag;\tint food_score;}food;
char userKey = _getch();
i=0
x = rand() % 49;\t\t\ty = rand() % 49;\t\t\tfood.food_x = x * 10;\t\t\tfood.food_y = y * 10;
(snake.snake_xy.x[0]-10 == snake.snake_xy.x[i] && snake.snake_xy.y[0] == snake.snake_xy.y[i]) || (snake.snake_xy.x[0] == snake.snake_xy.x[i] && snake.snake_xy.y[0] == snake.snake_xy.y[i])
snake.snake_dir != right
switch snake.snake_dir
setbkcolor(0x000000)
i = snake.snake_length - 1
flag=1
case right:
snake.snake_xy.x[i] = snake.snake_xy.x[i - 1];\t\tsnake.snake_xy.y[i] = snake.snake_xy.y[i - 1];
struct point{\tint x[50];\tint y[50];};
i < snake.snake_length - 1
switch (userKey)
int i;\tcleardevice();//清屏\tsetfillcolor(0x55FF55);// 设置当前填充颜色
food.food_x = 200;\tfood.food_y = 200;\tfood.food_flag = 0;\tfood.food_score = 0;
(snake.snake_xy.x[0] == snake.snake_xy.x[i] && snake.snake_xy.y[0]-10 == snake.snake_xy.y[i]) || (snake.snake_xy.x[0] == snake.snake_xy.x[i] && snake.snake_xy.y[0] == snake.snake_xy.y[i])
void Windows_init()
(snake.snake_xy.x[0] == snake.snake_xy.x[i] && snake.snake_xy.y[0]+10 == snake.snake_xy.y[i]) || (snake.snake_xy.x[0] == snake.snake_xy.x[i] && snake.snake_xy.y[0] == snake.snake_xy.y[i])
case down : snake.snake_xy.y[0] = snake.snake_xy.y[0] + 10;\t\tbreak;
snake.snake_xy.x[0] = 10; snake.snake_xy.y[0] = 0; snake.snake_xy.x[1] = 0; snake.snake_xy.y[1] = 0; snake.snake_xy.x[2] = -10; snake.snake_xy.y[2] = 0; snake.snake_dir = right; snake.snake_length = 3;
snake.snake_dir != down
case right: if (snake.snake_xy.x[0] == 490)\treturn 1; break;
设置键盘映射void key_dowm()
case up:
switch (snake.snake_dir)
int i;
吃到食物后进行的相关操作void eat_food()
调用窗口void Windows_init()
case down: if (snake.snake_xy.y[0] == 490)\treturn 1; break;
snake.snake_dir = right; break;
定义食物的初始参数void food_init()
case up: snake.snake_xy.y[0] = snake.snake_xy.y[0] - 10;\t\tbreak;
case up: if (snake.snake_xy.y[0] == 0)\treturn 1; break;
case left: snake.snake_xy.x[0] = snake.snake_xy.x[0] - 10; break;
snake.snake_xy.x[0] == food.food_x && snake.snake_xy.y[0] == food.food_y
在窗口中显示食物void show_food()
snake.snake_length += 1; food.food_flag = 1; food.food_score += 10;
i > 0
0 条评论
下一页
为你推荐
查看更多
抱歉,暂无相关内容