up method

bool up(
  1. List<int> colors,
  2. [int? n]
)

Color up from a current position defined by the movement.

Requires a list of colors and a number n of cells to color. If no number n of cells is passed all the column is colored. Return true on success.

Implementation

bool up(List<int> colors, [int? n]) {
  int? param = n;
  List<int> newColors = colors;
  int j = 0;
  int offset = 0;
  if (param == null) {
    final bool prev = move.copyMode;
    move.copyMode = false;
    while (move.down()) {
      offset++;
    }
    newColors = buildOffset(colors, offset);
    while (color(newColors[j]) && move.up()) {
      j = (j + 1) % colors.length;
    }
    move.copyMode = prev;

    return true;
  } else {
    param--;
  }

  if (param < 1 ||
      !_shape.validatePosition(move.column, move.row - param) ||
      !color(colors[j])) {
    return false;
  }
  for (int i = 0; i < param; i++) {
    j = (j + 1) % colors.length;
    move.up();
    color(colors[j]);
  }

  return true;
}