Help regarding Keys and doors

Hello people, i need help regrading Keys and doors in a maze. Here's my sample of the maze

{'o','o','o','o','o','o','o'},
{'o','S',' ',' ',' ','E','o'},
{'o','o','o',' ','o','D','o'},
{'o',' ',' ',' ',' ',' ','o'},
{'o',' ','o','o','o','K','o'},
{'o',' ',' ',' ',' ',' ','o'},
{'o','o','o','o','o','o','o'},

S = start
E = end
o = walls
D = door
K = key

And here are my code for the moving part

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
void moveMaze (char maze[][7]){ // change accordingly
    int x = 1; //starting point
    int y = 1;
    char move;
	
	while (maze[1][5] != 'X'){ //winning points
    cout << "Move(w/a/s/d)";
    move = getch();
    cout << endl;
	
	    if (move == 'w'){
        if (maze[x - 1][y] != 'o' && maze[x - 1][y] != 'D'){
            maze[x][y] = ' ';
            maze[x - 1][y] = 'X';
            x -= 1;
        } 
            
    }

		if (move == 'a'){
        if (maze[x][y - 1] != 'o' && maze[x][y - 1] != 'D'){
            maze[x][y] = ' ';
            maze[x][y - 1] = 'X';
            y -= 1;
        }
         
    }
    if (move == 's'){
        if (maze[x + 1][y] != 'o' && maze[x + 1][y] != 'D'){
            maze[x][y] = ' ';
            maze[x + 1][y] = 'X';
            x += 1;
        } 
    }
    if (move == 'd'){
        if (maze[x][y + 1] != 'o' && maze[x][y + 1] != 'D'){
            maze[x][y] = ' ';
            maze[x][y + 1] = 'X';
            y += 1;
        } 
	}



	if(maze [x - 1][y] == 'K' || maze[x][y - 1] == 'K' || maze[x + 1][y] == 'K' || maze[x][y + 1] == 'K' ) {
		if (move == 'a') {
			if (maze[x - 1][y] != 'o'){
            maze[x][y] = ' ';
            maze[x - 1][y] = 'X';
            x -= 1;
			}
		}
		if (move == 'd'){
			if (maze[x][y - 1] != 'o'){
            maze[x][y] = ' ';
            maze[x][y - 1] = 'X';
            y -= 1;
			}
		}
		if (move == 's'){
			if (maze[x + 1][y] != 'o'){
            maze[x][y] = ' ';
            maze[x + 1][y] = 'X';
            x += 1;

			} 
		}
		if (move == 'd') {
			if (maze[x][y + 1] != 'o'){
            maze[x][y] = ' ';
            maze[x][y + 1] = 'X';
            y += 1;
		 }
		}
	}
		
    
	

    printMaze(maze, 7, 7); // change accordingly
	
	
	
	}
} 

The problem is that even if get the key "K", the door "D" wont unlock.
Anyone can help me correct my code? So that when you get the key "K", you will be able to unlock the door "D". Thanks in advance.
Last edited on
help needed ~
Topic archived. No new replies allowed.