-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
112 lines (111 loc) · 2.4 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
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
108
109
110
111
112
#include "Player.h"
Direction Player::get_direction(int *dx, int *dy) {
if (dx) {
*dx = _dx;
}
if (dy) {
*dy = _dy;
}
if (this->_dx == -1)
return Direction::Up;
if (this->_dx == 1)
return Direction::Down;
if (this->_dy == -1)
return Direction::Left;
return Direction::Right;
}
void Player::_set_direction(Direction new_direction) {
switch (new_direction) {
case Direction::Up:
this->_dx = -1;
this->_dy = 0;
break;
case Direction::Down:
this->_dx = 1;
this->_dy = 0;
break;
case Direction::Left:
this->_dy = -1;
this->_dx = 0;
break;
case Direction::Right:
this->_dy = 1;
this->_dx = 0;
break;
}
}
int Player::get_arrow_count() { return this->_arrow_count; }
int Player::get_action_count() { return this->_action_count; }
bool Player::is_grab_gold() { return this->_is_grab_gold; }
int Player::get_state() { return this->_state; }
void Player::turn_left() {
int dx, dy;
Direction old = get_direction(&dx, &dy);
switch (old) {
case Direction::Up:
_set_direction(Direction::Left);
break;
case Direction::Down:
_set_direction(Direction::Right);
break;
case Direction::Left:
_set_direction(Direction::Down);
break;
case Direction::Right:
_set_direction(Direction::Up);
break;
}
}
void Player::turn_right() {
int dx, dy;
Direction old = get_direction(&dx, &dy);
switch (old) {
case Direction::Up:
_set_direction(Direction::Right);
break;
case Direction::Down:
_set_direction(Direction::Left);
break;
case Direction::Left:
_set_direction(Direction::Up);
break;
case Direction::Right:
_set_direction(Direction::Down);
break;
}
}
int Player::move() {
this->_x += this->_dx;
this->_y += this->_dy;
return 0;
}
int Player::move_to(int x, int y) {
this->_x = x;
this->_y = y;
return 0;
}
int Player::shoot() {
this->_arrow_count--;
return 0;
}
int Player::grab() {
this->_is_grab_gold = true;
return 0;
}
void Player::init() {
_x = 0;
_y = 0;
_dx = 1;
_dy = 0;
_is_grab_gold = false;
_action_count = 0;
is_dead = false;
}
Player::Player() : _arrow_count(1) { init(); }
Player::Player(int arrow_count) : _arrow_count(arrow_count) { init(); }
void Player::grab_gold() { _is_grab_gold = true; }
void Player::add_action_count() { _action_count++; }
void Player::set_arrow_count(int count){
_arrow_count = count;
}
// Smell Player::smell() {}