commit - d51286b2d1ea4f5be109ed6d76f006a0637d1873
commit + bf48b47d5f7b3c94484d833b43da334c5b8ac6be
blob - d1869cad1aa3259156b8583bad330c18cee625ce
blob + c79ab0248454c36a668a6ff3b50011c45a8aac83
--- Cargo.toml
+++ Cargo.toml
log = "0.4.14"
env_logger = "0.9.0"
rustyline = "9.0.0"
+rand = "0.8.4"
blob - 5fbe349ec64c01c5da245119913a5f43f9972142
blob + 44452112f6fe039d5cf84def7891feeea278123c
--- src/main.rs
+++ src/main.rs
use std::env;
mod character;
+mod rolls;
pub use character::Character;
impl Game {
fn execute_command(&mut self) {
match self.command.as_str() {
+ "oracle" => println!("<{}>", rolls::d100()),
+ "challenge" => println!("<{}>", rolls::d10()),
"q" => self.shutdown(),
_ => println!("Unkown command"),
}
}
fn load_history(&mut self) {
- let hp = self.sfpath.push_str("history");
- if self.rl.load_history(hp).is_err() {
- println!("No previous history.");
+ let hp = self.sfpath.clone() + "history";
+ if self.rl.load_history(&hp).is_err() {
+ log::info!("No previous history.");
}
}
fn shutdown(&mut self) {
- self.rl.save_history("history").unwrap();
+ let hp = self.sfpath.clone() + "history";
+ self.rl.save_history(&hp).unwrap();
std::process::exit(0)
}
match readline {
Ok(line) => {
game.rl.add_history_entry(line.as_str());
- println!("Line: {}", line);
game.command = line.to_string();
game.execute_command();
},
Err(ReadlineError::Interrupted) => {
- println!("CTRL-C");
break
},
Err(ReadlineError::Eof) => {
- println!("CTRL-D");
break
},
Err(err) => {
blob - /dev/null
blob + 40ae66cde2bb24e2f51e173a708ecb32d57a7d1f (mode 644)
--- /dev/null
+++ src/rolls.rs
+use rand::Rng;
+
+pub fn d100() -> i32 {
+ let mut rng = rand::thread_rng();
+ rng.gen_range(0..101)
+}
+
+pub fn d10() -> i32 {
+ let mut rng = rand::thread_rng();
+ rng.gen_range(1..11)
+}
+
+pub fn d6() -> i32 {
+ let mut rng = rand::thread_rng();
+ rng.gen_range(1..7)
+}