battle lib

This commit is contained in:
ntr 2018-08-20 11:53:11 +10:00
parent eb84b5b934
commit 0a11d55ef7
2 changed files with 29 additions and 24 deletions

View File

@ -34,9 +34,10 @@ struct Encounter {
player: Cryp, player: Cryp,
} }
#[derive(Debug)]
pub struct Battle { pub struct Battle {
a: Cryp, pub a: Cryp,
b: Cryp, pub b: Cryp,
// winner: Option<Cryp>, // winner: Option<Cryp>,
} }

View File

@ -4,36 +4,40 @@ extern crate uuid;
mod cryp; mod cryp;
mod combat; mod combat;
use combat::{battle, levelling}; use combat::{Battle, battle, levelling};
use cryp::Cryp; use cryp::Cryp;
pub fn main() { pub fn main() {
// let a = Cryp::new() let mut a = Cryp::new()
// .named("pronounced \"creeep\"".to_string()) .named("pronounced \"creeep\"".to_string())
// .level(8) .level(8)
// .create(); .create();
// let b = Cryp::new() let mut b = Cryp::new()
// .named("lemongrass tea".to_string()) .named("lemongrass tea".to_string())
// .level(8) .level(8)
// .create(); .create();
// let battle = battle(a, b); let battle = battle(a, b);
// let b_vec = vec!(battle.0, battle.1);
// let draw = b_vec.iter().all(|c| c.hp == 0);
// if draw {
// println!("{:?} was a draw", battle);
// return;
// }
// let winner = match b_vec.iter().find(|c| c.hp > 0) { let r_a = &battle.a;
// Some(w) => w, let r_b = &battle.b;
// None => panic!("no winner found {:?}", battle),
// };
// println!("{:?} is the winner with {:?} hp remaining", winner.name, winner.hp); {
let draw = vec!(r_a, r_b).iter().all(|c| c.hp == 0);
if draw {
println!("{:?} was a draw", battle);
return;
}
}
return; let winner = match vec![r_a, r_b].iter().find(|c| c.hp > 0) {
Some(w) => *w,
None => panic!("no winner found {:?}", battle),
};
println!("{:?} is the winner with {:?} hp remaining", winner.name, winner.hp);
return
} }
#[cfg(test)] #[cfg(test)]