moving a character randomly

Hi, so I've been trying to research on how to make an character move randomly using srand and for the life of me I cannot find anything useful on the internet (2 hours of searching) I'm a very new coder so idea's to try just doesn't pop in my head yet, so I've kind of hit a block wall.

I want my "Z" characters to move randomly around my grid any assistance would be great, I don't want the code written completely out for me, but some tips on what I need to write why i need to write it so I fully understand what I am doing would be great. Thanks!

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
#include <iostream>
#include <windows.h>
#include <time.h>

using namespace std;

char Map[30][53] = {

"#--------------------------------------------------#",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"|                                                  |",
"#--------------------------------------------------#" };



bool running = true;
int Gamespeed = 100;

int main()
{
	srand(time(0));

	int spawn = 0, spawn2 = 0, spawn3 = 0;

	while (spawn < 6)
	{
		int p1 = (rand() % 16) + 1;
		int p2 = (rand() % 50) + 1;

		if (Map[p1][p2] = ' ')
		{
			Map[p1][p2] = 'Z';
			spawn++;
		}
	}
	while (spawn2 < 6)
	{
		int p3 = (rand() % 16) + 1;
		int p4 = (rand() % 50) + 1;

		if (Map[p3][p4] = ' ')
		{
			Map[p3][p4] = 'O';
			spawn2++;
		}
	}

	int p5 = (rand() % 16) + 1;
	int p6 = (rand() % 50) + 1;
	Map[p5][p6] = 'M';

	while (running == true)
	{
		system("cls");
		for (int y = 0; y < 18; y++)
		{
			cout << Map[y] << endl;
		}
		for (int y = 0; y < 18; y++)
		{
			for (int x = 0; x < 52; x++)
			{
				

				switch (Map[y][x])
				{
				case 'M':
				{
					if (GetAsyncKeyState(VK_UP) != 0)
					{
						int y2 = (y - 1);

						switch (Map[y2][x])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							y -= 1;
							Map[y2][x] = 'M';
						}break;
						}
					}

					if (GetAsyncKeyState(VK_DOWN) != 0)
					{
						int y2 = (y + 1);

						switch (Map[y2][x])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							y += 1;
							Map[y2][x] = 'M';
						}break;
						}
					}

					if (GetAsyncKeyState(VK_RIGHT) != 0)
					{
						int x2 = (x + 1);

						switch (Map[y][x2])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							x += 1;
							Map[y][x2] = 'M';
						}break;
						}
					}
					if (GetAsyncKeyState(VK_LEFT) != 0)
					{
						int x2 = (x - 1);

						switch (Map[y][x2])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							x -= 1;
							Map[y][x2] = 'M';
						}
						}
					}
				}
				}
			}
		}
	}

	while (running)
	{
		system("cls");
		for (int y = 0; y < 18; y++)
		{
			cout << Map[y] << endl;
		}
		for (int y = 0; y < 18; y++)
		{
			for (int x = 0; x < 52; x++)
			{
				switch ( rand() %4 )
				{
				case 'Z':;
					if (Map[y][x])
				}
			}
		}
	}

	return 0;
}


As you can see in the code, I've got my man or "M" if you will to move on my command left, right, down and up and I've got them all to randomly spawn within the grid. it's just getting the zombies to randomly move is the tricky part.
Then these lines probably aren't what you really want (or they don't make sense):

1
2
if (Map[p1][p2] = ' ')
if (Map[p3][p4] = ' ')


with imho correct settings (for example -Werror -Wextra Flags), that won't even compile.

You could check if a field is 'Z', then create a new x and y position, which are

x+1 or x or x-1
y+1 or y or y-1


if you don't want to allow diagonal movement, make sure that one of the two stays the same.

Then assign a space to where the 'Z' used to be, and put a 'Z' at your new position

--------------------
|    | y-1  |     |
|x-1 |  Z   | x+1 |
|    | y+1  |     |


@bugbyte

