summary refs log tree commit diff stats
path: root/src/map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/map.cpp b/src/map.cpp index fda8009..87080e8 100644 --- a/src/map.cpp +++ b/src/map.cpp
@@ -1,7 +1,14 @@
1#include "map.h" 1#include "map.h"
2#include "game.h" 2#include "game.h"
3#include <cstdlib>
4#include <cstring>
3 5
4Map::Map(char* filename) 6Map::Map()
7{
8
9}
10
11Map::Map(const char* filename)
5{ 12{
6 FILE* f = fopen(filename, "r"); 13 FILE* f = fopen(filename, "r");
7 14
@@ -22,12 +29,44 @@ Map::Map(char* filename)
22 fclose(f); 29 fclose(f);
23} 30}
24 31
32Map::Map(Map& map)
33{
34 m_mapdata = (int*) malloc(MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(int));
35 memcpy(m_mapdata, map.m_mapdata, MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(int));
36
37 m_title = (char*) malloc((MAP_WIDTH+1)*sizeof(char));
38 strncpy(m_title, map.m_title, MAP_WIDTH+1);
39
40 m_leftMap = map.m_leftMap;
41 m_rightMap = map.m_rightMap;
42}
43
44Map::Map(Map&& map) : Map()
45{
46 swap(*this, map);
47}
48
25Map::~Map() 49Map::~Map()
26{ 50{
27 free(m_mapdata); 51 free(m_mapdata);
28 free(m_title); 52 free(m_title);
29} 53}
30 54
55Map& Map::operator= (Map map)
56{
57 swap(*this, map);
58
59 return *this;
60}
61
62void swap(Map& first, Map& second)
63{
64 std::swap(first.m_mapdata, second.m_mapdata);
65 std::swap(first.m_title, second.m_title);
66 std::swap(first.m_leftMap, second.m_leftMap);
67 std::swap(first.m_rightMap, second.m_rightMap);
68}
69
31const int* Map::mapdata() 70const int* Map::mapdata()
32{ 71{
33 return m_mapdata; 72 return m_mapdata;