Subversion Repositories sssnakesss

Rev

Rev 16 | 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 Snake::append(int num)
{
    int index = points.size() - 1;

    if (index >= 0)
    {
        Point p = points[index];
        points.push_back(p);
    }
}