Uhmm, okey I see where you are coming from with the if map statements, but it currently working fine for me, but I will change just for being 100% accurate with my coding, and if I'm honest, I am fine with it going diagonally even tho I didn't know it could, and thank you for explaining how not to allow it to go diagonal if in the future I do something like this again
Run this, you'll see what happens:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main() {
    using namespace std;

    char ch = 'A';
    cout << "ch: " << ch << '\n';
    if (ch == 'B') cout << "'A' == 'B'\n";
    if (ch = 'B') {
        cout << "ch: " << ch << '\n';
        ch = 'C';
        cout <<  "ch: " << ch << '\n';
    }
}

I had to compile without -Werror
Last edited on
by itself? cus when i did that, I just got errors?
what errors?
I didn't read them all but there was alot.... I'm using visual studios 2013 if that helps, but if i may ask what does the code do, and how does it relate to what i originally asked help for?
Bump
@Collwyr

Here's a small program I had written, and I added to it, 3 Zombie characters that each move randomly. It's not a polished game, but should give you enough ideas on how to program your game. If you have any questions, please ask..

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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include <iostream>
#include <conio.h>
#include <ctime>
#include <string>
#include <Windows.h>

using namespace std;

void Draw(int, int, int, int, int, int);
void gotoXY(int, int);
void gotoXY(int, int, string);
void pause(unsigned int milliseconds);

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

#define ENTER 13
#define UP 72
#define LEFT 75
#define RIGHT 77
#define DOWN 80

int main()
{
	int x, y, i, ch,z;
	
	int Zombie[3][2];
	Zombie[0][0] = { 25 };
	Zombie[0][1] = { 12 };
	Zombie[1][0] = { 16 };
	Zombie[1][1] = { 15 };
	Zombie[2][0] = { 27 };
	Zombie[2][1] = { 17 };
	
	x = 20;
	y = 10;
	char yn = 'y';
	int wins = false;
	string rub(5, '\xB0');
	gotoXY(10, 6, "To move, use the arrow keys.");
	gotoXY(10, 7, "'Enter' to change '\x01' to '\x02'");
	Draw(1, 1, 1, 78, 23, 1);
	Draw(2, 15, 9, 25, 12, 1);
		
	for (z = 0; z<3; z++)
		gotoXY(Zombie[z][0], Zombie[z][1], "Z");
	
	do
	{
		for (int a = 0; a < 3; a++)
		{
			i = rand() % 4;
			gotoXY(Zombie[a][0], Zombie[a][1], " ");
			if (i == 0 && Zombie[a][0] - 1 > 15)
				Zombie[a][0] -= 1;
			if (i == 2 && Zombie[a][0] + 1 < 39)
				Zombie[a][0] += 1;
			if (i == 1 && Zombie[a][1] - 1 > 10)
				Zombie[a][1] -= 1;
			if (i == 3 && Zombie[a][1] + 1 < 20)
				Zombie[a][1] += 1;
			gotoXY(Zombie[a][0], Zombie[a][1], "Z");
			if (Zombie[a][0] == x && Zombie[a][1] == y)
			{
				gotoXY(10, 5, "A Zombie Gotcha!!");
				wins = true;
			}
		}
		gotoXY(22, 14, "H");
		if (x == 22 && y == 14)
		{
			gotoXY(19, 12, "Yippee!!");
			gotoXY(18, 13, "I'm HOME!!");
			for (i = 0; i<8; i++)
			{
				gotoXY(x, y, "\x02");
				pause(140);
				gotoXY(x, y, "\x01");
				pause(140);
			}
			wins = true;
		}
		gotoXY(10, 22);
		cout << "The '\x01' is at column " << x << " row " << y - 9 << " ";
		gotoXY(x, y, "\x01");

		ch = _getch();
		switch (ch)
		{
			
			//Movement by pressing the arrow keys
		case LEFT:
		{
			if (x - 1>15)
			{
				gotoXY(x, y, " ");
				x--;
			}
			else
			{
				gotoXY(x - 6, y, "Ouch!");
				pause(500);
				gotoXY(x - 6, y, "     ");
			}
			break;
		}
		case RIGHT:
		{
			if (x + 1< 39)
			{
				gotoXY(x, y, " ");
				x++;
			}
			else
			{
				gotoXY(x + 2, y, "Ouch!");
				pause(500);
				gotoXY(x + 2, y, "\xB0    ");
			}
			break;
		}
		case UP:
		{
			if (y - 1>9)
			{
				gotoXY(x, y, " ");
				y--;
			}
			else
			{
				gotoXY(x - 2, y - 2, "Ouch!");
				pause(500);
				gotoXY(x - 2, y - 2, "     ");
			}
			break;
		}
		case DOWN:
		{
			if (y + 1<20)
			{
				gotoXY(x, y, " ");
				y++;
			}
			else
			{
				gotoXY(x - 2, y + 2, "Ouch!");
				pause(500);
				if (x-15<3)
				{
					gotoXY(14, y + 2, "  ");
					cout << rub;
				}
				else
				gotoXY(x - 2, y + 2, rub);
			}
			break;
		}
		case ENTER:
		{
			gotoXY(x, y, "\x02");
			pause(800);
		}
		pause(100);
		break;
		}
	} while (!wins);
	gotoXY(10, 22);
	return 0;
}

