✅ test joke ending
							parent
							
								
									6630002a34
								
							
						
					
					
						commit
						d40e6a83f7
					
				
							
								
								
									
										27
									
								
								src/main.rs
								
								
								
								
							
							
						
						
									
										27
									
								
								src/main.rs
								
								
								
								
							|  | @ -185,6 +185,7 @@ struct StateRoom1 { | |||
| 	detected_note: bool, | ||||
| } | ||||
| 
 | ||||
| #[derive (PartialEq)] | ||||
| enum Response { | ||||
| 	Print (String), | ||||
| 	PrintMany (Vec <&'static str>), | ||||
|  | @ -199,12 +200,12 @@ struct State { | |||
| } | ||||
| 
 | ||||
| impl State { | ||||
| 	fn room_1 (&mut self, input: String) -> Result <Vec <Response>> { | ||||
| 	fn room_1 (&mut self, input: &str) -> Vec <Response> { | ||||
| 		use Response::*; | ||||
| 		
 | ||||
| 		let action = parse_input (&input); | ||||
| 		let action = parse_input (input); | ||||
| 		
 | ||||
| 		Ok (match action { | ||||
| 		match action { | ||||
| 			PlayerAction::Quit => { | ||||
| 				vec! [ | ||||
| 					line_response ("Bye."), | ||||
|  | @ -240,16 +241,16 @@ impl State { | |||
| 					}, | ||||
| 					ItemName::Keypad => { | ||||
| 						if ! self.room_1.detected_keypad { | ||||
| 							return Ok (just (undetected_item ())); | ||||
| 							return just (undetected_item ()); | ||||
| 						} | ||||
| 						
 | ||||
| 						just (line_response ("The DOOR is locked by an electronic KEYPAD. A soft amber power light indicates that the KEYPAD is likely functional. The KEYPAD buttons are the digits 0-9, Enter, and Clear. Experience tells you that the key code is likely 4 or 5 digits long.")) | ||||
| 					}, | ||||
| 					ItemName::Note => { | ||||
| 						if ! self.room_1.detected_note { | ||||
| 							return Ok (vec! [ | ||||
| 							return vec! [ | ||||
| 								undetected_item (), | ||||
| 							]); | ||||
| 							]; | ||||
| 						} | ||||
| 						
 | ||||
| 						just (Response::PrintMany (vec! [ | ||||
|  | @ -314,7 +315,7 @@ impl State { | |||
| 					}, | ||||
| 				} | ||||
| 			}, | ||||
| 		}) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -343,7 +344,7 @@ fn game () -> Result <()> { | |||
| 	
 | ||||
| 	'main_loop: loop { | ||||
| 		let input = read_input ()?; | ||||
| 		let responses = state.room_1 (input)?; | ||||
| 		let responses = state.room_1 (&input); | ||||
| 		
 | ||||
| 		for response in responses.into_iter () { | ||||
| 			match response { | ||||
|  | @ -395,6 +396,16 @@ mod test { | |||
| 	
 | ||||
| 	#[test] | ||||
| 	fn joke_ending () { | ||||
| 		use super::{ | ||||
| 			Response, | ||||
| 			State, | ||||
| 		}; | ||||
| 		
 | ||||
| 		let mut state = State::default (); | ||||
| 		
 | ||||
| 		let responses = state.room_1 ("use emergency exit"); | ||||
| 		
 | ||||
| 		assert! (responses.contains (&Response::Quit)); | ||||
| 		assert! (responses.contains (&Response::JokeEnding)); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 _
						_