Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Orlha committed Oct 14, 2019
1 parent 119b9f6 commit f0c1a80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl Display for Cell {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
writeln!(f, " id: {}", self.id)?;
writeln!(f, " pos: {} {}", self.pos.x, self.pos.y)?;
writeln!(f, " nrg: {}", self.energy)?;
write! (f, "tape: {:02X?}", self.tape)
}
}
Expand Down Expand Up @@ -57,7 +58,17 @@ impl Cell {
Ok(r)
}
pub fn gain_energy(&mut self, n: i64) {
self.energy += n;
let mut energy: &mut i64 = &mut self.energy;
if *energy == 0 { return; }
*energy += n;
if *energy < 0 {
*energy = 0;
return;
}
if *energy > 100 {
*energy = 100;
return;
}
}
pub fn alive(&self) -> bool {
self.alive
Expand Down
1 change: 1 addition & 0 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl Game {
let cmd = cell.get_cmd().unwrap();
Game::cell_tick(&mut self.map, cell, cmd);
cell.gain_energy(-1);
println!("{}", cell);
}
}
println!("Processed {} cells;", x);
Expand Down

0 comments on commit f0c1a80

Please sign in to comment.