2D Array issues...

Topic Removed... Thank you for your help.
Last edited on
Have you played around with how you pass the array to your function?
...I believe the array is being passed correctly; I think the issue is that the array isn't storing the input values, thereby only outputting the initial array, not the list array which stores the new values. I could be wrong, but that's my best guess.
The first three lines I commented out are unnecessary because you are only concerned if there is an empty space where the user wants to go. Plus, you have no other conditions to check, i.e. else if's. And, I'm not sure, but are the last few conditions for checking if the user is only moving one space? What about x2 == x1 or y2 == y1 - 1?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	if(
		list[x1][y1] == 'S'
//		&& list[x2][y2] != 'S'
//		&& list[x2][y2] != 'F'
//		&& list[x2][y2] != ' ' //illegal move
		&& list[x2][y2] == '.' //empty space
		&& y2 == y1 +1 //up one
		|| y1 == y2 
		&& x2 == x1 +1 //to the right by one
//		|| y1 == y2    //Redundant 
		&& x2 == x1 -1
	){
 
		{  ///Why do you need these extra brackets?
			list[x1][y1] = '.'; 
			list[x2][y2] = 'S';
 
		}
 
	}


Oh, and I just noticed this.... Your sheepMovement function updates the list array, but your printgameboard never uses list. So your changes never appear.
Last edited on
@Daleth (not sure if the @ works here), I'm so embarrassed. I've been looking at this code for a few hours now, and my eyes are on Level: Zombie. Initially I had y1 == y2 +1 || y1 == y2 -1, but then went back and changed it because horizontal movement is only allowed for the x values, y values can only be moved up, not down. Anyway, I guess I didn't fully delete the old code, and because of that, extra brackets were left. So yeah, please don't think I'm an idiot, guess that's when you know its time to go to bed, when you start missing the obvious. At any rate, I still have the same issues w/my board, despite making the aforementioned changes:(
It's all good. Now you know.

Did you see my message after the code box? You have no current moethod of displaying the changes to your list array.
Topic archived. No new replies allowed.