-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameMap.h
51 lines (51 loc) · 969 Bytes
/
GameMap.h
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
#ifndef GAME_MAP_H
#define GAME_MAP_H
#include "AggregateBase.h"
#include <iostream>
#include <deque>
using namespace std;
class GameMap: public AggregateBase
{
public:
GameMap(int height, int width):m_height(height), m_width(width)
{
for(int i = 0; i < height; ++i)
{
int* cur = new int[width];
memset((void*)cur, 0, sizeof(int)*width);
m_deque.push_back(cur);
}
}
virtual ~GameMap()
{
for(int i = 0; i < m_height; ++i)
{
delete [] m_deque[i];
}
}
virtual IteratorBase* iterator(){return NULL;};
virtual int getMapXY(int x, int y)
{
if ( x>=m_height || y>=m_width || x < 0 || y < 0) return -1;
return m_deque[x][y];
}
virtual int setMapXY(int x, int y, int v)
{
if ( x>=m_height || y>=m_width || x < 0 || y < 0) return -1;
m_deque[x][y] = v;
return 0;
}
virtual int getWidth()
{
return m_width;
}
virtual int getHeight()
{
return m_height;
}
private:
int m_height;
int m_width;
deque<int*> m_deque;
};
#endif