void Draw(int style, int col, int row, int length, int height, int shadow)
{
	// Draws a 1 or 2 line box 
	int a;
	style--;
	//style=b*6;
	char box[2][6];
	box[0][0] = '\xDA';
	box[0][1] = '\xBF';
	box[0][2] = '\xC0';
	box[0][3] = '\xD9';
	box[0][4] = '\xB3';
	box[0][5] = '\xC4';
	box[1][0] = '\xC9';
	box[1][1] = '\xBB';
	box[1][2] = '\xC8';
	box[1][3] = '\xBC';
	box[1][4] = '\xBA';
	box[1][5] = '\xCD';
	char tl, tr, bl, br, side, edge;
	tl = box[style][0];
	tr = box[style][1];
	bl = box[style][2];
	br = box[style][3];
	side = box[style][4];
	edge = box[style][5];

	string Line(length - 2, edge);
	string Shadow(length, '\xB0');
	gotoXY(col, row);
	cout << tl << Line << tr;
	for (a = 1; a <height - 1; a++)
	{
		gotoXY(col, row + a);
		cout << side;
		gotoXY(col + length - 1, row + a);
		cout << side;
		if (shadow)
			cout << "\xB0";
	}
	gotoXY(col, (height + row) - 1);
	cout << bl << Line << br;
	if (shadow)
	{
		cout << "\xB0";
		gotoXY(col + 1, row + height, Shadow);
	}
}

void gotoXY(int x, int y)
{
	CursorPosition.X = x;
	CursorPosition.Y = y;
	SetConsoleCursorPosition(console, CursorPosition);
}

void gotoXY(int x, int y, string text)
{
	CursorPosition.X = x;
	CursorPosition.Y = y;
	SetConsoleCursorPosition(console, CursorPosition);
	cout << text;
}

void pause(unsigned int milliseconds)
{
	time_t final = milliseconds + clock();
	while (milliseconds < final)
	{
		milliseconds = clock();
	}
}
Last edited on
I didn't read them all but there was alot.... I'm using visual studios 2013 if that helps, but if i may ask what does the code do, and how does it relate to what i originally asked help for?

Well, we're still stuck in the same place. Copy some of the errors and paste them here. Or read them, and determine the generel type of error and explain.
The program shows why '=' in if-statements is almost always wrong, and it's effect compared to the usually corret '=='.

btw, I just tried your game. I think you missed srand in the new version?
Thought it was pretty cool. I mean, I'm not sure about the software design, but it's a nice little game ;)
Last edited on
@bugbyte

I think you missed srand in the new version?

I didn't bother with it, since the game was only to show Collwyr how to move each of the zombies, randomly. It didn't really matter if they moved the same each time the program is run.

Glad you liked the small game. I may expand on it a bit. Add color, bigger playing field, ask how tough the game should be, from the user, (IE: how many zombies on the playing field), and add a few walls to the playing field
Hey guys, so I've been rewriting a bit of the game because I felt the free roam thing was kinda to complicated for me and made it a move by move sort of like a text based game, I got my screen going without flickering and loads up after a new move from the user input but i'm having huge problems trying to get the user input working properly, some of it just isn't showing up and other bits is working incorrectly, for example I want to make it so when i press the Up arrow key I want it to move up, but it doesn't work I have to press "w" then enter which does nothing then I have to press the arrrow up key which shows a "W" but then when i press enter after that it works? and "a" "s" just doesn't work.

