-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjPos.cpp
More file actions
100 lines (84 loc) · 1.7 KB
/
Copy pathobjPos.cpp
File metadata and controls
100 lines (84 loc) · 1.7 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "objPos.h"
objPos::objPos()
{
pos = new Pos;
pos->x = 0;
pos->y = 0;
symbol = 0; //NULL
}
objPos::objPos(int xPos, int yPos, char sym)
{
pos = new Pos;
pos->x = xPos;
pos->y = yPos;
symbol = sym;
}
// Respect the rule of six / minimum four
// [TODO] Implement the missing special member functions to meet the minimum four rule
// Destructor
objPos::~objPos()
{
delete pos;
}
// Copy Constructor
objPos::objPos(const objPos &other)
{
pos = new Pos;
pos -> x = other.pos -> x;
pos -> y = other.pos -> y;
symbol = other.symbol;
}
// Copy Assignment Operator
objPos &objPos::operator=(const objPos &other)
{
if (this != &other) // Check for self-assignment
{
// Clean up existing resources
delete pos;
// Allocate new memory and copy the data
pos = new Pos;
pos -> x = other.pos -> x;
pos -> y = other.pos -> y;
symbol = other.symbol;
}
return *this;
}
void objPos::setObjPos(objPos o)
{
pos->x = o.pos->x;
pos->y = o.pos->y;
symbol = o.symbol;
}
void objPos::setObjPos(int xPos, int yPos, char sym)
{
pos->x = xPos;
pos->y = yPos;
symbol = sym;
}
objPos objPos::getObjPos() const
{
objPos returnPos;
returnPos.pos->x = pos->x;
returnPos.pos->y = pos->y;
returnPos.symbol = symbol;
return returnPos;
}
char objPos::getSymbol() const
{
return symbol;
}
bool objPos::isPosEqual(const objPos* refPos) const
{
return (refPos->pos->x == pos->x && refPos->pos->y == pos->y);
}
char objPos::getSymbolIfPosEqual(const objPos* refPos) const
{
if(isPosEqual(refPos))
{
return symbol;
}
else
{
return 0;
}
}