Started C# porting git add . NOT WORKING FOR NOW

This commit is contained in:
2022-04-29 11:32:48 +02:00
commit 404c5b91a7
7 changed files with 291 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
use crate::prelude::*;
pub struct Population{
pub start_infected_ratio:u32,
pub start_immune_ratio:u32,
pub start_dead_ratio:u32,
pub humans:Vec<Human>,
pub width:u32,
pub height:u32,
pub age:u32,
pub plague:Disease,
}
pub fn human_idx(x: i32, y: i32,width:i32) -> usize {
((y * width) + x)as usize
}
impl Population{
pub fn new(start_infected_ratio:u32,start_immune_ratio:u32,start_dead_ratio:u32,width:u32,height:u32,plague:Disease)->Self{
let mut the_humans:Vec<Human>;
//filling the population
// could not use this because each human need to know his position in the vector
//humans : vec![Human::new(State::Normal, pos_x :i32, pos_y :i32); width*height],
for x in 0..width{
for y in 0..height{
the_humans[human_idx(x as i32,y as i32,width as i32)] = Human::new(State::Normal,x as i32,y as i32);
}
}
Self{
start_infected_ratio:start_infected_ratio,
start_immune_ratio:start_immune_ratio,
start_dead_ratio:start_dead_ratio,
width:width,
height:height,
plague:plague,
age:0,
humans:the_humans,
}
}
pub fn change_disease(&mut self, plague:Disease){
self.plague = plague;
}
}