Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Pos { int x, int y; };
- class Snake {
- list<Pos> body;
- Direction dir;
- void move();
- public:
- void mainLoop();
- };
- void Snake::mainLoop(){
- while (true){
- sleep(10);
- move();
- }
- }
- void Snake::move(){
- if (dir == stop){ return; }
- body.pop_back();
- Pos oldHead = *(body.begin()); // get the first element of the list
- Pos newHead = oldHead;
- switch (dir){
- case left: newHead.x--; break;
- case right: newHead.x++; break;
- case up: newHead.y--; break;
- case down: newHead.y++; break;
- };
- body.push_front(newHead});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement