-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
76 lines (63 loc) · 1.46 KB
/
Copy pathPlayer.cpp
File metadata and controls
76 lines (63 loc) · 1.46 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
75
76
//
// Created by Owner on 6/1/2024.
//
#include "Player.h"
Player::Player(char symbol) : Entity(1,1, symbol){
if(symbol == '$' || symbol == '#' || symbol == 'H' || !(isalnum(symbol)))
throw NameError();
}
Player::Player(int x, int y, char symbol) : Entity(x, y, symbol) {
if(symbol == '$' || symbol == '#' || symbol == 'H')
throw NameError();
}
Player::Player(const Player &other) : Entity(other) {}
Player &Player::operator=(const Player &other) {
x = other.x;
y = other.y;
symbol = other.symbol;
return *this;
}
void swap(Player &first, Player &second) {
using std::swap;
swap(first.x, second.x);
swap(first.y, second.y);
// Swap alte membri dacă există
}
std::ostream &operator<<(std::ostream &os, const Player &player) {
os << "x: " << player.x << " y: " << player.y << " symbol: " << player.symbol<<"\n";
return os;
}
void Player::move(int directionX, int directionY) {
x=x+directionX;
y=y+directionY;
}
void Player::reset() {
x=1;
y=1;
gun.reset();
}
void Player::fire(){
gun.fire(x+1, y);
}
Gun& Player::getGun() {
return gun;
}
Gun::Gun(int x, int y, char symbol, bool isFired): Entity(x, y, symbol), isFired(isFired){}
void Gun::fire(int _x, int _y) {
if(isFired)
throw FireError();
x = _x;
y = _y;
isFired = true;
}
bool Gun::getIsFired(){
return isFired;
}
void Gun::move(){
x+=3;
}
void Gun::reset() {
isFired=false;
x=0;
y=0;
}