blob: 6d66a79029156ee178f37b961aef7b8c184acddc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#include <stdio.h>
#include <iostream>
#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_currentCoordinates = Coordinates(0, 0);
m_velocityVector = VelocityVector(0, 1);
// 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<Coordinates> Player::move() {
std::vector<Coordinates> 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);
}
|