My bools appear as 205 and 105

I have a dynamic array [bool] called terrain. I was wondering why my code doesn't work until I had to cout<<terrain[y][x], which returned 205 when false and 105 when true.
I want my code to use
if (terrain[y][x]==false)
instead of
if (terrain[y][x]==205)
How do I do this?
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
int main()
{
	time_t sec;
	time(&sec);
	srand((unsigned int) sec);


	int map_width,map_height,map_density,map_stepcounter=0;
	cout<<"Width of the maze?\n";
	cin>>map_width;
	map_width+=2;
	cout<<"Height of the maze?\n";
	cin>>map_height;
	map_height+=2;
	cout<<"Density percent of maze? 0-100\n";
	cin>>map_density;

	bool ** terrain = new bool* [map_height];
	for (int i=0;i<map_height;i++)
	{
		terrain[i]=new bool [map_width];
	}

	generate_maze(terrain,map_width,map_height,map_density);
clrscr();

	for (int y=0;y<map_height;y++)
		for (int x=0;x<map_width;x++)
		{
			gotoxy(x,y);
			if (terrain[y][x]==true) cout<<"#";
			else cout<<".";
		}
	COORD MOUSE;
	MOUSE.X=1;
	MOUSE.Y=5;
	do
	{
		map_stepcounter++;
		gotoxy(0,0);
		cout<<"COUNTERS "<<map_stepcounter;
		if (terrain[MOUSE.Y][MOUSE.X+1]==205)
			MOUSE.X++;
		else if (terrain[MOUSE.Y-1][MOUSE.X]==205)
			MOUSE.Y--;
		else if (terrain[MOUSE.Y+1][MOUSE.X]==205)
			MOUSE.Y++;
		gotoxy(MOUSE.X,MOUSE.Y);
		delay(1000);
	}
	while (MOUSE.X<23);
}

You allocate space for the bool arrays, but you never set anything explicitly to true/false. That is my best guess. Also, that program crashes for me, even if I fix it to work with true/false. I'm guessing it is because the program is trying access the array out of its intended boundaries. How to fix it? I have no idea. I'm guessing it is a problem with the +/- 1 parts. :)
Sorry, I forgot to add a bunch of stuff, and I can't add because I lost my source
But I did set them explicitely as true and false in map generation.
What's weird is that, when I said terrain[y][x]==true.

The things that are missing are includes, as well as the scripts
generate_maze(), clscr(), and gotoxy()
Topic archived. No new replies allowed.