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

@@ -46,7 +46,7 @@ impl Distribution<Cls> for Standard {
#[derive(Debug, Default)]
struct Character {
cls: Cls,
class: Cls,
strength: u32,
dexterity: u32,
constitution: u32,
@@ -55,9 +55,19 @@ struct Character {
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 {
let mut rolls = Vec::new();
@@ -68,22 +78,14 @@ fn roll_stat() -> u32 {
}
rolls.push(roll);
}
println!("{:?}", rolls);
rolls.sort_by(|a,b| b.cmp(a));
println!("{:?}", rolls);
rolls.pop();
println!("{:?}", rolls);
rolls.iter().sum()
}

fn main() {
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);
}

Loading…
Cancel
Save