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,
}
#[derive(Debug)]
pub struct Battle {
a: Cryp,
b: Cryp,
pub a: Cryp,
pub b: Cryp,
// winner: Option<Cryp>,
}

View File

@ -4,37 +4,41 @@ extern crate uuid;
mod cryp;
mod combat;
use combat::{battle, levelling};
use combat::{Battle, battle, levelling};
use cryp::Cryp;
pub fn main() {
// let a = Cryp::new()
// .named("pronounced \"creeep\"".to_string())
// .level(8)
// .create();
let mut a = Cryp::new()
.named("pronounced \"creeep\"".to_string())
.level(8)
.create();
// let b = Cryp::new()
// .named("lemongrass tea".to_string())
// .level(8)
// .create();
let mut b = Cryp::new()
.named("lemongrass tea".to_string())
.level(8)
.create();
// 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 battle = battle(a, b);
// let winner = match b_vec.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);
let r_a = &battle.a;
let r_b = &battle.b;
{
let draw = vec!(r_a, r_b).iter().all(|c| c.hp == 0);
if draw {
println!("{:?} was a draw", battle);
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)]
mod tests {