#include <iostream>
#include <string>
#include <time.h>
int main()
{
char place[5][5];
int xPlayer = rand() % 6;
int yPlayer = rand() % 6;
if (xPlayer == 1 || xPlayer == 6)
{
yPlayer;
}
if (yPlayer == 1 || yPlayer == 6)
{
xPlayer;
}
}
I'm pretty sure if my google sources are correct that sould make the 6x6 grid and give me a random spawn anywhere inside, but I can't think of what I would put so I down spawn in the middle of the map
You could use one random number to decide on which border you are going to spawn, and then a second random number to decide which of the border squares you are going to spawn.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int side = rand() % 4;
int square = rand() % 5;
switch (side)
{
case 0: // left
x = 0; y = square;
break;
case 1: // right
x = 4; y = square;
break;
case 2: // top
x = square; y = 0;
break;
case 3: // bottom
x = square; y = 4;
break;
}
int side = rand() % 4;
int square = rand() % 5;
switch (side)
{
case 0: // left
x = 0; y = square;
break;
case 1: // right
x = 4; y = square;
break;
case 2: // top
x = square; y = 0;
break;
case 3: // bottom
x = square; y = 4;
break;
}
With this how would I set it up to move around my drawn map in the OP?
I haven't used many switch/case statements not too sure entirely how they work
int side = rand() % 4;
int square = rand() % 5;
if (side == 0) // left
{
x = 0;
y = square;
}
elseif (side == 1) // right
{
x = 4;
y = square;
}
elseif (side == 2) // top
{
x = square;
y = 0;
}
else // bottom
{
x = square;
y = 4;
}
Note that this is for a 5x5 map. If you want it to work for a 6x6 map you need to make the place array larger and adjust the constants in the code above (I recommend using named constants).
How you should be moving the player around, I don't know. Are you using cin?
@Peter87, Yeah I'm using std::cin to take in commands from the user and with movements of North, East, South and West, (reason for the compass) also trying to make it so that each room has different types of puzzles (that part I can do anyway)