dont work homework
This commit is contained in:
1 parent
1e9529733f
commit
6ffbfbb7bf
5 files changed
+238
-1
No files matched your search
+83
-1
@@ -1,3 +1,85 @@
|
||||
mod grid;
|
||||
mod input;
|
||||
mod render;
|
||||
|
||||
use grid::*;
|
||||
use input::*;
|
||||
use render::*;
|
||||
//use std::clone;
|
||||
use std::{clone, sync::atomic::AtomicI32};
|
||||
fn step(g: &mut Grid, rez: &(usize, usize)) {
|
||||
let a = g.clone();
|
||||
for i in 0..rez.0 as i32 {
|
||||
for j in 0..(rez.1 - 1) as i32 {
|
||||
if !a.who_in(&(i as usize, (j + 1) as usize)) {
|
||||
g.push_in(false, &(i as usize, j as usize));
|
||||
g.push_in(true, &(i as usize, (j + 1) as usize));
|
||||
} else if !a.who_in(&((i + 1) as usize, (j + 1) as usize)) && i < rez.1 as i32 {
|
||||
g.push_in(false, &(i as usize, j as usize));
|
||||
g.push_in(true, &((i + 1) as usize, (j + 1) as usize));
|
||||
} else if !a.who_in(&((i - 1) as usize, (j + 1) as usize)) && i > 0 {
|
||||
g.push_in(false, &(i as usize, j as usize));
|
||||
g.push_in(true, &((i - 1) as usize, (j + 1) as usize));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum InputType {
|
||||
keyboard,
|
||||
comand,
|
||||
}
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let mut it = InputType::comand;
|
||||
let mut r = Render::init();
|
||||
_ = r.clear();
|
||||
_ = r.print("Hello sand!");
|
||||
//_ = r.frame();
|
||||
let rez: (usize, usize) = (40, 80);
|
||||
_ = r.resize(&rez);
|
||||
let mut space = Grid::init(&rez);
|
||||
space.rand();
|
||||
loop {
|
||||
_ = r.frame(&space);
|
||||
step(&mut space, &rez);
|
||||
match it {
|
||||
InputType::comand => {
|
||||
_ = r.print("print comand:");
|
||||
let input = Comand_pars();
|
||||
if input.is_err() {
|
||||
_ = r.print(&input.err().unwrap());
|
||||
} else {
|
||||
match input.unwrap() {
|
||||
ComandEvent::Exit => {
|
||||
_ = r.print("end program\n");
|
||||
return;
|
||||
}
|
||||
ComandEvent::Key => {
|
||||
it = InputType::keyboard;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
InputType::keyboard => {
|
||||
let input = Key_pars();
|
||||
if input.is_err() {
|
||||
_ = r.print(&format!("{}", input.err().unwrap()));
|
||||
} else {
|
||||
if let Some(k) = input.unwrap() {
|
||||
match k {
|
||||
KeyEvent::Exit => {
|
||||
_ = r.print("end program\n");
|
||||
return;
|
||||
}
|
||||
KeyEvent::Comand => {
|
||||
it = InputType::comand;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user