W ramach nauki C++ piszę snake'a kod nie jest w całości mój. W 90% go rozumiem ale mam problem z jednym konstruktorem
//Klasa Food
Food::Food(Snake *s) // całkowicie nie rozumiem tego konstruktora
{
snake = s; // jak wyżej, nie wiem jak go rozumieć jak z niego skorzystać
this -> osX = 41;
this -> osY = 9;
srand(time(NULL));
}
Food::~Food()
{
}
void Food::setFeed(char xo, char yo){
if ((xo == snake -> getNewX()+1) && (yo == snake->getNewY()+1)) {
this->osX = (rand() % 79) + 2;
this->osY = (rand() % 24) + 2;
}
}
void Food::check() {
this -> setFeed(this->getFeedX(),this->getFeedY());
}
char Food::getFeedX() {
return this-> osX;
}
char Food::getFeedY() {
return this -> osY;
}
}
Klasa Sneak
#include "Snake.h"
Snake::Snake()
{
this->velX = 0;
this->velY = -1;
this->segments.push_front(SnakeSegment(40, 12));
this->segments.push_front(SnakeSegment(40, 11));
this->segments.push_front(SnakeSegment(40, 10));
this->oldTail.setPosition(40,13);
}
Snake::~Snake()
{
}
void Snake::setHeadPosition(char x, char y)
{
this->segments.front().setPosition(x, y);
}
void Snake::setVel(char x, char y)
{
this->velX = x;
this->velY = y;
}
char Snake::getNewX()
{
return newX;
}
char Snake::getNewY()
{
return newY;
}
void Snake::delta()
{
newX = this->segments.front().x + this->velX;
newY = this->segments.front().y + this->velY;
// nowa głowa
this->segments.push_front(SnakeSegment(newX, newY));
// zapamiętaj i usuń ostatni segment ogona
this->oldTail = this->segments.back();
this->segments.pop_back();
}
list<SnakeSegment> Snake::getSegments()
{
return segments;
}
SnakeSegment Snake::getOldTail()
{
return this->oldTail;
}
potem oczywiście wywołuje konstruktor Sneak z parametrem sneak w trzeciej klasie
wszystko co prawda mi działa ale chcę zrozumieć co tu się dzieje