public class NeighborhoodRunner {
public static void main(String[] args) {
/* ----------------------------------- TO DO -----------------------------------
*
* -----------------------------------------------------------------------------
*/
RowPainter Dan = new RowPainter(1, 4, "east", 40);
Dan.paintArea("red", "orange");
}
}
import org.code.neighborhood.*;
public class RowPainter extends Painter {
public RowPainter(int x, int y, String direction, int paint) {
super(x, y, direction, paint);
}
public void turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
public void moveIfCanMove() {
if (canMove()) {
move();
}
}
public void paintArea(String firstColor, String secondColor) {
while (canMove()) {
paintEast(firstColor);
paintWest(secondColor);
moveIfCanMove();
if (!canMove()) {
paintEast(firstColor);
paintWest(secondColor);
moveToNextRow();
}
}
}
public void paintEast(String color) {
if ((getY() == 3%4) && (isFacingEast())){
paint(color);
}
}
public void paintWest(String color) {
if ((getY() == 12%4) && (isFacingEast())){
if (hasPaint()){
paint(color);
}
}
}
public void moveToNextRow() {
if (canMove("south")) {
if (facingEast()) {
turnRight();
moveIfCanMove();
turnRight();
}
else {
turnLeft();
moveIfCanMove();
turnLeft();
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/799 ... wont-paint
Мобильная версия