-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMazeReader.cpp
More file actions
104 lines (92 loc) · 2.15 KB
/
MazeReader.cpp
File metadata and controls
104 lines (92 loc) · 2.15 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* @Author: Anna Fritz
* @File: MazeReader.cpp
* @Date: March 27, 2019
* @Brief: This is the implementation file for the MazeReader class
*/
#include "MazeReader.h"
/**
* @post A MazeReader is created. A 2D char array is allocated with the maze information.
* @throws MazeCreationExecption
*
*/
MazeReader::MazeReader(string file)
{
m_filename = file;
ifstream inFile;
inFile.open(m_filename);
if (inFile.is_open())
{
inFile >> m_numRow >> m_numCol;
inFile >> m_startRow >> m_startCol;
if (m_numCol < 1 || m_numRow < 1 || m_startRow > m_numCol || m_startRow > m_numRow)
{
throw MazeCreationExecption("Invalid starting position. It does not exist on this board.");
}
// creating array
m_maze = new char* [m_numRow];
for (int i = 0; i < m_numRow; i++)
{
m_maze[i] = new char [m_numCol];
}
// filling array
for (int i = 0; i < m_numRow; i++)
{
for (int j = 0; j < m_numCol; j++)
{
inFile >> m_maze[i][j];
}
}
}
inFile.close();
}
/**
* @post The maze is deallocated.
*/
MazeReader::~MazeReader()
{
for (int i = 0; i < m_numRow; i++)
{
delete m_maze[i];
}
delete m_maze;
}
/**
* @pre the file was formatting and read in correctly
* @return Returns pointer to the maze
*/
char** MazeReader::getMaze() const
{
return (m_maze);
}
/**
* @pre the file was formatted and read in correctly
* @returns the number of columns listed in the file
*/
int MazeReader::getCols() const
{
return (m_numCol);
}
/**
* @pre the file was formatted and read in correctly
* @returns the number of rows listed in the file
*/
int MazeReader::getRows() const
{
return (m_numRow);
}
/**
* @pre the file was formatted and read in correctly
* @returns the starting column
*/
int MazeReader::getStartCol() const
{
return (m_startCol);
}
/**
* @pre the file was formatted and read in correctly
* @returns the starting row
*/
int MazeReader::getStartRow() const
{
return (m_startRow);
}