实现了贪吃蛇的移动和打印
This commit is contained in:
parent
6d87594d11
commit
8fae4e8b4a
@ -45,6 +45,7 @@ public:
|
||||
//利用vector来存储蛇的节点
|
||||
std::vector<Base> nodes;
|
||||
Direction direction;
|
||||
|
||||
Snake() {
|
||||
//默认向右移动
|
||||
direction = RIGHT;
|
||||
@ -58,6 +59,30 @@ public:
|
||||
nodes[i].show();
|
||||
}
|
||||
}
|
||||
//给爷动起来!
|
||||
void MoveInDirection() {
|
||||
|
||||
if (GetAsyncKeyState(37)) {
|
||||
if(direction!=LEFT) {
|
||||
direction = LEFT;
|
||||
}
|
||||
}
|
||||
else if (GetAsyncKeyState(38)) {
|
||||
if (direction != UP) {
|
||||
direction = LEFT;
|
||||
}
|
||||
}
|
||||
else if (GetAsyncKeyState(39)) {
|
||||
if (direction != RIGHT) {
|
||||
direction = LEFT;
|
||||
}
|
||||
}
|
||||
else if (GetAsyncKeyState(40)) {
|
||||
if (direction != DOWN) {
|
||||
direction = LEFT;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
class Food : public Base {
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user