Subversion Repositories sssnakesss

Rev

Rev 13 | 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;
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
    {
26
        case up:
27
            nextPoint(Point(points[0].X, points[0].Y - 1));
28
        case down:
29
            nextPoint(Point(points[0].X, points[0].Y + 1));
30
        case left:
31
            nextPoint(Point(points[0].X - 1, points[0].Y));
32
        case right:
33
            nextPoint(Point(points[0].X + 1, points[0].Y));
34
    }
35
}