Start to build game grid
This commit is contained in:
34
rust/cli_player/src/ui_widgets/game_map_widget.rs
Normal file
34
rust/cli_player/src/ui_widgets/game_map_widget.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use sea_battle_backend::data::{GameRules, PlayConfiguration};
|
||||
use tui::buffer::Buffer;
|
||||
use tui::layout::Rect;
|
||||
use tui::widgets::{BorderType, Widget};
|
||||
|
||||
pub struct GameMapWidget<'a> {
|
||||
rules: &'a GameRules,
|
||||
}
|
||||
|
||||
impl<'a> GameMapWidget<'a> {
|
||||
pub fn new(rules: &'a GameRules) -> Self {
|
||||
Self { rules }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Widget for GameMapWidget<'a> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let alphabet = PlayConfiguration::default().ordinate_alphabet;
|
||||
|
||||
let symbols = BorderType::line_symbols(BorderType::Plain);
|
||||
|
||||
// Paint game grid
|
||||
for y in 0..(self.rules.map_height + 1) {
|
||||
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('.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod button_widget;
|
||||
pub mod checkbox_widget;
|
||||
pub mod game_map_widget;
|
||||
pub mod text_editor_widget;
|
||||
|
Reference in New Issue
Block a user