battle lib
This commit is contained in:
parent
eb84b5b934
commit
0a11d55ef7
@ -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>,
|
||||
}
|
||||
|
||||
|
||||
48
src/lib.rs
48
src/lib.rs
@ -4,36 +4,40 @@ 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),
|
||||
// };
|
||||
let r_a = &battle.a;
|
||||
let r_b = &battle.b;
|
||||
|
||||
// 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)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user