(root)/src/snake.cpp - Rev 15
Rev 14 |
Rev 16 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <vector>
using namespace std;
#include "point.hpp"
#include "snake.hpp"
Snake::Snake()
{
R = 255;
G = 255;
B = 0;
direction = Up;
}
void Snake::nextPoint(Point newPoint)
{
points.insert(points.begin(), newPoint);
points.pop_back();
}
void Snake::move()
{
switch (direction)
{
case Up:
nextPoint(Point(points[0].X, points[0].Y - 1));
break;
case Down:
nextPoint(Point(points[0].X, points[0].Y + 1));
break;
case Left:
nextPoint(Point(points[0].X - 1, points[0].Y));
break;
case Right:
nextPoint(Point(points[0].X + 1, points[0].Y));
break;
}
}