Making a messy text repl thing
This commit is contained in:
parent
b3bcfc5a3f
commit
2c3b08521c
@ -1,3 +1,116 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::io::{self,Write};
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let game = build_game();
|
||||
|
||||
println!("// you enter the zone");
|
||||
loop {
|
||||
print!("> ");
|
||||
io::stdout().flush();
|
||||
|
||||
match game.in_battle {
|
||||
false => {
|
||||
|
||||
let mut line = String::new();
|
||||
io::stdin().read_line(&mut line)?;
|
||||
match line.trim() {
|
||||
"help" => {
|
||||
println!("// maybe try 'loc'");
|
||||
},
|
||||
"loc" => {
|
||||
println!("// you stand at ({}, {})", game.adventurer.l.x, game.adventurer.l.y);
|
||||
},
|
||||
"step forward" => {
|
||||
let loc = game.adventurer.l;
|
||||
loc.x += 1;
|
||||
println!("// you step forward");
|
||||
for s in game.scarers.iter() {
|
||||
if (loc.x, loc.y) == (s.l.x, s.l.y) {
|
||||
println!("// oh no it's an {}", s.name)
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
println!("// what is this {}?", line.trim())
|
||||
}
|
||||
}
|
||||
},
|
||||
true => {
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_game() -> Game {
|
||||
Game {
|
||||
in_battle: false,
|
||||
zone: Zone {
|
||||
width: 4,
|
||||
depth: 4,
|
||||
},
|
||||
adventurer: Adventurer {
|
||||
name: String::from("adv"),
|
||||
h: Humors {
|
||||
health: 1000,
|
||||
attack: 1,
|
||||
critical_pct: 10,
|
||||
},
|
||||
l: Location {
|
||||
x: 0,
|
||||
y: 0,
|
||||
}
|
||||
},
|
||||
scarers: vec![
|
||||
Scarer {
|
||||
name: String::from("Blue Minotaur"),
|
||||
description: String::from("Towering half bull with flaming nostrils"),
|
||||
h: Humors {
|
||||
health: 4000,
|
||||
attack: 4,
|
||||
critical_pct: 2,
|
||||
},
|
||||
l: Location {
|
||||
x: 2,
|
||||
y: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
struct Humors {
|
||||
health: u16,
|
||||
attack: u8,
|
||||
critical_pct: u8,
|
||||
}
|
||||
|
||||
struct Location {
|
||||
x: u8,
|
||||
y: u8,
|
||||
}
|
||||
|
||||
struct Adventurer {
|
||||
name: String,
|
||||
h: Humors,
|
||||
l: Location,
|
||||
}
|
||||
|
||||
struct Scarer {
|
||||
name: String,
|
||||
description: String,
|
||||
h: Humors,
|
||||
l: Location,
|
||||
}
|
||||
|
||||
struct Zone {
|
||||
width: u8,
|
||||
depth: u8,
|
||||
}
|
||||
|
||||
struct Game {
|
||||
in_battle: bool,
|
||||
zone: Zone,
|
||||
adventurer: Adventurer,
|
||||
scarers: Vec<Scarer>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user