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 105 106 107 108 109 110 111 112 113 114
|
#include <iostream>
#include <fstream>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
class Cell{
public:
Cell(){}
Cell(bool a,bool b,bool c,bool d);
Cell(Cell ©);
bool getTop(){ return top; }
bool getBottom(){ return bottom; }
bool getRight(){return right;}
bool getLeft(){return left;}
bool getVisited(){return visited;}
bool getPrevCell(){return prevCell;}
char getData(){return data;}
void setTop(bool a ){top = a;}
void setBottom(bool b){bottom = b;}
void setRight(bool c){right = c;}
void setLeft(bool d){left = d;}
void setVisited(bool e){ visited = e; }
void setPrevCell(bool f){prevCell = f;}
void setData();
private:
bool top, bottom, right, left, visited, prevCell;
char data;
};
Cell::Cell(bool a,bool b,bool c,bool d){
top = a;
bottom = b;
right = c;
left = d;
}
Cell::Cell(Cell ©){
top = copy.top;
bottom = copy.bottom;
right = copy.right;
left = copy.left;
}
class Maze{
Maze(){}
Maze(Cell m, Cell n);
private:
vector<Cell> *maze;
};
Maze::Maze(Cell m, Cell n){
*maze(m, n);
}
int main()
{
ifstream in("maze.txt");
char str1[100],str2[100],str3[100];
in.getline(str1, 100);
in.getline(str2, 100);
in.getline(str3, 100);
int line = 1, cell = 1; //variables are used for students to understand the reading structure
while (!in.eof())
{
cell = 1;
cout << "line " << line << endl;
int i = 0;
bool top, down, right, left; // to trace walls
top = down = right = left = false;
int j = 0, k = 1; // j for str2, k for str3
Cell *c;
while (i < strlen(str1)-1)
{
top = down = right = left = false;
if (str1[i] == '+') i++; // new cell begins
else if (str1[i] == '-') top = true; // wall above
else if (str1[i] == ' ') top = false;
//else error ...
i = i + 3;
if (str2[j] == '|') left = true; // left wall
else if (str2[j] == ' ') left = false;
//else error ...
j = j + 4;
if (str2[j] == '|') right = true; // right wall
else if (str2[j] == ' ') right = false;
//else error ...
if (str3[k] == '-') down = true; // wall below
else if (str3[k] == ' ') down = false;
//else error ...
k = k + 4;
cout << "cell = " << cell++ << endl;
cout << "Top : " << top << "\t";
cout << "down : " << down << endl;
cout << "right : " << right << "\t";
cout << "left : " << left << endl;
cout << endl << endl;
c= new Cell(top, down, right, left);
}
strcpy(str1, str3);
cout << str1 << endl;
in.getline(str2, 100);
in.getline(str3, 100);
line++;
}
return 0;
}
|