diff --git a/practise/practise.cpp b/practise/practise.cpp index 694a42d..dabe1a9 100644 --- a/practise/practise.cpp +++ b/practise/practise.cpp @@ -4,11 +4,33 @@ #include #include #include +#include +//创建方向的枚举类型 +enum Direction{UP,DOWN,LEFT,RIGHT}; +//贪吃蛇的抽象基类 class Base { public: - int positionX; - + Base() { + m_x = 50; + m_y = 50; + } + Base(int x,int y) { + m_x = x; + m_y = y; + } + //绘图 + virtual void show() { + setlinecolor(BLUE); + fillcircle(m_x, m_y, 6); + } + //移动 + void move(int x,int y) { + m_x += x; + m_x += y; + } + int m_x; + int m_y; private: }; /* @@ -17,17 +39,32 @@ private: 具有的方法:移动 */ class Snake :public Base{ - +public: + int snake_lenth; + int speed = 100; + //利用vector来存储蛇的节点 + std::vector nodes; + Direction direction; + Snake() { + //默认向右移动 + direction = RIGHT; + //位置 + nodes.push_back(Base()); + speed = 100; + } + //显示蛇的身体 + void Show() { + for(int i=0;i