From 2feb1a9c6532cd4c3dcbb93aa45aefc513989fad Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 2 Mar 2023 11:37:58 +1300 Subject: [PATCH] implemented setting shields --- 84_Super_Star_Trek/rust/src/main.rs | 22 ++++++++++++++++++++++ 84_Super_Star_Trek/rust/src/view.rs | 17 +++++++++++++++++ 84_Super_Star_Trek/rust/tasks.md | 6 +++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/84_Super_Star_Trek/rust/src/main.rs b/84_Super_Star_Trek/rust/src/main.rs index 4212c6a7..477a0594 100644 --- a/84_Super_Star_Trek/rust/src/main.rs +++ b/84_Super_Star_Trek/rust/src/main.rs @@ -27,6 +27,7 @@ fn main() { match command[0].to_uppercase().as_str() { "SRS" => view::short_range_scan(&galaxy), "NAV" => gather_dir_and_speed_then_move(&mut galaxy, command[1..].into()), + "SHE" => get_amount_and_set_shields(&mut galaxy, command[1..].into()), _ => view::print_command_help() } @@ -37,6 +38,27 @@ fn main() { } } +fn get_amount_and_set_shields(galaxy: &mut Galaxy, provided: Vec) { + + // todo check for damaged module + + view::energy_available(galaxy.enterprise.total_energy); + let value = param_or_prompt_value(&provided, 0, "Number of units to shields", 0, i32::MAX); + if value.is_none() { + view::shields_unchanged(); + return; + } + let value = value.unwrap() as u16; + if value > galaxy.enterprise.total_energy { + view::ridiculous(); + view::shields_unchanged(); + return; + } + + galaxy.enterprise.shields = value; + view::shields_set(value); +} + fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy, provided: Vec) { let course = param_or_prompt_value(&provided, 0, "Course (1-9)?", 1, 9); diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index f460eaa7..95cad41d 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -174,3 +174,20 @@ pub fn insuffient_warp_energy(warp_speed: f32) { pub fn divert_energy_from_shields() { println!("Shield Control supplies energy to complete the maneuver.") } + +pub fn energy_available(total_energy: u16) { + println!("Energy available = {{{total_energy}}}") +} + +pub fn shields_unchanged() { + println!("") +} + +pub fn ridiculous() { + println!("Shield Control reports, 'This is not the Federation Treasury.'") +} + +pub fn shields_set(value: u16) { + println!("Deflector control room report: + 'Shields now at {value} units per your command.'") +} diff --git a/84_Super_Star_Trek/rust/tasks.md b/84_Super_Star_Trek/rust/tasks.md index da2b9c1b..7c7e1df8 100644 --- a/84_Super_Star_Trek/rust/tasks.md +++ b/84_Super_Star_Trek/rust/tasks.md @@ -7,9 +7,9 @@ Started after movement and display of stats was finished (no energy management o - [x] add intro - [x] add entering (and starting in) sector headers - [x] conditions and danger messages -- [ ] remove energy on move -- [ ] shields - - [ ] shield control +- [x] remove energy on move +- [x] shields + - [x] shield control - [ ] shield hit absorption - [ ] subsystem damage - and support for reports