Maze game error

Hey, I'm pretty new at this and I have this maze game I'm making on C++, and every time I try to run it whilst debugging, the same 3 problems come up with the enemies I've implemented.
The error message states; 'Run-Time Check Failure #3 - The variable 'Enemy1' is being used without being initialized.'
it does the same for Enemy2 and Enemy3.
i was wondering if anyone could tell me what I'm doing wrong?
the code is as follows;

#include <iostream>
#include <cstdlib>
//#include <ctime>
using namespace std;

struct Killer{
int x, y;
char kill;
};

struct Blocker{
int x, y;
char block;
};

struct Restarter{
int x, y;
char restart;
};

const char Height = 11, Width = 18;
const char Player = 'O', enemy1 = 'K', enemy2 = 'B', enemy3 = 'R', Goal = 'X';
int playerPositionX = 1, playerPositionY = 1, goalPositionX = 10, goalPositionY = 16;
char playerMovement;

unsigned char Map[Height][Width] = {
'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ','#',' ','#',' ','#','#',' ','#','#','#','#','#','#','#',' ','#',
'#',' ',' ',' ',' ',' ','#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#',
'#',' ','#','#',' ','#','#',' ','#',' ','#',' ','#','#','#','#',' ','#',
'#',' ',' ',' ',' ',' ',' ',' ','#',' ','#',' ','#',' ',' ',' ',' ','#',
'#',' ','#','#','#',' ','#',' ','#',' ','#',' ','#',' ','#','#','#','#',
'#',' ','#',' ','#',' ','#',' ','#',' ',' ',' ',' ',' ',' ',' ',' ','#',
'#',' ',' ',' ',' ',' ','#',' ','#',' ','#',' ','#','#','#','#',' ','#',
'#',' ','#',' ','#',' ','#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#',
'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
};

int refreshMap() {
Map[playerPositionX][playerPositionY] = Player;
Map[goalPositionX][goalPositionY] = Goal;
for (int y = 0; y < Height; y++) {
cout << endl;
for (int x = 0; x < Width; x++) {
cout << Map[x][y];
}
}
return 0;
}

int SpawnEnemy1() {

Killer Enemy1;
Enemy1.kill = enemy1;
//srand(time(0));

int Enemy1SpawnPointX = Enemy1.x;
Enemy1SpawnPointX = (rand() % 9) + 1;

int Enemy1SpawnPointY = Enemy1.y;
Enemy1SpawnPointY = (rand() % 16) + 1;

if (Map[Enemy1SpawnPointX][Enemy1SpawnPointY] != '#') {
if (Map[Enemy1SpawnPointX][Enemy1SpawnPointY] != 'O') {
Map[Enemy1SpawnPointY][Enemy1SpawnPointX] = enemy1;
}
}
return 0;
}

int SpawnEnemy2() {
Blocker Enemy2;
Enemy2.block = enemy2;
//srand(time(0));

int Enemy2SpawnPointX = Enemy2.x;
Enemy2SpawnPointX = (rand() % 9) + 2;

int Enemy2SpawnPointY = Enemy2.y;
Enemy2SpawnPointY = (rand() % 16) + 2;

if (Map[Enemy2SpawnPointX][Enemy2SpawnPointY] != '#') {
if (Map[Enemy2SpawnPointX][Enemy2SpawnPointY] != 'O') {
Map[Enemy2SpawnPointY][Enemy2SpawnPointX] = enemy2;
}
}
return 0;
}

int SpawnEnemy3() {
Restarter Enemy3;
Enemy3.restart = enemy3;
//srand(time(0));

int Enemy3SpawnPointX = Enemy3.x;
Enemy3SpawnPointX = (rand() % 9) + 2;

int Enemy3SpawnPointY = Enemy3.y;
Enemy3SpawnPointY = (rand() % 16) + 2;

if (Map[Enemy3SpawnPointX][Enemy3SpawnPointY] != '#') {
if (Map[Enemy3SpawnPointX][Enemy3SpawnPointY] != 'O') {
Map[Enemy3SpawnPointY][Enemy3SpawnPointX] = enemy3;
}
}
return 0;
}

