dont work homework

This commit is contained in:
lemon-cat committed 2026-05-18 14:42:41 +03:00
1 parent 1e9529733f
commit 6ffbfbb7bf
5 files changed
+238 -1

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
use std::io::{Stdout, Write, stdout};
use crossterm::{
cursor::MoveTo,
queue,
style::Print,
terminal::{Clear, ClearType},
};
use crate::grid::Grid;
pub struct Render {
out: Stdout,
rez: (usize, usize),
}
impl Render {
// add code here
pub fn init() -> Self {
Render {
out: stdout(),
rez: (40, 80),
}
}
pub fn resize(&mut self, r: &(usize, usize)) -> Result<(), std::io::Error> {
self.rez = r.clone();
Ok(())
}
pub fn clear(&mut self) -> Result<(), std::io::Error> {
queue!(self.out, Clear(ClearType::All), MoveTo(0, 0))?;
self.out.flush()?;
Ok(())
}
pub fn print(&mut self, out: &str) -> Result<(), std::io::Error> {
queue!(self.out, Print(out), Print("\r\n"))?;
self.out.flush()?;
Ok(())
}
pub fn frame(&mut self, g: &Grid) -> Result<(), std::io::Error> {
for i in 0..self.rez.0 {
for j in 0..self.rez.1 {
let r = g.who_in(&(i, j));
match r {
true => {
queue!(self.out, Print("፨"))?;
}
false => {
queue!(self.out, Print(" "))?;
}
}
}
queue!(self.out, Print("\r\n"))?;
}
self.out.flush()?;
Ok(())
}
}