(root)/src/snake.cpp - Rev 16
Rev 15 |
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;
dead = false; // FALSE ?
}
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;
}
}
void append(int num)
{
Point * p = & points[points.size() - 1];
points.push_back(*p);
}