summary refs log tree commit diff stats
path: root/src/map.cpp
blob: 5f9e7bd7a74fc9a25c48702f619816a8180081ca (plain) (blame)
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
#include "map.h"
#include "mapview.h"

Map::Map(char* filename)
{
  FILE* f = fopen(filename, "r");
  
  m_mapdata = (int*) malloc(MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(int));
  for (int i=0; i<MAP_HEIGHT-1; i++)
  {
    for (int j=0; j<MAP_WIDTH; j++)
    {
      fscanf(f, "%d,", &(m_mapdata[i*MAP_WIDTH + j]));
    }
    
    fgetc(f);
  }
  
  m_title = (char*) calloc(41, sizeof(char));
  fgets(m_title, 41, f);
  
  fclose(f);
}

Map::~Map()
{
  free(m_mapdata);
  free(m_title);
}

const int* Map::mapdata()
{
  return m_mapdata;
}

const char* Map::title()
{
  return m_title;
}

Map* Map::getLeftMap()
{
  return m_leftMap;
}

Map* Map::getRightMap()
{
  return m_rightMap;
}

void Map::setLeftMap(Map* m)
{
  m_leftMap = m;
}

void Map::setRightMap(Map* m)
{
  m_rightMap = m;
}