void Game::playerMoved(DIRECTION::Direction d){ AbstractPlayer* p = dynamic_cast<AbstractPlayer*>(this->sender()); if (p == nullptr) return; Position pos = p->getPosition(); if (d == DIRECTION::UP) pos.second--; else if (d == DIRECTION::DOWN) pos.second++; else if (d == DIRECTION::LEFT) pos.first--; else if (d == DIRECTION::RIGHT)pos.first++; if (this->map->isFree(pos)){ this->removeObject(p->getPosition(), OBJECTS::PLAYER); p->setPosition(pos); this->addObject(p->getPosition(), OBJECTS::PLAYER); } this->checkPlayers(); }
AbstractPlayer* Game::addPlayer(){ AbstractPlayer *pl = new AbstractPlayer(this->getFreePosition(), this); this->addObject(pl->getPosition(), OBJECTS::PLAYER); this->connectPlayer(pl); return pl; }