| 70 | } |
| 71 | |
| 72 | fn main() { |
| 73 | let mut current_room = Room::new(vec!["banana", "chair", "piano"].into_iter()); |
| 74 | let mut character = Character::new(); |
| 75 | let valid_chants = vec!["team", "wildcats"]; |
| 76 | |
| 77 | let stdin = io::stdin(); |
| 78 | loop { |
| 79 | print!("What are you doing next? "); |
| 80 | io::stdout().flush().unwrap(); |
| 81 | let mut command = String::new(); |
| 82 | stdin.lock().read_line(&mut command).unwrap(); |
| 83 | let elems: Vec<&str> = command.split_whitespace().collect(); |
| 84 | println!("{:?}", &elems); |
| 85 | match &elems[..] { |
| 86 | ["quit"] => { |
| 87 | println!("Good bye!"); |
| 88 | break; |
| 89 | } |
| 90 | ["look"] => current_room.describe(), |
| 91 | ["look", "backpack"] => println!("in backpack {:?}", character.backpack), |
| 92 | ["take", obj] => character.take(obj.to_string(), &mut current_room), |
| 93 | ["drop", objects @ ..] => { |
| 94 | for obj in objects { |
| 95 | character.drop(obj.to_string(), &mut current_room); |
| 96 | } |
| 97 | } |
| 98 | ["go", direction] => current_room = current_room.neighbor(direction), |
| 99 | ["go", direction @ ("north" | "south" | "east" | "west")] => { |
| 100 | current_room = current_room.neighbor(direction) |
| 101 | } |
| 102 | ["go", chant] if valid_chants.contains(chant) => { |
| 103 | println!("YEAH, GOOOOO {}", chant.to_uppercase()) |
| 104 | } |
| 105 | _ => println!("dunno"), |
| 106 | } |
| 107 | } |
| 108 | } |