/include/sssnakesss.hpp |
---|
16,7 → 16,10 |
void run(); |
void checkEvents(); |
void update(); |
void motion(); |
void draw(); |
void initLevel(int level); |
35,6 → 38,7 |
Snake *snake; // controlled snake (snakes[0]) |
vector<Snake *> snakes; // all snakes |
Point food; |
vector<Point> obstacles; |
}; |
/include/snake.hpp |
---|
16,8 → 16,9 |
void nextPoint(Point newPoint); |
void move(); |
void append(int num); |
// Stuff that should be private |
// Stuff that should be private - Did I write this comment? (F) |
vector<Point> points; // list of points snake occupies |
// Colour Values |
27,6 → 28,8 |
Direction direction; |
bool dead; |
}; |
#endif // SNAKE_HPP |
/src/sssnakesss.cpp |
---|
99,7 → 99,7 |
void SSSNAKESSS::initLevel(int level) |
{ |
obstacles.erase(obstacles.begin(), obstacles.end()); |
obstacles.erase(obstacles.begin(), obstacles.end() - 1); |
for (int i = 0; i < level * 3; i++) |
{ |
// add random obstacle |
143,11 → 143,10 |
void SSSNAKESSS::motion() |
{ |
snake * s; |
for (int i = 0; i < snakes.size(); i++) |
for (unsigned int i = 0; i < snakes.size(); i++) |
{ |
s = snakes[i]; |
s.move(); |
Snake *s = snakes[i]; |
s->move(); |
} |
} |
/src/snake.cpp |
---|
11,6 → 11,7 |
G = 255; |
B = 0; |
direction = Up; |
dead = false; // FALSE ? |
} |
void Snake::nextPoint(Point newPoint) |
23,13 → 24,26 |
{ |
switch (direction) |
{ |
case up: |
case Up: |
nextPoint(Point(points[0].X, points[0].Y - 1)); |
case down: |
break; |
case Down: |
nextPoint(Point(points[0].X, points[0].Y + 1)); |
case left: |
break; |
case Left: |
nextPoint(Point(points[0].X - 1, points[0].Y)); |
case right: |
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); |
} |