-
Notifications
You must be signed in to change notification settings - Fork 22
/
Location.cc
58 lines (50 loc) · 879 Bytes
/
Location.cc
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
// Location.cc
#include "Location.h"
Location::Location ()
{
X = 0;
Y = 0;
}
Location::Location (int x, int y)
{
X = x;
Y = y;
}
Location::Location (const Location& location)
{
X = location.X;
Y = location.Y;
}
Location& Location::operator= (const Location& location)
{
if (this == &location)
{
return *this;
}
X = location.X;
Y = location.Y;
return *this;
}
bool Location::operator== (const Location& location) const
{
if ((X == location.X) && (Y == location.Y))
{
return true;
}
return false;
}
bool Adjacent (const Location& location1, const Location& location2)
{
int X1 = location1.X;
int X2 = location2.X;
int Y1 = location1.Y;
int Y2 = location2.Y;
if (((X1 == X2) && (Y1 == (Y2 - 1))) ||
((X1 == X2) && (Y1 == (Y2 + 1))) ||
((X1 == (X2 - 1)) && (Y1 == Y2)) ||
((X1 == (X2 + 1)) && (Y1 == Y2)))
{
return true;
}
return false;
}