not sure where I have gone wrong? any help would be great

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
#include <iostream>
#include <windows.h>
#include <time.h>
#include "Console.h"

using namespace std;

char Map[30][53] = {

	"#--------------------------------------------------#",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"|                                                  |",
	"#--------------------------------------------------#" };


int main()
{

	bool running = true;
	int Gamespeed = 100;

	srand(time(NULL));

	enum Direction : char
	{
		UP, DOWN, LEFT, RIGHT
	};

	int spawn = 0, spawn2 = 0, spawn3 = 0, y2 = 0;

	while (spawn < 6)
	{
		int p1 = (rand() % 16) + 1;
		int p2 = (rand() % 50) + 1;

		if (Map[p1][p2] == ' ')
		{
			Map[p1][p2] = 'Z';
			spawn++;
		}
	}
	while (spawn2 < 6)
	{
		int p3 = (rand() % 16) + 1;
		int p4 = (rand() % 50) + 1;

		if (Map[p3][p4] == ' ')
		{
			Map[p3][p4] = 'O';
			spawn2++;
		}
	}

	int p5 = (rand() % 16) + 1;
	int p6 = (rand() % 50) + 1;
	Map[p5][p6] = 'M';


	while (running == true)
	{
		//system("cls");

		Console::clear();
		char input;


		for (int y = 0; y < 30; y++)
		{
			for (int x = 0; x < 53; x++)
			{
				cout << Map[y][x];
			}
			cout << endl;
		}
		for (int y = 0; y < 30; y++)
		{
			for (int x = 0; x < 53; x++)
			{
				switch (Map[y][x])
				{
				case 'M':
				{
							cin >> input;
							if (input == 0, GetAsyncKeyState(VK_UP))
							{
								int y2 = (y - 1);

								switch (Map[y2][x])
								{
								case ' ':
								{
											Map[y][x] = ' ';
											y -= 1;
											Map[y2][x] = 'M';
								}break;
								}
							}

							if (input == 0, GetAsyncKeyState(VK_DOWN))
							{
								int y2 = (y + 1);

								switch (Map[y2][x])
								{
								case ' ':
								{
											Map[y][x] = ' ';
											y += 1;
											Map[y2][x] = 'M';
								}break;
								}
							}

							if (input == 0, GetAsyncKeyState(VK_RIGHT))
							{
								int x2 = (x + 1);

								switch (Map[y][x2])
								{
								case ' ':
								{
											Map[y][x] = ' ';
											x += 1;
											Map[y][x2] = 'M';
								}break;
								}
							}
							if (input == 0, GetAsyncKeyState(VK_LEFT))
							{
								int x2 = (x - 1);

								switch (Map[y][x2])
								{
								case ' ':
								{
											Map[y][x] = ' ';
											x -= 1;
											Map[y][x2] = 'M';
											break;
								}
								}
							}
				}
				}


				switch (Map[y][x])
				{
				case 'Z':

					static_cast<Direction>(rand() % 4);
					break;

				case 0:
					(Map[y][x], rand() % (UP));
					break;
				}
			}
			cout << endl;
		}
	}
	system("pause");
	return 0;
}


Don't worry about the zombie bit, i haven't finished that, but could use some help with that also.
@Update I figured out what was wrong, I gave up trying to use the keys so I decided to go with good ol' fashion "W,A,S,D" which was simple putting in

if (input == 0, GetAsyncKeyState(0x57)) that instead of
if (input == 0, GetAsyncKeyState(VK_UP))

Which I'm glad means I've solved that. now to the zombie part...

OKey, as you can see I have the the zombies directions in a rand to make the directions they move randomly, i'm struggling to type in the correct code for once a direction has been picked, to move one spot in that direction.

I was hoping it would be something as simple as

1
2
3
4
5
6
7
8
9
10
11
switch (Map[y][x])
				{
				case 'Z':

					static_cast<Direction>(rand() % 4);
					break;

				case 0:
					(Map[y][x], rand() % (UP));
					break;
				}


