From 01ca2f50f4306366802293fa81158027d83c4388 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Fri, 7 Oct 2022 10:38:56 +0200 Subject: [PATCH] Improve game map formatting --- .../src/ui_widgets/game_map_widget.rs | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/rust/cli_player/src/ui_widgets/game_map_widget.rs b/rust/cli_player/src/ui_widgets/game_map_widget.rs index 21ee061..e638475 100644 --- a/rust/cli_player/src/ui_widgets/game_map_widget.rs +++ b/rust/cli_player/src/ui_widgets/game_map_widget.rs @@ -24,10 +24,36 @@ impl<'a> Widget for GameMapWidget<'a> { for x in 0..(self.rules.map_width + 1) { let o_x = x as u16 * 2; let o_y = y as u16 * 2; - buf.get_mut(o_x, o_y).set_symbol(symbols.cross); - buf.get_mut(o_x + 1, o_y).set_symbol(symbols.horizontal); - buf.get_mut(o_x, o_y + 1).set_symbol(symbols.vertical); - buf.get_mut(o_x + 1, o_y + 1).set_char('.'); + buf.get_mut(o_x, o_y).set_symbol(match (x, y) { + (0, 0) => symbols.top_left, + + (x, 0) if x == self.rules.map_width => symbols.top_right, + (0, y) if y == self.rules.map_height => symbols.bottom_left, + + (0, _) => symbols.vertical_right, + (_, 0) => symbols.horizontal_down, + + (x, y) if x == self.rules.map_width && y == self.rules.map_height => { + symbols.bottom_right + } + + (x, _) if x == self.rules.map_width => symbols.vertical_left, + (_, y) if y == self.rules.map_height => symbols.horizontal_up, + + _ => symbols.cross, + }); + + if x < self.rules.map_width { + buf.get_mut(o_x + 1, o_y).set_symbol(symbols.horizontal); + } + + if y < self.rules.map_height { + buf.get_mut(o_x, o_y + 1).set_symbol(symbols.vertical); + } + + if x < self.rules.map_width && y < self.rules.map_height { + buf.get_mut(o_x + 1, o_y + 1).set_char('.'); + } } } }