Show invalid boats in red
This commit is contained in:
@ -133,16 +133,36 @@ fn ui<B: Backend>(
|
||||
) -> CoordinatesMapper {
|
||||
let errors = model.layout.errors(rules);
|
||||
|
||||
// Color of current boat
|
||||
let current_boat = ColoredCells {
|
||||
color: Color::Green,
|
||||
cells: model.layout.0[model.curr_boat].all_coordinates(),
|
||||
};
|
||||
|
||||
// Color of invalid boats
|
||||
let mut invalid_coordinates = vec![];
|
||||
for (idx, pos) in model.layout.boats().iter().enumerate() {
|
||||
if idx == model.curr_boat {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !model
|
||||
.layout
|
||||
.check_present_boat_position(idx, rules)
|
||||
.is_empty()
|
||||
{
|
||||
invalid_coordinates.append(&mut pos.all_coordinates());
|
||||
}
|
||||
}
|
||||
let invalid_boats = ColoredCells {
|
||||
color: Color::Red,
|
||||
cells: invalid_coordinates,
|
||||
};
|
||||
|
||||
// Color of other boats
|
||||
let mut other_boats_cells = vec![];
|
||||
for boat in &model.layout.0 {
|
||||
for pos in boat.all_coordinates() {
|
||||
other_boats_cells.push(pos);
|
||||
}
|
||||
other_boats_cells.append(&mut boat.all_coordinates());
|
||||
}
|
||||
|
||||
let other_boats = ColoredCells {
|
||||
@ -163,6 +183,7 @@ fn ui<B: Backend>(
|
||||
let mut game_map_widget = GameMapWidget::new(rules)
|
||||
.set_default_empty_char(' ')
|
||||
.add_colored_cells(current_boat)
|
||||
.add_colored_cells(invalid_boats)
|
||||
.add_colored_cells(other_boats)
|
||||
.set_title("Choose your boat layout")
|
||||
.set_yield_func(|c, r| {
|
||||
@ -174,7 +195,7 @@ fn ui<B: Backend>(
|
||||
})
|
||||
.set_legend(legend);
|
||||
|
||||
// Colorate neighbors if boats can not touch
|
||||
// Color of neighbors if boats can not touch
|
||||
if !rules.boats_can_touch {
|
||||
let mut boats_neighbors_cells = vec![];
|
||||
for boat in &model.layout.0 {
|
||||
|
Reference in New Issue
Block a user