Subversion Repositories sssnakesss

Rev

Rev 14 | Rev 16 | 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;
10 tom 14
}
15
 
16
void Snake::nextPoint(Point newPoint)
17
{
11 freddie 18
    points.insert(points.begin(), newPoint);
19
    points.pop_back();
10 tom 20
}
14 freddie 21
 
22
void Snake::move()
23
{
24
    switch (direction)
25
    {
15 tom 26
        case Up:
14 freddie 27
            nextPoint(Point(points[0].X, points[0].Y - 1));
15 tom 28
            break;
29
 
30
        case Down:
14 freddie 31
            nextPoint(Point(points[0].X, points[0].Y + 1));
15 tom 32
            break;
33
 
34
        case Left:
14 freddie 35
            nextPoint(Point(points[0].X - 1, points[0].Y));
15 tom 36
            break;
37
 
38
        case Right:
14 freddie 39
            nextPoint(Point(points[0].X + 1, points[0].Y));
15 tom 40
            break;
14 freddie 41
    }
42
}