but alas, It is not. any help would be amazing!
Last edited on
Can someone explain to me what is happening to my code, I tried making my zombies move randomly by themselves, now for some reason when i run the program, my enter box is miles down the screen and when i put in a input to move my "M" the game just randomly ends but i cannot see the problem because the input line is miles down the console... it wasn't like this before i entered in my lines of code for the zombie, so I don't understand why its doing it?

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
#include <iostream>
#include <windows.h>
#include <time.h>
#include "Console.h"

using namespace std;

char Map[30][53] = {

	"####################################################",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"#                                                  #",
	"####################################################" };


int main()
{

	bool running = true;
	int Gamespeed = 100;

	srand(time(NULL));

	enum Direction : char
	{
		UP, DOWN, LEFT, RIGHT
	};

	int spawn = 0, spawn2 = 0, spawn3 = 0, y2 = 0, i = 0, Zombie = 0, randNum = 0;

	while (spawn < 6)
	{
		int p1 = (rand() % 16) + 1;
		int p2 = (rand() % 50) + 1;

		if (Map[p1][p2] == ' ')
		{
			Map[p1][p2] = 'Z';
			spawn++;
		}
	}
	while (spawn2 < 6)
	{
		int p3 = (rand() % 16) + 1;
		int p4 = (rand() % 50) + 1;

		if (Map[p3][p4] == ' ')
		{
			Map[p3][p4] = 'O';
			spawn2++;
		}
	}

	int p5 = (rand() % 16) + 1;
	int p6 = (rand() % 50) + 1;
	Map[p5][p6] = 'M';


	while (running == true)
	{

		Console::clear();
		char input;


		for (int y = 0; y < 30; y++)
		{
			for (int x = 0; x < 53; x++)
			{
				cout << Map[y][x];
			}
			cout << endl;
		}
		for (int y = 0; y < 30; y++)
		{
			for (int x = 0; x < 53; x++)
			{
				switch (Map[y][x])
				{
				case 'M':
				{
					cin >> input;
					if (input == 0, GetAsyncKeyState(0x57))
					{
						int y2 = (y - 1);

						switch (Map[y2][x])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							y -= 1;
							Map[y2][x] = 'M';
						}break;
						}
					}

					if (input == 0, GetAsyncKeyState(0x53))
					{
						int y2 = (y + 1);

						switch (Map[y2][x])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							y += 1;
							Map[y2][x] = 'M';
						}break;
						}
					}

					if (input == 0, GetAsyncKeyState(0x44))
					{
						int x2 = (x + 1);

						switch (Map[y][x2])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							x += 1;
							Map[y][x2] = 'M';
						}break;
						}
					}
					if (input == 0, GetAsyncKeyState(0x41))
					{
						int x2 = (x - 1);

						switch (Map[y][x2])
						{
						case ' ':
						{
							Map[y][x] = ' ';
							x -= 1;
							Map[y][x2] = 'M';
							break;
						}
						}
					}
				}
				}



				switch (Map[y][x])
				{
				case 'Z':
					randNum = rand() % 4 + 1;

					switch (randNum){


						case 1:
							if (Map[y - 1][x] != '#' && Map[y - 1][x] != 'Z'){
	
								Map[y][x] = ' ';
								Map[y - 1][x] = 'Z';
							}
							break;
						case 2:
							if (Map[y][x + 1] != '#' && Map[y][x + 1] != 'Z'){
	
								Map[y][x] = ' ';
								Map[y][x + 1] = 'Z';
							}
							break;
						case 3:
							if (Map[y + 1][x] != '#' && Map[y + 1][x] != 'Z'){
	
								Map[y][x] = ' ';
								Map[y + 1][x] = 'Z';
							}
							break;
						case 4:
							if (Map[y][x - 1] != '#' && Map[y][x - 1] != 'Z'){
	
								Map[y][x] = ' ';
								Map[y][x - 1] = 'Z';
							}
							break;
					}
							
				}
				cout << endl;
			}
		}
		system("pause");
		return 0;
	}
}
Topic archived. No new replies allowed.