Start to build game grid

This commit is contained in:
2022-10-07 10:20:21 +02:00
parent 17a4edf417
commit 7178b96077
6 changed files with 118 additions and 2 deletions

View 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('.');
}
}
}
}

View File

@ -1,3 +1,4 @@
pub mod button_widget;
pub mod checkbox_widget;
pub mod game_map_widget;
pub mod text_editor_widget;