-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
82 lines (77 loc) · 1.79 KB
/
Map.cpp
File metadata and controls
82 lines (77 loc) · 1.79 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
#include "Map.h"
#include <iostream>
using namespace std;
Map::Map(int n, int m)
{
height = n;
width = m;
M.resize(n);
for (int i = 0; i < n; i++)
M[i].resize(m);
M[0][0] = 1;
}
Map::~Map()
{
M.erase(M.begin(), M.end());
}
Map::Map(Map &obj)
{
height = obj.height;
width = obj.width;
M.resize(height);
for (int i = 0; i < height; i++)
M[i].resize(width);
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
M[i][j] = obj.M[i][j];
}
bool Map::is_trap(pair < int, int > p) const
{
if (M[p.first][p.second] == -1)
{
return true;
}
return false;
}
Map &Map::operator=(const Map &A)
{
if (this != &A)
{
height = A.height;
width = A.width;
treasure_position.first = A.treasure_position.first;
treasure_position.second = A.treasure_position.second;
M.resize(height);
for (int i = 0; i < height; i++)
M[i].resize(width);
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
M[i][j] = A.M[i][j];
}
return *this;
}
void operator << (int x, Map & world)
{
int i, j;
for (i = 0; i < world.height; i++)
cout << "__";
cout << "\n";
for (i = 0; i < world.height; i++)
{
for (j = 0; j < world.width; j++)
{
if(j == 0)
cout << "| ";
if(world.M[i][j] == 0)
cout << "_ ";
else
cout << world.M[i][j] << " ";
if(j == world.width - 1)
cout << "|";
}
cout << "\n";
}
for (i = 0; i < world.height; i++)
cout << "__";
cout << "\n";
}