[try Beta version]
Not logged in

 
Small game problem

Jul 27, 2015 at 8:41am
I'm having trouble with the syntax of converting each map to the variable used in my later code for the actual game to be played on. Any help is appreciated.

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
char Map1[10][10] = 
{ 
"#########",
"#!#     #",
"# #     #",
"# #     #",
"#       #",
"#       #",
"#   @   #",
"#########" };

char Map2[10][10] = 
{ 
"#########",
"#!# #   #",
"# #     #",
"# #     #",
"#       #",
"#       #",
"#   @   #",
"#########" };

char Map3[10][10] = 
{ 
"#########",
"#!# #   #",
"# # #   #",
"# #     #",
"#       #",
"#       #",
"#   @   #",
"#########" };

int Gamespeed = 100;
int Level = 1;
bool stopgame = false;
char Map[10][10];
int main()
{

	if(Level == 1)
{
	char Map = Map1;
}

	if(Level == 2)
{
	char Map = Map2;
}
	if(Level == 3)
{
	char Map = Map3;
}
Jul 27, 2015 at 1:49pm
Lines 43, 48, 52: You're declaring a local char variable named Map and then trying to assign it one of the 2-D arrays. You can't do this.

You have a couple of options.
1) Copy one map array to the other. Write a function to do this.
2) Change line 37 to a pointer. Then at lines 43,48,52, you can assign one of the arrays to the pointer.
Jul 27, 2015 at 3:12pm
This is how you define a pointer to a 2d array:

char (*Map)[10];
Topic archived. No new replies allowed.