-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.cpp
65 lines (50 loc) · 992 Bytes
/
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
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include "map.h"
#include "game.h"
extern char* maps[];
//Done By Daniel(Leader) & Amirul
//Tips from Mr Alex Toh
PMAP load_map(int x)
{
//using pointers to generate the map
MAP* map;
char* filename = maps[x];
ifstream infile;
int nrow, ncol, i;
infile.open(filename);
if (!infile)
{
cout << "Error Opening" << filename << endl ;
exit(1);
}
if (infile.good())
{
// get nrow and ncol at 1st line of the file
infile >> nrow >> ncol;
// allocate the MAP structure and memory to hold the map data
map = new MAP(nrow, ncol);
// read back the map data
i= 0;
while(infile.good())
{
string line;
getline(infile, line);
if (line.length())
{
memcpy(map->data[i],line.c_str(), ncol);
i++;
}
}
}
infile.close();
return map;
}
//Done By Daniel(Leader) & Amirul
//Tips from Mr Alex Toh
void free_map(PMAP pmap)
{
delete pmap;
}