Skip to content

Commit

Permalink
input prompts are > for commands and : for input requests; rework dir…
Browse files Browse the repository at this point in the history
…ections to show names not letters in game
  • Loading branch information
Zaechus committed Mar 5, 2020
1 parent f87228d commit 316ff2a
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 298 deletions.
10 changes: 7 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ impl Cli {
}

/// Prompts the user for input from stdin
pub fn prompt(prompt: &str) -> String {
pub fn prompt(&self, prompt: &str) -> String {
loop {
print!("\n{}> ", prompt);
if self.last_cmd.borrow().has_request() {
print!("\n{}: ", prompt);
} else {
print!("\n{}> ", prompt);
}
io::stdout().flush().expect("Error flushing stdout");
let input = read_line();
if !input.is_empty() {
Expand Down Expand Up @@ -108,7 +112,7 @@ Some available commands:

self.running.set(true);
while self.running.get() && self.player.borrow().is_alive() {
println!("{}", self.ask(&Cli::prompt("")));
println!("{}", self.ask(&self.prompt("")));
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/input/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ impl Lexer {
for w in words {
modified.push(
match w.as_str() {
"north" => "n",
"south" => "s",
"east" => "e",
"west" => "w",
"northeast" => "ne",
"northwest" => "nw",
"southeast" => "se",
"southwest" => "sw",
"up" => "u",
"down" => "d",
"n" => "north",
"s" => "south",
"e" => "east",
"w" => "west",
"ne" => "northeast",
"nw" => "northwest",
"se" => "southeast",
"sw" => "southwest",
"u" => "up",
"d" => "down",
_ => w,
}
.to_owned(),
Expand Down
5 changes: 2 additions & 3 deletions src/input/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ impl Parser {
pub fn parse(words: CmdTokens, world: &mut World, player: &mut Player) -> CmdResult {
if let (Some(verb), Some(short_verb)) = words.short_verb() {
match short_verb {
"n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw" | "u" | "d" => {
world.move_room(verb)
}
"north" | "south" | "east" | "west" | "northeast" | "northwest" | "southeast"
| "southwest" | "up" | "down" => world.move_room(verb),
"enter" | "go" | "move" => Parser::parse_move(verb, &words, world),
"c" | "stat" | "stats" => player.info(),
"i" | "invent" => player.print_inventory(),
Expand Down
Loading

0 comments on commit 316ff2a

Please sign in to comment.