Basically I am making an adventure game in a 2D array, I would like the character to move around fighting monsters and have that represented in a 2D array. I have the movement done and I have just figured out how to detect if there is another character on the players coordinates. Right now my problem is because I've used rand() to determine where each of my monsters are every time my map updates the monsters also move, I understand why this is happening but the only way I can think of to fix this is to put the randomisation of the monsters coordinates into main or somewhere that only gets called once.

i have tried doing that by making a structure and a class which should only make one randomised coordinate per item in the array.

Code:
struct Character
{

	int X;
	int Y;

	int health;
	string name;

	Character()
	{
		health = 99999;
		name = "ChangeMe";
	}
}; 



class Monster
{
	public:
	Character _Character[AMMOUNT_OF_MONSTERS];
	string type;

	Monster()
	{
		for (int howManyMonsters = 0; howManyMonsters < AMMOUNT_OF_MONSTERS; howManyMonsters++)
		{
			_Character[howManyMonsters].X = rand() % GRID_SIZE;//will randomize each monsters X position
			_Character[howManyMonsters].Y = rand() % GRID_SIZE;//will randomize each monsters Y position
		}
	}
};


for (howManyMonsters = 0; howManyMonsters < AMMOUNT_OF_MONSTERS; howManyMonsters++) // to create the ammount of monsters i want
	{
		if (map[x][y] != grid && map[x][y] != map[playerX][playerY])
		{
			map[_Monster._Character[howManyMonsters].X][_Monster._Character[howManyMonsters].Y] = 'M';
		}	
	}

Thank you,

Michael Burdge



full code:
the original code for the Monster is the same as the church and survivor, i have changed it just trying out new things.

Code:
// My Game For C++ Neil.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <ctime>
#include <iostream>

#define GRID_SIZE 29 //The Grid size is GRID_SIZE by GRID_SIZE
#define AMMOUNT_OF_MONSTERS 17
#define AMMOUNT_OF_CHURCHES 1//10
#define AMMOUNT_OF_SURVIVORS 1//6
using namespace std;

int NewMap(int playerX, int playerY);
//int ContinueMap(int moveDistance, int direction);
void FightMonster();
void HealAtChurch();
void RecruitSurvivor();


struct Character
{

	int X;
	int Y;

	int health;
	string name;

	Character()
	{
		health = 99999;
		name = "ChangeMe";
	}
}; 



class Monster
{
	public:
	Character _Character[AMMOUNT_OF_MONSTERS];
	string type;

	Monster()
	{
		for (int howManyMonsters = 0; howManyMonsters < AMMOUNT_OF_MONSTERS; howManyMonsters++)
		{
			_Character[howManyMonsters].X = rand() % GRID_SIZE;//will randomize each monsters X position
			_Character[howManyMonsters].Y = rand() % GRID_SIZE;//will randomize each monsters Y position
		}
	}
};


int main()
{
	int playerX;
	int playerY;

	bool canContinue;

	playerX = GRID_SIZE / 2;
	playerY = GRID_SIZE / 2;

	int direction;
	char directionCHR;
	int moveDistance;
	time_t t;

	srand((unsigned)time(&t));

	cout << "The Aim Is To Kill" << endl;
	cout << "A = Adventurer: You are the Adventurer" << endl;
	cout << "M = Monsters: Fight Monsters" << endl;
	cout << "C = Churches: Heal After Fighting Monsters" << endl;
	cout << "S = Survivors: Recruit People To Help Fight Monsters" << endl;

	NewMap(playerX, playerY);

	for (int i = 0; i < 5; i++)
	{
		do
		{
			do
			{
				cout << "Which Direction Would You Like To Move?" << endl << "N for North, E for East, S for South, W for West" << endl;

				cin >> directionCHR;

				if (directionCHR == 'N' || directionCHR == 'n')
				{
					direction = 0;
				}
				else if (directionCHR == 'E' || directionCHR == 'e')
				{
					direction = 1;
				}
				else if (directionCHR == 'S' || directionCHR == 's')
				{
					direction = 2;
				}
				else if (directionCHR == 'W' || directionCHR == 'w')
				{
					direction = 3;
				}
			} while (directionCHR != 'N' && directionCHR != 'n' && directionCHR != 'E' && directionCHR != 'e' && directionCHR != 'S' && directionCHR != 's' && directionCHR != 'W' && directionCHR != 'w');

		
			canContinue = true;

			cout << "How Far Would You Like To Move?" << endl;

			cin >> moveDistance;

			if (direction == 0) // the reason why i did it like this is because originally i had the movement in the function along with the generation of the map.
			{
				playerX -= moveDistance;
				if (playerX < 0)
				{
					cout << "out of bounds" << endl;
					canContinue = false;
					playerX += moveDistance;
				}
			}
			else if (direction == 1)
			{
				playerY += moveDistance;
				if (playerY > GRID_SIZE)
				{
					cout << "out of bounds" << endl;
					canContinue = false;
					playerY -= moveDistance;
				}
			}
			else if (direction == 2)
			{
				playerX += moveDistance;
				if (playerX > GRID_SIZE)
				{
					cout << "out of bounds" << endl;
					canContinue = false;
					playerX -= moveDistance;
				}
			}
			else if (direction == 3)
			{
				playerY -= moveDistance;
				if (playerY < 0)
				{
					cout << "out of bounds" << endl;
					canContinue = false;
					playerY += moveDistance;
				}
			}
		} while (!canContinue);

		NewMap(playerX, playerY);

	}
	return 0;
}

