Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMarkS

Posted 06 December 2012 - 09:56 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form of control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

		  {

			   x--;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only increment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

		  {

			   x++;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

}


#5MarkS

Posted 06 December 2012 - 09:52 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

		  {

			   x--;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only increment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

		  {

			   x++;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

}


#4MarkS

Posted 06 December 2012 - 09:52 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

          {

			   x--;

			   map[x][y] = 2;

          }

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only incriment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

          {

			   x++;

			   map[x][y] = 2;

          }

		  redraw();

	 }

}


#3MarkS

Posted 06 December 2012 - 09:36 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

			   x--;

		  map[x][y] = 2;

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only incriment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

			   x++;

		  map[x][y] = 2;

		  redraw();

	 }

}


#2MarkS

Posted 06 December 2012 - 09:35 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

          if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

               x--;

		  map[x][y] = 2;

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only incriment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

			   x++;

		  map[x][y] = 2;

		  redraw();

	 }

}


#1MarkS

Posted 06 December 2012 - 09:25 PM

Glad I could help.

PARTNERS