paintPattern method
Implementation
void paintPattern(List<String> colors, String repetitions, String pattern) {
final List<int> colorsParsed =
colors.map((String e) => containsColor(e.trim()).index).toList();
if (colorsParsed.contains(CatColors.NaC.index) || colors.isEmpty) {
_error = CatError.invalidColor;
return;
}
final int column = _commandCaller.board.move.column;
final int row = _commandCaller.board.move.row;
final String color = pattern
.split(" ")
.where((String element) => element.isNotNullOrEmpty)
.mapIndexed(
(int index, String p1) => index == 0 ? p1 : p1.capitalize(),
)
.map((String e) => e.replaceAll("-", ""))
.join();
bool call = false;
try {
final int repetitionsParsed = repetitions.toInt();
call = _commandCaller
.color(color, <dynamic>[colorsParsed, repetitionsParsed]);
} on FormatException {
call = _commandCaller.color(color, <dynamic>[
colorsParsed,
]);
}
if (!call) {
_error = CatError.invalidColoringCommand;
}
_commandCaller.board.move.toPosition(row, column);
}