|
@ -6,7 +6,7 @@ Snake::Snake(int headY, int headX) |
|
|
:direction{LEFT} |
|
|
:direction{LEFT} |
|
|
{ |
|
|
{ |
|
|
snake.push_back(Point{headY, headX, '>'}); //add the head of the snake
|
|
|
snake.push_back(Point{headY, headX, '>'}); //add the head of the snake
|
|
|
for(int i=1; i<=3; i++) |
|
|
|
|
|
|
|
|
for(int i=1; i<=7; i++) |
|
|
snake.push_back(Point{headY, headX+i, BODY}); |
|
|
snake.push_back(Point{headY, headX+i, BODY}); |
|
|
this->printSnake(); |
|
|
this->printSnake(); |
|
|
} |
|
|
} |
|
@ -21,6 +21,7 @@ bool Snake::isBitten(void){ |
|
|
while(body_part != snake.end()){ |
|
|
while(body_part != snake.end()){ |
|
|
if(body_part->getX() == head.getX() && body_part->getY() == head.getY()) |
|
|
if(body_part->getX() == head.getX() && body_part->getY() == head.getY()) |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
body_part++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
@ -30,6 +31,15 @@ bool Snake::hasBitSnack(int snackY, int snackX){ |
|
|
return readChar(snackY, snackX) == SNACK; |
|
|
return readChar(snackY, snackX) == SNACK; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Snake::hasCrashedWall(void){ |
|
|
|
|
|
Point &head = *snake.begin(); |
|
|
|
|
|
|
|
|
|
|
|
return (head.getY() < GAME_TOP_WALL_Y) || |
|
|
|
|
|
(head.getY() > GAME_BOTTOM_WALL_Y) || |
|
|
|
|
|
(head.getX() < GAME_LEFT_WALL_X) || |
|
|
|
|
|
(head.getX() > GAME_RIGHT_WALL_X); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
int Snake::getSize(void){ |
|
|
int Snake::getSize(void){ |
|
|
return snake.size(); |
|
|
return snake.size(); |
|
|
} |
|
|
} |
|
|