框架
This commit is contained in:
parent
8e828b68dc
commit
6d87594d11
@ -4,11 +4,33 @@
|
||||
#include<random>
|
||||
#include<graphics.h>
|
||||
#include<conio.h>
|
||||
#include<vector>
|
||||
//创建方向的枚举类型
|
||||
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<Base> nodes;
|
||||
Direction direction;
|
||||
Snake() {
|
||||
//默认向右移动
|
||||
direction = RIGHT;
|
||||
//位置
|
||||
nodes.push_back(Base());
|
||||
speed = 100;
|
||||
}
|
||||
//显示蛇的身体
|
||||
void Show() {
|
||||
for(int i=0;i<nodes.size();i++){
|
||||
nodes[i].show();
|
||||
}
|
||||
}
|
||||
};
|
||||
class Food : public Base {
|
||||
|
||||
public:
|
||||
};
|
||||
int main() {
|
||||
while (true) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user