comparison examples/eclrenderer.rs @ 687:ac092b70c39a

Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 17 Aug 2019 13:49:31 +0200
parents cdb484115c5b
children 7ae576a418ff
comparison
equal deleted inserted replaced
686:aefe5b5f481e 687:ac092b70c39a
119 if ecl.subs.len() < sub as usize { 119 if ecl.subs.len() < sub as usize {
120 eprintln!("This ecl doesn’t contain a sub named {}.", sub); 120 eprintln!("This ecl doesn’t contain a sub named {}.", sub);
121 return; 121 return;
122 } 122 }
123 123
124 // TODO: seed this PRNG with a valid seed. 124 // Get the time since January 1970 as a seed for the PRNG.
125 let prng = Rc::new(RefCell::new(Prng::new(0))); 125 let time = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap();
126 let prng = Rc::new(RefCell::new(Prng::new(time.subsec_micros() as u16)));
126 127
127 // Create the Game god object. 128 // Create the Game god object.
128 let game = Game::new(prng, rank); 129 let game = Game::new(prng, rank);
129 let game = Rc::new(RefCell::new(game)); 130 let game = Rc::new(RefCell::new(game));
130 131