help please

[/output]Write your question here.
I cant figure out the errors I have taken them off and redone them. I am supposed to make a number generated maze in order for the computer to find its way out to the edge if it gets trapped it tells you you are trapped if you make it out you win. I have done this in sections, The maze part works great and yes its supposed to not have lines. but i cant get the rest to work. Please help I have been at this for 2 weeks

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
  #include <iostream>
#include <ctime>
#include <string>
#include <cstdlib>
#include <Windows.h>   //Holds the random number and GetTickCount fns

using namespace std;

int main ()
{
	char ans;
	char cMaze[11][11];
	do{
	for(int i=0; i<11; i++)
	{
		for(int j=0; j<11; j++)
		{
			cMaze[i][j] = ' ';
		}
	}
	cMaze[5][5] = 'x';
			cout << "  0 1 2 3 4 5 6 7 8 9 10" << endl;
	for(int i=0; i<11; i++)
	{
		cout << i << " ";
				for(int j=0; j<11; j++)
		{
			cout << cMaze[i][j] << " ";

srand(GetTickCount());    //Seed the random number generator



void moveup(){
    history[moves]="Up";
    locationy--;
    maze[locationx][locationy]='*';
    moves++;
}

void movedown(){
    history[moves]="Down";
    locationy=locationy+1;
    maze[locationx][locationy]='*';
    moves++;
}

void moveleft(){
    history[moves]="Left";
    locationx=locationx-1;
    maze[locationx][locationy]='*';
    moves++;
}

void moveright(){
    history[moves]="Right";
    locationx++;
    maze[locationx][locationy]='*';
    moves++;
}


bool canmoveup(){
    if (history[moves-1]=="Down"){
        return false;
    }
    int newy=locationy-1;
    if(maze[locationx][newy]=='O'){
        return true;
    }
    else{
        return false;
    }
}

bool canmovedown(){
    if (history[moves-1]=="Up"){
        return false;
    }
    int newy=locationy+1;
    if(maze[locationx][newy]=='O'){
        return true;
    }
    else{
        return false;
    }
}

bool canmoveleft(){
    if (history[moves-1]=="Right"){
        return false;
    }
    int newx=locationx-1;
    if(maze[newx][locationy]=='O'){
        return true;
    }
    else{
        return false;
    }
}

bool canmoveright(){
    if (history[moves-1]=="Left"){
        return false;
    }
    int newx=locationx+1;
    if(maze[newx][locationy]=='O'){
        return true;
    }
    else{
        return false;
    }
}

void printAll(){

    for (int i=0;i<6;i++){
        cout<<endl;
        for(int x=0;x<6;x++){
            cout<<maze[x][i]<<' ';
        }
    }
}

bool impossible(){
    if (maze[1][1]=='X'){
        cout<<endl<<"The maze cheated!  The Entrance is Blocked!"<<endl;
        return true;
    }
    if (maze[6][6]=='X'){
        cout<<endl<<"The maze cheated!  The Exit is Blocked!"<<endl;
        return true;
    }

return false;
}

bool end(){

    if (locationx==20 && locationy==20){
        return true;
    }
    if (moves!=0 && (locationx==1 && locationy==1)){
            return true;
    }
    return false;
}

int getmoves(){
return moves;
}

string gethistory(int movenumber){
    return history[movenumber];
}
};


int main(){

    Maze gameboard;
    gameboard.printmaze();
    bool ended=false;

    if (gameboard.impossible()){
        return 0;
    }
        while (!ended){
            if(gameboard.end()){
                cout<<endl<<"You got out!"<<endl;
                ended=true;
                continue;
            }

            if (gameboard.canmoveright()){
                gameboard.moveright();
                continue;
            }
            if(gameboard.end()){
                cout<<endl<<"You got out!"<<endl;
                ended=true;
                continue;
            }
            if(gameboard.canmovedown()){
                gameboard.movedown();
                continue;
            }
            if(gameboard.end()){
                cout<<endl<<"You got out!"<<endl;
                ended=true;
                continue;
            }
            if (gameboard.canmoveleft()){
                gameboard.moveleft();
                continue;
            }
            if(gameboard.end()){
                cout<<endl<<"You got out!"<<endl;
                ended=true;
                continue;
            }
            if (gameboard.canmoveup()){
                gameboard.moveup();
                continue;
            }
            if(gameboard.end()){
                cout<<endl<<"You got out!"<<endl;
                ended=true;
                continue;
            }
                cout<<endl<<"Escape is Impossible!"<<endl;
                ended=true;
        }
    cout<<endl<<endl;
    for(int i=0;i<gameboard.getmoves();i++){
        cout<<gameboard.gethistory(i)<<endl;
    }
    cout<<endl;
    gameboard.printAll();
    cout<<endl;
}     
		
	}	
	
	cout << "would you like to play again?: ";
	cin >> ans;
	}while(ans == 'y');
}
Last edited on
Topic archived. No new replies allowed.