Browse Source

Starting to build characters

main
Noëlle 3 years ago
parent
commit
763cbde59d
3 changed files with 89 additions and 1 deletions
  1. 1
    0
      .gitignore
  2. 1
    0
      Cargo.toml
  3. 87
    1
      src/main.rs

+ 1
- 0
.gitignore View File

@@ -1 +1,2 @@
/target
Cargo.lock

+ 1
- 0
Cargo.toml View File

@@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.3"

+ 87
- 1
src/main.rs View File

@@ -1,3 +1,89 @@
use rand::{ distributions:: {Distribution, Standard},
Rng
};

#[derive(Debug)]
enum Cls {
Artificer,
Barbarian,
Bard,
Cleric,
Druid,
Fighter,
Monk,
Paladin,
Ranger,
Rogue,
Sorcerer,
Warlock,
Wizard
}

impl Default for Cls {
fn default() -> Self { Cls::Fighter }
}

impl Distribution<Cls> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cls {
match rng.gen_range(0..=12) {
0 => Cls::Artificer,
1 => Cls::Barbarian,
2 => Cls::Bard,
3 => Cls::Cleric,
4 => Cls::Druid,
5 => Cls::Fighter,
6 => Cls::Monk,
7 => Cls::Paladin,
8 => Cls::Ranger,
9 => Cls::Rogue,
10 => Cls::Sorcerer,
11 => Cls::Warlock,
12 => Cls::Wizard,
_ => Cls::Fighter
}
}
}
#[derive(Debug, Default)]
struct Character {
cls: Cls,
strength: u32,
dexterity: u32,
constitution: u32,
intelligence: u32,
wisdom: u32,
charisma: u32,
}

// impl Character {

// }

fn roll_stat() -> u32 {
let mut rolls = Vec::new();
while rolls.len()<4 {
let roll = rand::thread_rng().gen_range(1..=6);
if roll == 1 {
continue;
}
rolls.push(roll);
}
println!("{:?}", rolls);
rolls.sort_by(|a,b| b.cmp(a));
println!("{:?}", rolls);
rolls.pop();
println!("{:?}", rolls);
rolls.iter().sum()
}

fn main() {
println!("Hello, world!");
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();
println!("{:?}", chr);
}

Loading…
Cancel
Save