Help, Simple 2D array Game

Hey all,

I need some help on first 2D array game. To make this game I just took a simple approach making a drawing function that draws the array, and a function that sets my array to default values. Then check for arrow keys pressed then set player new position, clear screen and redraw the array. My program works pretty much fine expect for 2 problems. Heres a bit of my code.

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
51
int keys;

	do
	{
		
	if(keys=_getch()==72) // Up key
	{

		firstmap(map); // set all values of the array back to default
		currenty = currenty - 1; 
		map[currenty][currentx] = "*"; // sets player new position
		system("CLS");     // clear screen
		drawmap(map);  // redraws new array with new player position

	}

	if(keys=_getch()==75) // Left Key
	{

		firstmap(map);
		currentx = currentx - 1;
		map[currenty][currentx] = "*";
		system("CLS");
		drawmap(map);

	}

	if(keys=_getch()==77) // Right key
	{

		firstmap(map);
		currentx = currentx + 1;
		map[currenty][currentx] = "*";
		system("CLS");
		drawmap(map);

	}

		if(keys=_getch()==80) // down key
	{

		firstmap(map);
		currenty = currenty + 1;
		map[currenty][currentx] = "*";
		system("CLS");
		drawmap(map);

	}

	
	}while(map[3][4]!="*");


When my program enters the loop only the last if statement will work. For example in my code above my program will run flawlessly for the down key but not for the rest of the keys. If I switch the last if statement to the up key it will work fine for the up key nothing else(same for the rest of the keys). As well my second question is how come I have to press the button twice in order for it to work.
Last edited on
@BruteCOder
You may want to try this.
1
2
3
4
#define UP 72
#define LEFT 75
#define RIGHT 77
#define DOWN 80 


Then check with
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
int keys = _getch();
		switch(keys)
		{
		case UP:
                {
		  firstmap(map); // set all values of the array back to default
		  currenty = currenty - 1; 
	 	  map[currenty][currentx] = "*"; // sets player new position
		  system("CLS");     // clear screen
		  drawmap(map);  // redraws new array with new player position
                   break;
               }
		case LEFT:
		{
          	  firstmap(map);
		  currentx = currentx - 1;
		  map[currenty][currentx] = "*";
		  system("CLS");
		  drawmap(map);
                  break;
                }
		case RIGHT:
		{
		   firstmap(map);
		   currentx = currentx + 1;
		   map[currenty][currentx] = "*";
		   system("CLS");
		   drawmap(map);
                    break;
		}
		case DOWN:
		{
                   firstmap(map);
		   currenty = currenty + 1;
	  	  map[currenty][currentx] = "*";
		  system("CLS");
		  drawmap(map);
                   break;
		}
^^Thanks alot worked like a charm
Topic archived. No new replies allowed.