Subversion Repositories sssnakesss

Rev

Rev 15 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 tom 1
#include <vector>
2
 
3
using namespace std;
4
 
5
#include "point.hpp"
9 freddie 6
#include "snake.hpp"
7
 
10 tom 8
Snake::Snake()
9 freddie 9
{
11 freddie 10
    R = 255;
11
    G = 255;
12
    B = 0;
13 tom 13
    direction = Up;
16 freddie 14
    dead = false; // FALSE ?
10 tom 15
}
16
 
17
void Snake::nextPoint(Point newPoint)
18
{
11 freddie 19
    points.insert(points.begin(), newPoint);
20
    points.pop_back();
10 tom 21
}
14 freddie 22
 
23
void Snake::move()
24
{
25
    switch (direction)
26
    {
15 tom 27
        case Up:
14 freddie 28
            nextPoint(Point(points[0].X, points[0].Y - 1));
15 tom 29
            break;
30
 
31
        case Down:
14 freddie 32
            nextPoint(Point(points[0].X, points[0].Y + 1));
15 tom 33
            break;
34
 
35
        case Left:
14 freddie 36
            nextPoint(Point(points[0].X - 1, points[0].Y));
15 tom 37
            break;
38
 
39
        case Right:
14 freddie 40
            nextPoint(Point(points[0].X + 1, points[0].Y));
15 tom 41
            break;
14 freddie 42
    }
43
}
16 freddie 44
 
45
void append(int num)
46
{
47
    Point * p = & points[points.size() - 1];
48
    points.push_back(*p);
49
}