Hi guys, I'm trying to write a text-based adventure game. The basic gist is that I create a layout with different rooms, each numbered starting with 0.
In a part of this assignment, I am expected to "Declare a 2-dimensional integer array to hold each room’s exits. This array should have 2 sizes: the number of rooms (7) and total possible exits (4). Use an initializer list to add all of your room exits. Each room should contain a 4 element array containing the indices to the rooms that connect to it in the order: North of this room, East of this room, West of this room, South of this room.
Can someone please show me how to declare a 2-D array with these directions? I'm confused about the instructions--am I supposed to create an array of 7 rows and 2 columns? How do I initialize a 2-D array?
If you know how to use normal arrays, you'll understand 2d arrays.
So, the 7 is the rooms. and the 4 is exits. So if you want to access the third room, and the last exit in that room, it would be
arr[2][3];
If you want to input to it etc, you would use a nested for loops, 2 for loops within eachother. The outside for-loop runs 7 times becuase there are 7 rooms, and the inside one runs 4 times.
I understand what the array is (7 rooms, 4 possible exits). I also know that for each room, these are the possible exits from the layout I have (each number is a room; I can't get the formatting right, but room 6 is supposed to be directly under room 4)--
I just don't understand how to initialize it? I'm not sure if initialize is the word, but I hope you can understand what I'm asking after this diagram.
I'm just trying to understand how to "tie it all together". If I put arr[7][4]; like you said, wouldn't the default value be {0,0,0,0} for all of the rooms?