check dead state

This commit is contained in:
2022-05-03 13:48:32 +02:00
parent eccb238f5e
commit 5eddad02ee
+23 -19
View File
@@ -167,6 +167,7 @@ impl Population{
// ##@
}
};
println!("{} to infect, {} to cure, {} to kill", people_to_infect.len(), people_to_cure.len(), people_to_kill.len());
for infected_position in &people_to_infect {
// println!("To infect: {:?}", infected_position);
//people_to_infect.iter().map(|infected_position|{
@@ -190,9 +191,12 @@ impl Population{
for dead_position in &people_to_kill {
//people_to_kill.iter().map(|dead_position|{
let dead_index = human_idx(dead_position.x, dead_position.y, self.width);
self.humans[dead_index].present_state = State::Dead;
if self.humans[dead_index].present_state == State::Dead {
println!("Already dead");
} else {
self.humans[dead_index].present_state = State::Dead;
}
//DEBUG
//println!("Killed someone");
};
stats
}
@@ -200,21 +204,21 @@ impl Population{
let mut rng = rand::thread_rng();
rng.gen_range(0..CORRECTED_PERCENTAGE) <= probability as i32
}
pub fn display(&mut self){
let sprite = "#";
print!("\n");
for x in 0..self.width{
for y in 0..self.height{
let index = human_idx(x as i32,y as i32,self.width as i32);
match self.humans[index].present_state {
State::Normal => print!("{}",style(sprite).green()),
State::Dead => print!("{}",style(sprite).black()),
State::Infected => print!("{}",style(sprite).red()),
State::Immune => print!("{}",style(sprite).blue()),
_ => print!("{}",style(sprite).white()),
}
}
print!("\n");
}
}
// pub fn display(&mut self){
// let sprite = "#";
// print!("\n");
// for x in 0..self.width{
// for y in 0..self.height{
// let index = human_idx(x as i32,y as i32,self.width as i32);
// match self.humans[index].present_state {
// State::Normal => print!("{}",style(sprite).green()),
// State::Dead => print!("{}",style(sprite).black()),
// State::Infected => print!("{}",style(sprite).red()),
// State::Immune => print!("{}",style(sprite).blue()),
// _ => print!("{}",style(sprite).white()),
// }
// }
// print!("\n");
// }
// }
}