#include #include #include "Player.h" #include "Controller.h" Player::Player(PlayerNumber PlayerID, Coordinates InitialPoint, VelocityVector initialVel) : m_playerID(PlayerID), m_currentCoordinates(InitialPoint), m_velocityVector(initialVel) { m_alive = true; m_pController = NULL; // m_name not initialized } Player::Player() { m_playerID = -1; m_alive = false; m_pController = NULL; // m_name not initialized } Player::~Player(void) { if (m_pController) delete(m_pController); } void Player::setCoordinates(Coordinates c) { m_currentCoordinates = c; } void Player::setNumber(PlayerNumber n) { m_playerID = n; } void Player::revive() { m_alive = true; } std::vector Player::move() { std::vector cases; int sgn_x = m_velocityVector.x >= 0 ? 1 : -1; int sgn_y = m_velocityVector.y >= 0 ? 1 : -1; for (int i = 0; i <= abs(m_velocityVector.x) ; ++i ) { for (int j = 0; j <= abs(m_velocityVector.y) ; ++j ) { cases.push_back(Coordinates(m_currentCoordinates.x+i*sgn_x, m_currentCoordinates.y+j*sgn_y)); } } m_currentCoordinates.x += m_velocityVector.x; m_currentCoordinates.y += m_velocityVector.y; return(cases); } void Player::setVelocity(VelocityVector v) { m_velocityVector = v; } void Player::turnLeft() { VelocityVector t = VelocityVector(- m_velocityVector.y, m_velocityVector.x); m_velocityVector = t; } void Player::turnRight() { VelocityVector t = VelocityVector(m_velocityVector.y, - m_velocityVector.x); m_velocityVector = t; } bool Player::changeDirection(VelocityVector v) { if ((m_velocityVector.x != 0 && v.x != 0) || (m_velocityVector.y != 0 && v.y != 0)) { return(false); } else { m_velocityVector = v; return(true); } } bool Player::isAlive() { return(m_alive); } void Player::kill() { m_alive = false; } PlayerNumber Player::getNumber() { return(m_playerID); } Controller* Player::getController() { return(m_pController); } void Player::setController(Controller* pController) { m_pController=pController; } VelocityVector Player::getVelocity() { return(m_velocityVector); } Coordinates Player::getCoordinates() { return(m_currentCoordinates); }