forked from msdohehrty/dsa555-s16
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaze.cpp
More file actions
93 lines (85 loc) · 1.51 KB
/
maze.cpp
File metadata and controls
93 lines (85 loc) · 1.51 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
#include "maze.h"
#include <string>
#include <fstream>
#include <iostream>
#include <cstdio>
using namespace std;
Maze::Maze(string mazeFile){
fstream fs(mazeFile,ios::in);
char s[2000];
char curr;
fs.getline(s,99,'\n');
sscanf(s,"%d %d",&width_,&height_);
theMaze_=new int*[height_];
for(int i=0;i<height_;i++){
theMaze_[i]=new int[width_];
}
for(int i=0;i<height_;i++){
fs.getline(s,1999,'\n');
for(int j=0;j<width_;j++){
curr=s[j];
if(curr=='X'){
theMaze_[i][j]=WALL;
}
else if(curr==' '){
theMaze_[i][j]=EMPTY;
}
}
}
fs.close();
}
bool Maze::isWall(const Coord& co) const{
bool rc=false;
if(theMaze_[co.y][co.x]==WALL){
rc=true;
}
return rc;
}
bool Maze::isEmpty(const Coord& co) const{
bool rc=false;
if(theMaze_[co.y][co.x]==EMPTY){
rc=true;
}
return rc;
}
bool Maze::isMarked(const Coord& co) const{
bool rc=false;
if(theMaze_[co.y][co.x]==MARKED){
rc=true;
}
return rc;
};
bool Maze::mark(const Coord& co){
bool rc=false;
if(isEmpty(co)){
theMaze_[co.y][co.x]=MARKED;
rc=true;
}
return rc;
}
bool Maze::unMark(const Coord& co){
bool rc=false;
if(isMarked(co)){
theMaze_[co.y][co.x]=EMPTY;
rc=true;
}
return rc;
}
Maze::~Maze(){
for(int i=0;i<height_;i++){
delete [] theMaze_[i];
}
delete [] theMaze_;
}
void Maze::print() const{
for(int i=0;i<height_;i++){
for (int j=0;j<width_;j++){
switch(theMaze_[i][j]){
case WALL: cout << 'X'; break;
case EMPTY: cout << ' '; break;
case MARKED: cout << 'o'; break;
}
}
cout << endl;
}
}