-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
74 lines (66 loc) · 1.87 KB
/
Copy pathPlayer.cpp
File metadata and controls
74 lines (66 loc) · 1.87 KB
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
// Justin Adkins
// Player Implementation
#include "Player.h"
/**
Player Constructor: Inializes Player objects private variables. If enemy, it randomly chooses one of the two SquareTypes associated with the enemies.
*/
Player::Player(const std::string name, const bool is_human) : name_(name), is_human_(is_human) {
// Array of different enemy types
SquareType enemy[2] = {SquareType::Enemy1, SquareType::Enemy2};
if (is_human) {
char_image_ = SquareType::Human;
}
else {
// Choose random character image
char_image_ = enemy[rand() % 2];
}
points_ = 0;
}
/**
ChangePoints is an accessor method to change the value of a players points
*/
void Player::ChangePoints(const int x) {
points_ += x;
}
/**
SetPosition is an accessor method to set the pos_ variable
*/
void Player::SetPosition(Position pos) {
pos_ = pos;
}
/**
ToRelativePosition looks to see if the position passed in is up, down, left, or right of the players current position.
@param other: this is the position we are locating around the players current position.
@return: A string with either the direction of the position, or invalid if an immediate position wasn't given.
*/
std::string Player::ToRelativePosition(Position other) {
if (other.row == pos_.row) {
if (other.col == pos_.col - 1) {
return "LEFT";
}
else if (other.col == pos_.col + 1) {
return "RIGHT";
}
}
else if (other.col == pos_.col) {
if (other.row == pos_.row + 1) {
return "DOWN";
}
else if (other.row == pos_.row - 1) {
return "UP";
}
}
return "INVALID"; // Probably shouldn't get here
}
/**
Stringify is a small helper method to print a players name and points
*/
std::string Player::Stringify() {
return name_ + " has " + std::to_string(points_) + ".\n";
}
/**
set_squaretype is an accessor method to set the char_image_ variable
*/
void Player::set_squaretype(SquareType char_image) {
char_image_ = char_image;
}