This commit is contained in:
ntr 2018-08-04 16:08:48 +10:00
commit 139eab701e
4 changed files with 98 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
target/
**/*.rs.bk
Cargo.lock

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "cryps"
version = "0.1.0"
authors = ["ntr <ntr@smokestack.io>"]
[dependencies]
rand = "0.5.4"

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# Cryps ("creeps") // Creeptography
## Stats
str agi int
items
wallet value?
gain 1 lvl per battle
## Rolling
stat & rng
block hash or totally random
friendship on ties?

73
src/lib.rs Normal file
View File

@ -0,0 +1,73 @@
extern crate rand;
use rand::prelude::*;
// items?
// stranth + stam + intel + luck?
struct Cryp {
name: String,
dmg: u64,
def: u64,
stam: u64,
}
pub struct Turn {
dmg: u64,
def: u64,
}
fn att_roll(rng: &mut ThreadRng, att: u64) -> u64 {
let roll: u64 = rng.gen();
println!("stat: {:b}", att);
println!("roll: {:b}", roll);
println!("outp: {:b}\n", att & roll);
return att & roll;
}
fn cryp_turn(mut rng: &mut ThreadRng, c: Cryp) -> Turn {
let dmg = att_roll(&mut rng, c.dmg);
let def = att_roll(&mut rng, c.def);
// att_roll(rng, c.stam);
return Turn { dmg, def }
}
fn battle(a: Cryp, b: Cryp) -> Vec<Turn> {
let mut rng = thread_rng();
let mut turns = Vec::new();
turns.push(cryp_turn(&mut rng, a));
turns.push(cryp_turn(&mut rng, b));
return turns;
}
pub fn main() -> Vec<Turn> {
let a = Cryp {
name: "pronounced \"creeep\"".to_string(),
dmg: 213213213,
def: 129435899,
stam: 342687328,
};
let b = Cryp {
name: "lemongrass tea".to_string(),
dmg: 213213213,
def: 129435899,
stam: 342687328,
};
return battle(a, b);
}
#[cfg(test)]
mod tests {
use main;
#[test]
fn it_works() {
main();
return;
}
}