I am looking for the best way to implement what I am trying to achieve. I am creating a basic first game program, and I have the movement working correctly by using an array. See below:
do
{
std::cout << "Please enter (N)orth, (S)outh, (E)ast, (W)est, (P)erson, or (Q)uit." << std::endl;
std::cout << POS[0] << ", " << POS[1];
std::cout << std::endl;
std::cout << "What do you want to do: ";
std::cin >> get_key;
if (toupper(get_key) == 'N')
{
POS[0] += 1;
_check_position(POS); //SEND TO POS_CHECK
clearscr;
}
elseif (toupper(get_key) == 'S')
{
POS[0] -= 1;
_check_position(POS); //SEND TO POS_CHECK
clearscr;
}
elseif (toupper(get_key) == 'W')
{
POS[1] += 1;
_check_position(POS); //SEND TO POS_CHECK
clearscr;
}
elseif (toupper(get_key) == 'E')
{
POS[1] -= 1;
_check_position(POS); //SEND TO POS_CHECK
clearscr;
}
elseif (toupper(get_key) == 'P')
{
clearscr;
u_p1.display_stats(&addrp1);
}
elseif (toupper(get_key) == 'Q')
{
cont = false;
}
else
{
std::cout << "You did not enter a valid option.";
pause;
pause;
}
} while (cont != false);
I am looking for the most logical way to implement actions at specific locations, such as at the position 10, 1. For example, at 10, 1 I would like it to say that the player has reached a city, and provide with a menu (such as item shop, weapon shop, and a few others). Would it be best to use if/else if/else statements for each position that I want to happen?
Would it be best to use if/else if/else statements for each position that I want to happen?
No. That would turn out to be a lot of work, adding a new set for every location, and having to edit many lines of code if you want to change the location.
How about some kind of lookup table? A map would do. If these are new terms for you, time to learn something new.