pub struct GameOfLife { /* private fields */ }Expand description
Class of game of life.
To create a new game of life with a grid of 25 collumns wide and 45 lines height, use :\
fn main(){
let mut game = GameOfLife::new(25, 45);
}Implementations§
Source§impl GameOfLife
impl GameOfLife
Sourcepub fn new(nb_col: usize, nb_lig: usize) -> GameOfLife
pub fn new(nb_col: usize, nb_lig: usize) -> GameOfLife
Examples found in repository?
examples/basic.rs (line 6)
5fn main(){
6 let mut g = GameOfLife::new(45, 25);
7 g.set_element(5, 5);
8 g.set_element(6, 5);
9 g.set_element(7, 5);
10 g.set_element(6, 6);
11 clear();
12 reverse();
13 loop {
14 g.show();
15 g.update();
16 refresh();
17 clear();
18 sleep(Duration::from_millis(500));
19 }
20}Sourcepub fn set_element(&mut self, i_col: usize, i_lig: usize)
pub fn set_element(&mut self, i_col: usize, i_lig: usize)
Function to set the value of an element.
For exemple, to set the element at position 5, 5 (e.g. to make the cell alive), do :
/!\ Pay attention ! : It is the collumn first, and after the line.\
fn main(){
let mut game = GameOfLife::new(25, 45);
game.set_element(5,5);
}Examples found in repository?
examples/basic.rs (line 7)
5fn main(){
6 let mut g = GameOfLife::new(45, 25);
7 g.set_element(5, 5);
8 g.set_element(6, 5);
9 g.set_element(7, 5);
10 g.set_element(6, 6);
11 clear();
12 reverse();
13 loop {
14 g.show();
15 g.update();
16 refresh();
17 clear();
18 sleep(Duration::from_millis(500));
19 }
20}Sourcepub fn unset_element(&mut self, i_col: usize, i_lig: usize)
pub fn unset_element(&mut self, i_col: usize, i_lig: usize)
Function to reset the value of an element.
For exemple, to reset the element at position 5, 5 (e.g. to kill the cell), do :
/!\ Pay attention ! : It is the collumn first, and after the line.\
fn main(){
let mut game = GameOfLife::new(25, 45);
game.unset_element(5,5);
}Sourcepub fn show(&self)
pub fn show(&self)
Function to show the actual state of the game.
For exemple :\
fn main(){
let mut game = GameOfLife::new(25, 45);
game.show();
}Examples found in repository?
examples/basic.rs (line 14)
5fn main(){
6 let mut g = GameOfLife::new(45, 25);
7 g.set_element(5, 5);
8 g.set_element(6, 5);
9 g.set_element(7, 5);
10 g.set_element(6, 6);
11 clear();
12 reverse();
13 loop {
14 g.show();
15 g.update();
16 refresh();
17 clear();
18 sleep(Duration::from_millis(500));
19 }
20}Sourcepub fn update(&mut self)
pub fn update(&mut self)
Function which update the game (e.g. pass to the next state)
For exemple :\
fn main(){
let mut game = GameOfLife::new(25, 45);
game.update();
}Examples found in repository?
examples/basic.rs (line 15)
5fn main(){
6 let mut g = GameOfLife::new(45, 25);
7 g.set_element(5, 5);
8 g.set_element(6, 5);
9 g.set_element(7, 5);
10 g.set_element(6, 6);
11 clear();
12 reverse();
13 loop {
14 g.show();
15 g.update();
16 refresh();
17 clear();
18 sleep(Duration::from_millis(500));
19 }
20}Auto Trait Implementations§
impl Freeze for GameOfLife
impl RefUnwindSafe for GameOfLife
impl Send for GameOfLife
impl Sync for GameOfLife
impl Unpin for GameOfLife
impl UnsafeUnpin for GameOfLife
impl UnwindSafe for GameOfLife
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more