From f3252a9930d2018964cd5f8b11f7ac1d33d2035a Mon Sep 17 00:00:00 2001 From: pw6mfljci <2537107798@qq.com> Date: Mon, 17 Jun 2024 19:12:00 +0800 Subject: [PATCH] ADD file via upload --- snake.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 snake.h diff --git a/snake.h b/snake.h new file mode 100644 index 0000000..9a1253e --- /dev/null +++ b/snake.h @@ -0,0 +1,44 @@ +#pragma once + +#include "common.h" +#include +class Snake +{ +public: + const int MinSpeed = 1; //蛇的最小速度 + const int MaxSpeed = 25; //蛇的最大速度 + const int OrgSpeed = 20; //蛇的原始速度 + +private: + int m_len; //蛇的长度 + int m_speed; //蛇的速度 + Dir m_direction; //蛇的方向 + Point m_tail; //蛇移动过后的尾部节点,主要用于吃食物 + +public: + Snake(); + Snake(int x); + std::list m_snakelist; //蛇的链表 + int getLen(); //获取长度 + int getSpeed(); //获取速度 + Dir getDirection(); //获取方向 + bool setSpeed(int speed); //设置速度,设置成功返回true + + void Move(); //移动一节 + void EatFood(); //吃食物 + void ChangeDir(Dir dir); //改变方向 + void Dead(); //死亡 + + bool ColideWall(int left, int top, int right, int bottom); //碰撞到墙 + bool ColideSnake(); //碰撞到了自身 + bool ColideSnake2(Snake& m_snake2); //碰到其它蛇 + bool ColideFood(Point point); //碰到了食物 + + void DrawSnake(); //绘制蛇 + void DrawSnake2(); //绘制蛇2 + void DrawSnakeHead(Point pos); //绘制蛇头 + void DrawSnakeNode(Point pos); //绘制蛇的身体结点 + void DrawSnakeHead2(Point pos); //绘制蛇头2 + void DrawSnakeNode2(Point pos); //绘制蛇的身体结点2 + std::list GetSnakeAllNode(); +};