right method
Color right 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 row is colored.
Return true on success.
Implementation
bool right(List<int> colors, [int? n]) {
int? param = n;
List<int> newColors = colors;
int offset = 0;
int j = 0;
if (param == null) {
final bool prev = move.copyMode;
move.copyMode = false;
while (move.left()) {
offset++;
}
newColors = buildOffset(colors, -offset);
while (color(newColors[j]) && move.right()) {
j = (j + 1) % colors.length;
}
move.copyMode = prev;
return true;
} else {
param--;
}
if (param < 1 ||
!_shape.validatePosition(move.column + param, move.row) ||
!color(newColors[j])) {
return false;
}
for (int i = 0; i < param; i++) {
j = (j + 1) % newColors.length;
move.right();
color(newColors[j]);
}
return true;
}