-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
47 lines (41 loc) · 1.16 KB
/
Player.cpp
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
#include "Player.hh"
/*
** To see all the elements of the class easly
*/
std::ostream& operator<<(std::ostream& os, const Player& player)
{
static std::string const dir[4] = {"up", "right", "down", "left"};
os << player.getName() << " posX = " << player.getPosx() << " - posY = " << player.getPosy() << " - points = " << player.getNbPoints() << " direction = " << dir[player.getDirection()];
return os;
}
Player::Player(int posX, int posY, std::string const &image, std::string const &name, int points)
: ACharacter(ACharacter::RIGHT)
{
this->posX = posX;
this->posY = posY;
this->image = image;
this->nbPoints = points;
this->name = name;
this->lifePoints = 1;
}
Player::~Player()
{
}
void Player::update(Subject *sub)
{
std::cerr << this->name << ": update()" << std::endl;
GameElement *elem = dynamic_cast<GameElement *>(sub);
if (elem->getPosx() == this->posX && elem->getPosy() == this->posY)
{
if (elem->getEatable() == false)
{
std::cerr << this->name << " will be dead" << std::endl;
--this->lifePoints;
}
else
{
std::cerr << this->name << " is getting more points." << std::endl;
this->nbPoints += elem->getNbPoints();
}
}
}