review: change Die to enum to handle range and value list in the future
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
use crate::*;
|
||||
|
||||
impl Die {
|
||||
pub fn new(sides: u16) -> Self {
|
||||
Self { sides }
|
||||
}
|
||||
}
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod unit_tests { use super::*; }
|
||||
@@ -2,7 +2,12 @@ use crate::*;
|
||||
|
||||
impl Die {
|
||||
pub fn roll(&self) -> i32 {
|
||||
let mut rng = rand::rng();
|
||||
rng.random_range(1..=self.sides) as i32
|
||||
fn roll_sides(sides: u16) -> i32 {
|
||||
let mut rng = rand::rng();
|
||||
rng.random_range(1..=sides) as i32
|
||||
}
|
||||
match self {
|
||||
Die::Sides(sides) => roll_sides(*sides),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ impl Handful {
|
||||
pub fn grab(dice_num: u16, sides: u16) -> Self {
|
||||
let mut dice = Vec::<Die>::new();
|
||||
for _ in 1..=dice_num {
|
||||
dice.push(Die::new(sides));
|
||||
dice.push(Die::Sides(sides));
|
||||
}
|
||||
Self { dice }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod die_new;
|
||||
pub mod die_roll;
|
||||
pub mod handful_grab;
|
||||
pub mod handful_roll;
|
||||
|
||||
Reference in New Issue
Block a user