if (map[xPos][yPos] == map[xTPos][yTPos]) this works and does what I want it to do. But when I increase the traps. Multiple traps "5" display on the grid but only the last one (assuming) that is created will trigger my if statement.
I was trying to add map(i)[xTPos][yTPos] but I'm having no luck with creating 30 different map[xTPos][yTPos]. I know I'm on the right track with the for loop! Just don't know how to put the syntax with arrays.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
srand((unsigned)time(0));
int xPos = 0;
int yPos = 0;
int xTPos = 0;
int yTPos = 0;
int move;
int map[15][15] = { 1};
for (int i=0;i<30;i++)//Will display a Trap 30 times but only 1 trap will trigger
{
xTPos = (rand()%15)+1; my if statement
yTPos = (rand()%15)+1;
map[xTPos][yTPos]; // Trap
map[xTPos][yTPos] = 5;
}
do
{
for (int i=0;i<15;i++)
{
for (int j=0;j<15;j++)
{
cout << map[i][j] << " ";
}
cout << endl;
}
cout << "(1):\t Down\n(2):\tUp\n(3):\tRight\n(4):\tLeftn";
cin >> move;
switch ( move )
{
case 1:
map[xPos][yPos] = 0; //
map[xPos+1][yPos] = 1; // displays number
xPos++;
break;
case 2:
map[xPos][yPos] = 0;
map[xPos-1][yPos] = 1; // displays number
xPos--;
break;
case 3:
map[xPos][yPos] = 0; //
map[xPos][yPos+1] = 1; // displays number
yPos++;
break;
case 4:
map[xPos][yPos] = 0; //
map[xPos][yPos-1] = 1; // displays number
yPos--;
break;
}
system("cls");
if (map[xPos][yPos] == map[xTPos][yTPos]) // if number 1 lands on 5 ....
{
cout << "TRAP TRAP!\n";
}
}while (move == 1 || 2 || 3 || 4);
cin.get();
return EXIT_SUCCESS;
}