int PlayerDirection() {
for (;;) {
cin >> playerMovement;

switch (playerMovement) {
case 'w':
if (Map[playerPositionX - 1][playerPositionY] != '#') {
if (Map[playerPositionX - 1][playerPositionY] != enemy2) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionX--;
}
}
if (Map[playerPositionX][playerPositionY] == enemy3) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionX = 1;
playerPositionY = 1;
}
if (Map[playerPositionX][playerPositionY] == enemy1) {
Map[playerPositionX][playerPositionY] = ' ';
for (;;) {
cout << "\n You Lose" << endl;
}
}
break;

case 's':
if (Map[playerPositionX + 1][playerPositionY] != '#') {
if (Map[playerPositionX + 1][playerPositionY] != enemy2) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionX++;
}
}
if (Map[playerPositionX][playerPositionY] == enemy3) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionX = 1;
playerPositionY = 1;
}
if (Map[playerPositionX][playerPositionY] == enemy3) {
Map[playerPositionX][playerPositionY] = ' ';
for (;;) {
cout << "\n You Lose" << endl;
}
}
break;

case 'a':
if (Map[playerPositionX][playerPositionY - 1] != '#') {
if (Map[playerPositionX][playerPositionY - 1] != enemy2) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionY--;
}
}
if (Map[playerPositionX][playerPositionY] == enemy3) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionX = 1;
playerPositionY = 1;
}
if (Map[playerPositionX][playerPositionY] == enemy1) {
Map[playerPositionX][playerPositionY] = ' ';
for (;;) {
cout << "You Lose" << endl;
}
}
break;

case 'd':
if (Map[playerPositionX][playerPositionY - 1] != '#') {
if (Map[playerPositionX][playerPositionY - 1] != enemy2) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionY--;
}
}
if (Map[playerPositionX][playerPositionY] == enemy3) {
Map[playerPositionX][playerPositionY] = ' ';
playerPositionX = 1;
playerPositionX = 1;
}
if (Map[playerPositionX][playerPositionY] == enemy1) {
Map[playerPositionX][playerPositionY] = ' ';
for (;;) {
cout << "\n You Lose" << endl;
}
}
break;

default:
cout << "You Pressed a Wrong Button, Try again" << endl;
break;
}
cout << SpawnEnemy1();
cout << SpawnEnemy2();
cout << SpawnEnemy3();
refreshMap();
}
return 0;
}
int main() {
cout << "\n Welcome to Treasure Hunt, where you must navigate a maze to find the 'X' Marking the burried treasure!" << endl;
cout << "the controls are are follows;" << endl;
cout << " W = UP\n A = LEFT\n D = RIGHT\n S = DOWN" << endl;
cout << "Watch out for enemy tiles. There are three different types you need to avoid:" << endl;
cout << "(B) Who will block your path" << endl;
cout << "(K) Who will kill you and the game will end" << endl;
cout << "(R) Who will send you back to the beginning" << endl;
cout << "Press any directional key to start (W,A,S,D)" << endl;

cout << SpawnEnemy1();
cout << SpawnEnemy2();
cout << SpawnEnemy3();
refreshMap();
cout << endl;
PlayerDirection();

return 0;
};

thanks so much!
main.cpp(58): warning C4700: uninitialized local variable 'Enemy1' used
main.cpp(77): warning C4700: uninitialized local variable 'Enemy2' used
main.cpp(96): warning C4700: uninitialized local variable 'Enemy3' used

It means that the variables have a random value. Random values can lead to problems that are difficult to find.
Oh right, thanks so much
How would you suggest I correct this?
Initialize them. Set their game state. Set their position. Otherwise all you get is garbage values.
Topic archived. No new replies allowed.