From 2360bfd0c2dd869025a4ff46490852178f785ac7 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 2 Mar 2023 19:08:21 +1300 Subject: [PATCH] implemented getting stranded --- 84_Super_Star_Trek/rust/src/main.rs | 2 +- 84_Super_Star_Trek/rust/src/model.rs | 8 ++++++++ 84_Super_Star_Trek/rust/src/view.rs | 6 ++++++ 84_Super_Star_Trek/rust/tasks.md | 5 +++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/84_Super_Star_Trek/rust/src/main.rs b/84_Super_Star_Trek/rust/src/main.rs index fd01b9b5..385d122c 100644 --- a/84_Super_Star_Trek/rust/src/main.rs +++ b/84_Super_Star_Trek/rust/src/main.rs @@ -34,7 +34,7 @@ fn main() { _ => view::print_command_help() } - if galaxy.enterprise.destroyed { // todo: also check if stranded + if galaxy.enterprise.destroyed || galaxy.enterprise.check_stranded() { view::end_game_failure(&galaxy); // todo check if can restart break; diff --git a/84_Super_Star_Trek/rust/src/model.rs b/84_Super_Star_Trek/rust/src/model.rs index a55eb62f..f231124c 100644 --- a/84_Super_Star_Trek/rust/src/model.rs +++ b/84_Super_Star_Trek/rust/src/model.rs @@ -93,6 +93,14 @@ impl Enterprise { self.damaged.entry(system.to_string()).and_modify(|d| *d += amount); return false; } + + pub fn check_stranded(&self) -> bool { + if self.total_energy < 10 || (self.total_energy - self.shields < 10 && self.damaged.contains_key(systems::SHIELD_CONTROL)) { + view::stranded(); + return true; + } + return false; + } } pub mod systems { diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index 26daf070..fc4a4735 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -251,3 +251,9 @@ pub fn long_range_scan(galaxy: &Galaxy) { println!("{:-^19}", ""); } } + +pub fn stranded() { + println!("** FATAL ERROR ** You've just stranded your ship in space +You have insufficient maneuvering energy, and shield control +is presently incapable of cross-circuiting to engine room!!") +} diff --git a/84_Super_Star_Trek/rust/tasks.md b/84_Super_Star_Trek/rust/tasks.md index 8dd2d166..a2729d9b 100644 --- a/84_Super_Star_Trek/rust/tasks.md +++ b/84_Super_Star_Trek/rust/tasks.md @@ -14,8 +14,8 @@ Started after movement and display of stats was finished (no energy management o - [x] subsystem damage - [x] and support for reports - [x] random system damage or repairs on move -- [ ] lrs? -- [ ] stranded... +- [x] lrs? +- [x] stranded... - [ ] stop before hitting an object - when moving across a sector, the enterprise should stop before it runs into something - the current move is a jump, which makes this problematic. would need to rewrite it @@ -29,3 +29,4 @@ Started after movement and display of stats was finished (no energy management o - [ ] restarting the game - [ ] time progression - check all areas where time should move, and adjust accordingly +- [ ] intro instructions