From 64c44822724265d5d589c7a0f81d8d1dbd73ab1d Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Tue, 13 Sep 2022 20:06:58 +0200 Subject: Fixed a bug where the width was way more that its supposed to be --- src/debug.txt | 13 +++++++++++++ src/generation.rs | 28 +++++++++++++++++----------- src/ui.rs | 9 ++------- 3 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 src/debug.txt (limited to 'src') diff --git a/src/debug.txt b/src/debug.txt new file mode 100644 index 0000000..1aec867 --- /dev/null +++ b/src/debug.txt @@ -0,0 +1,13 @@ +warning: function `render_gen` is never used + --> src/generation.rs:38:8 + | +38 | pub fn render_gen(chunk: &Rect, gen: &Gen) { + | ^^^^^^^^^^ + | + = note: `#[warn(dead_code)]` on by default + +warning: `gof-rs` (bin "gof-rs") generated 1 warning + Finished dev [unoptimized + debuginfo] target(s) in 0.02s + Running `/home/pengu/test/rust-dev/gof-rs/target/debug/gof-rs` +heigt: 44 +width: 62 diff --git a/src/generation.rs b/src/generation.rs index a105d43..df971d7 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -50,18 +50,20 @@ pub fn render_gen(chunk: &Rect, gen: &Gen) { pub fn new_gen(chunk: &Rect) -> Gen { let cells = vec![Cell::Dead, Cell::Dead, Cell::Alive, Cell::Dead, Cell::Alive]; - let cols: u16 = chunk.height; - let rows: u16 = chunk.width; - let mut colums: Vec> = Vec::new(); - for _ in 0..cols { - let mut col: Vec = Vec::new(); - for _ in 0..rows { + let cols: u16 = chunk.width - 90; + let rows: u16 = chunk.height - 2; + eprintln!("heigt: {}", rows); + eprintln!("width: {}", cols); + let mut grid: Vec> = Vec::new(); + for _ in 0..rows { + let mut row: Vec = Vec::new(); + for _ in 0..cols{ let rand = thread_rng().gen_range(0..10); - col.push(cells[rand % 5]); + row.push(cells[rand % 5]); } - colums.push(col); + grid.push(row); } - colums + grid } pub fn gen_to_spans(gen: &Gen) -> Vec { @@ -70,8 +72,12 @@ pub fn gen_to_spans(gen: &Gen) -> Vec { let mut txt = String::new(); for j in 0..gen[0].len() { match gen[i][j] { - Cell::Alive => txt.push('X'), - Cell::Dead => txt.push('-'), + // Cell::Alive => print!("😎"), + // Cell::Alive => txt.push_str("🦀"), + Cell::Alive => txt.push_str("❌"), + Cell::Dead => txt.push_str("⬛️"), + // Cell::Alive => txt.push('X'), + // Cell::Dead => txt.push('-'), } } spans.push(Spans::from(txt)); diff --git a/src/ui.rs b/src/ui.rs index 08d615f..7317901 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -115,13 +115,8 @@ pub fn run_app( let mut last_tick = Instant::now(); loop { terminal.draw(|f| ui(f, &mut app))?; - // let mut frame = app.generation; - // let nxt; - // let timeout = tick_rate - // .checked_sub(last_tick.elapsed()) - // .unwrap_or_else(|| Duration::from_secs(0)); - let timeout = Duration::from_millis(40); + let timeout = Duration::from_millis(10); if crossterm::event::poll(timeout)? { if let Event::Key(key) = event::read()? { match key.code { @@ -214,6 +209,6 @@ fn ui(f: &mut Frame, app: &mut App) { let paragraph = Paragraph::new(spans.clone()) .style(Style::default().bg(Color::Black).fg(Color::Blue)) .block(create_block(" Game Of Life ")) - .alignment(Alignment::Left); + .alignment(Alignment::Center); f.render_widget(paragraph, chunks[1]); } -- cgit v1.2.3