/
GameMap.cpp
77 lines (66 loc) · 1.73 KB
/
GameMap.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
//
// Created by teone on 02-Apr-18.
//
#include "GameMap.h"
using namespace std;
GameMap::GameMap(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] = R;
}
GameMap::~GameMap() {
M.erase(M.begin(), M.end()); // ?
// for (int i = 0; i < height; i++)
// delete[] M[i];
// delete[] M;
}
GameMap::GameMap(GameMap &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 GameMap::isTrap(pair<int, int> p) const{
if (M[p.first][p.second] == T) {
return true;
}
return false;
}
bool GameMap::isItem(pair<int, int> p) const{
if (M[p.first][p.second] == I) {
return true;
}
return false;
}
GameMap &GameMap::operator=(const GameMap &A) {
if (this != &A) {
height = A.height;
width = A.width;
treasurePosition.first = A.treasurePosition.first;
treasurePosition.second = A.treasurePosition.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;
}
ofstream &operator << (ofstream &output, GameMap & world) {
int i, j;
for (i = 0; i < world.height; i++) {
for (j = 0; j < world.width; j++) {
output << world.M[i][j] << " ";
}
output << "\n";
}
return output;
}