-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.cpp
executable file
·54 lines (43 loc) · 1.23 KB
/
map.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
#include "map.h"
#include "iostream"
#include "block.h"
using namespace std;
Map::Map(int _rowcount, int _colcount){
rowcount=_rowcount;
colcount=_colcount;
map=new Block*[rowcount];
for(int i=0; i<rowcount; i++)
map[i]=new Block[colcount];
//--------------------------------------------------------set all block empty
for(int i=0; i<rowcount; i++)
for(int j=0; j<colcount; j++)
map[i][j].setEmpty();
//---------------------------------------------------------set row and col of all block
for(int i=0; i<rowcount; i++)
for(int j=0; j<colcount; j++)
map[i][j].setPlace(i,j);
}
Block* Map::getBlock(int row,int col){
if( 0<=row && row<rowcount && 0<=col && col<colcount )
return &(map[row][col]);
else
return NULL;
}
Map::~Map(){
for(int i=0; i<rowcount; i++)
delete []map[i];
delete []map;
}
int Map::GetRowcount(){
return rowcount;
}
int Map::GetColcount(){
return colcount;
}
void Map::Eqaul(Map* _map){
for(int i=0; i<rowcount; i++)
for(int j=0; j<colcount; j++){
Block* temp=_map->getBlock(i,j);
map[i][j]=(*temp);
}
}