mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-01 07:27:55 -08:00
init
This commit is contained in:
17
30_Cube/rust/src/game.rs
Normal file
17
30_Cube/rust/src/game.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
pub type Position = (u8, u8, u8);
|
||||
|
||||
pub struct Game {
|
||||
wallet: u8,
|
||||
bet: u8,
|
||||
landmines: Vec<Position>,
|
||||
player: Position,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn new() -> Self {
|
||||
let mut landmines = Vec::new();
|
||||
|
||||
let mut m: Position = (0, 0, 0);
|
||||
while !landmines.contains(&m) {}
|
||||
}
|
||||
}
|
||||
6
30_Cube/rust/src/main.rs
Normal file
6
30_Cube/rust/src/main.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
mod game;
|
||||
mod util;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
23
30_Cube/rust/src/util.rs
Normal file
23
30_Cube/rust/src/util.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
pub fn get_random_position() -> crate::game::Position {
|
||||
(get_random_axis(), get_random_axis(), get_random_axis())
|
||||
}
|
||||
|
||||
fn get_random_axis() -> u8 {
|
||||
rand::Rng::gen_range(&mut rand::thread_rng(), 1..=3)
|
||||
}
|
||||
|
||||
pub fn prompt(yes_no: bool, msg: &str) -> (u8, bool) {
|
||||
loop {
|
||||
let mut input = String::new();
|
||||
std::io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("~~Failed reading line!~~");
|
||||
let input = input.trim();
|
||||
|
||||
if yes_no {
|
||||
if let Ok(n) = input.parse::<u8>(){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user