Logic Question

closed account (4wvoLyTq)
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
			}
			else if (toupper(get_key) == 'S')
			{
				POS[0] -= 1;
				_check_position(POS);	//SEND TO POS_CHECK
				clearscr;
			}
			else if (toupper(get_key) == 'W')
			{
				POS[1] += 1;
				_check_position(POS);	//SEND TO POS_CHECK
				clearscr;
			}
			else if (toupper(get_key) == 'E')
			{
				POS[1] -= 1;
				_check_position(POS);	//SEND TO POS_CHECK
				clearscr;
			}

			else if (toupper(get_key) == 'P')
			{
				clearscr;
				u_p1.display_stats(&addrp1);
			}
			else if (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.
closed account (4wvoLyTq)
Yes, hah I am still learning. I will check that out, Thanks!
Topic archived. No new replies allowed.