int NewMap(int playerX, int playerY)
{
	Monster _Monster;


	char map[GRID_SIZE][GRID_SIZE];
	char grid = 176; //what ive chosen as the map ground, i chose this because it looks good as a background

	int x; //Map X
	int y; //Map Y


	int howManyMonsters; //How many Monsters on the map
	int monsterX; //Monsters X
	int monsterY; //Monsters Y


	//int howManyChurches; //How many Churches on the map
	//int churchX; //Church X
	//int churchY; //Church Y

	//int howManySurvivors; //How many Survivors on the map
	//int survivorX; //Survivor X
	//int survivorY; //Survivor Y




	for (x = 0; x < GRID_SIZE; x++)
	{
		for (y = 0; y < GRID_SIZE; y++)
		{
			map[x][y] = grid; //chooses what the map is
			map[playerX][playerY] = 'A';
		}
	}

	for (howManyMonsters = 0; howManyMonsters < AMMOUNT_OF_MONSTERS; howManyMonsters++) // to create the ammount of monsters i want
	{
		if (map[x][y] != grid && map[x][y] != map[playerX][playerY])
		{
			map[_Monster._Character[howManyMonsters].X][_Monster._Character[howManyMonsters].Y] = 'M';
		}
		//do // to randomize the coordinates of the monsters so they arent overwriting anything.
		//{
		//	x = rand() % GRID_SIZE;
		//	y = rand() % GRID_SIZE;


		//	_Monster._Character[spawnMonsters].monsterX;
		//	_Monster._Character[spawnMonsters].monsterY;
		//	map[hereMonsterX][hereMonsterY] = 'M';// place monsters at map[monsterX][monsterY]

		//} while (map[x][y] != grid && map[x][y] != map[playerX][playerY]); // this is so the monster wont replace the adventurer with monsters
		
	}
	//for (howManyChurches = 0; howManyChurches < AMMOUNT_OF_CHURCHES; howManyChurches++)
	//{
	//	do
	//	{
	//		x = rand() % GRID_SIZE;
	//		y = rand() % GRID_SIZE;
	//		churchX = rand() % GRID_SIZE; //will randomize each church X position
	//		churchY = rand() % GRID_SIZE; //will randomize each church Y position
	//	} while (map[x][y] != grid && map[x][y] != 'M' && map[x][y] != map[playerX][playerY]); // so we dont replace the adventurer or monsters with churches
	//	map[churchX][churchY] = 'C';

	//}

	//for (howManySurvivors = 0; howManySurvivors < AMMOUNT_OF_SURVIVORS; howManySurvivors++)
	//{
	//	do
	//	{
	//		x = rand() % GRID_SIZE;
	//		y = rand() % GRID_SIZE;
	//		survivorX = rand() % GRID_SIZE; //will randomize each survivor X position
	//		survivorY = rand() % GRID_SIZE; //will randomize each survivor Y position
	//	} while (map[x][y] != grid && map[x][y] != 'M' && map[x][y] != 'C' && map[x][y] != map[playerX][playerY]); //so we dont replace the adventurer, monsters or churches with survivors
	//	map[survivorX][survivorY] = 'S';

	//}

	for (x = 0; x < GRID_SIZE; x++)//this here makes the spacing between each background character, i made a space between them because 
	{
		for (y = 0; y < GRID_SIZE; y++)
		{
			cout << map[x][y] << " ";
		}
		cout << endl;
	}

	for (x = 0; x < GRID_SIZE; x++)
	{
		for (y = 0; y < GRID_SIZE; y++)
		{
			if (map[playerX][playerY] == char('M'))
			{
				FightMonster(); //runs the function to fight a monster.
				map[playerX][playerY] = 'A'; // places the Adventurer aka the player in that position
			}
			else if (map[playerX][playerY] == char('C'))
			{
				HealAtChurch(); //runs the function to heal at the churche.
				map[playerX][playerY] = 'A'; // places the Adventurer aka the player in that position
			}
			else if (map[playerX][playerY] == char('S'))
			{
				RecruitSurvivor(); // runs the function to recruit a survivor;
				map[playerX][playerY] = 'A'; // places the Adventurer aka the player in that position
			}
			else
			{
				map[playerX][playerY] = 'A'; // places the Adventurer aka the player in that position
			}
		}
	}
return 0;
}




void FightMonster()
{
	cout << "FIGHT A MONSTER" << endl;
}

void HealAtChurch()
{
	cout << "HEAL AT A CHURCH" << endl;
}

void RecruitSurvivor()
{
	cout << "RECRUIT A SURVIVOR" << endl;
}