Code.org Painter Object repeats a line, how do I stop this?

Viewed 10

Diagonal lines where one in the middle repeats (the problem line)

The code is meant to make alternating lines of white and red, but after it switches at the halfway point (once it can't go north), it repeats the first color again.

public void pattern1(String color, String color2) {
setPaint(1000);
int I=1;
int C=1; /* which color*/
moveTo(0,0);
moveSouth();
paint(color);
C = 2;
int X = getX();
int Y = getY();
while (getMyPaint() != 744) {
  if (canMove("north")){
  while (canMove("north")) {
  while (C == 1){
    if (!canMove("west")) {
      X = X+1;
      moveTo(X,Y);
      C = 2;
  }
    if (canMove("west")) {
      while (canMove("west")) {
        makeTurn("north");
        paint(color);
        move();
        makeTurn("west");
        move();
        paint(color);
 }
}


}
      while (C == 2){
        if (!canMove("west")) {
          X = X+1;
          moveTo(X,Y);
          C = 1;
      }
        if (canMove("west")) {
          while (canMove("west")) {
            makeTurn("north");
            paint(color2);
            move();
            makeTurn("west");
            move();
            paint(color2);
      }
     }
    }
   }
  }
    if (!canMove("north")) {
      X=getX();
      Y=getY();
      X = X+1;
      moveTo(X,Y);
      while (canMove("south")){
        while (C == 1){
        if (!canMove("east")) {
          X = X+1;
          moveTo(X,Y);
          C = 2;
      }
        if (canMove("east")) {
          while (canMove("east")) {
            makeTurn("south");
            paint(color);
            move();
            makeTurn("east");
            move();
            paint(color);
     }
    }
   }
      while (C != 1){
        if (!canMove("east")) {
          X = X+1;
          moveTo(X,Y);
          C = 1;
      }
        if (canMove("east")) {
          while (canMove("east")) {
            makeTurn("south");
            paint(color2);
            move();
            makeTurn("east");
            move();
            paint(color2);
       }
      }
     }
    }
   }    
  }
 }
}

The problem occurs in the if(!canMove("north")), if you know what the issue is, please let me know

0 Answers
Related