Browse Source

Move functions into Character implementation

main
Noëlle 3 years ago
parent
commit
bf86aa265d
1 changed files with 16 additions and 14 deletions
  1. 16
    14
      src/main.rs

+ 16
- 14
src/main.rs View File

#[derive(Debug, Default)] #[derive(Debug, Default)]
struct Character { struct Character {
cls: Cls,
class: Cls,
strength: u32, strength: u32,
dexterity: u32, dexterity: u32,
constitution: u32, constitution: u32,
charisma: u32, charisma: u32,
} }


// impl Character {

// }
impl Character {
fn pick_class(&mut self) {
self.class = rand::random();
}
fn gen_stats(&mut self) {
self.strength = roll_stat();
self.dexterity = roll_stat();
self.constitution = roll_stat();
self.intelligence = roll_stat();
self.wisdom = roll_stat();
self.charisma = roll_stat();
}
}


fn roll_stat() -> u32 { fn roll_stat() -> u32 {
let mut rolls = Vec::new(); let mut rolls = Vec::new();
} }
rolls.push(roll); rolls.push(roll);
} }
println!("{:?}", rolls);
rolls.sort_by(|a,b| b.cmp(a)); rolls.sort_by(|a,b| b.cmp(a));
println!("{:?}", rolls);
rolls.pop(); rolls.pop();
println!("{:?}", rolls);
rolls.iter().sum() rolls.iter().sum()
} }


fn main() { fn main() {
let mut chr: Character = Default::default(); let mut chr: Character = Default::default();
chr.cls = rand::random();
chr.strength = roll_stat();
chr.dexterity = roll_stat();
chr.constitution = roll_stat();
chr.intelligence = roll_stat();
chr.wisdom = roll_stat();
chr.charisma = roll_stat();
chr.pick_class();
chr.gen_stats();
println!("{:?}", chr); println!("{:?}", chr);
} }

Loading…
Cancel
Save