From d973dec62d26e0688dd548ad32d0feb7c0f57440 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 5 Mar 2023 14:09:28 +1300 Subject: [PATCH] implemented klongon data, final computer program --- 84_Super_Star_Trek/rust/src/commands.rs | 20 ++++++++++++++++++-- 84_Super_Star_Trek/rust/src/view.rs | 8 ++++++++ 84_Super_Star_Trek/rust/tasks.md | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/84_Super_Star_Trek/rust/src/commands.rs b/84_Super_Star_Trek/rust/src/commands.rs index 2848b039..2bc28da8 100644 --- a/84_Super_Star_Trek/rust/src/commands.rs +++ b/84_Super_Star_Trek/rust/src/commands.rs @@ -312,14 +312,30 @@ pub fn access_computer(galaxy: &Galaxy, provided: Vec) { view::status_report(galaxy); run_damage_control(galaxy); }, - 3 => show_starbase_data(galaxy), + 2 => show_klingon_direction_data(galaxy), + 3 => show_starbase_direction_data(galaxy), 4 => direction_dist_calculator(galaxy), 5 => view::galaxy_region_map(), _ => todo!() // todo implement others } } -fn show_starbase_data(galaxy: &Galaxy) { +fn show_klingon_direction_data(galaxy: &Galaxy) { + let quadrant = &galaxy.quadrants[galaxy.enterprise.quadrant.as_index()]; + if quadrant.klingons.len() == 0 { + view::no_local_enemies(); + return; + } + + view::klingon_report(quadrant.klingons.len() > 1); + let origin = galaxy.enterprise.sector; + for k in &quadrant.klingons { + let target = k.sector; + view::direction_distance(origin.direction(target), origin.dist(target)) + } +} + +fn show_starbase_direction_data(galaxy: &Galaxy) { let quadrant = &galaxy.quadrants[galaxy.enterprise.quadrant.as_index()]; match &quadrant.star_base { None => { diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index 282e6dc4..7e8aa399 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -620,4 +620,12 @@ pub fn direction_dist_intro(enterprise: &Enterprise) { println!("Direction/distance calculator: You are at quadrant {quadrant} sector {sector} Please enter") +} + +pub fn klingon_report(more_than_one: bool) { + let mut plural = ""; + if more_than_one { + plural = "s"; + } + println!("From Enterprise to Klingon battle cruiser{}", plural) } \ No newline at end of file diff --git a/84_Super_Star_Trek/rust/tasks.md b/84_Super_Star_Trek/rust/tasks.md index 1871b317..c4406208 100644 --- a/84_Super_Star_Trek/rust/tasks.md +++ b/84_Super_Star_Trek/rust/tasks.md @@ -28,10 +28,10 @@ Started after movement and display of stats was finished (no energy management o - [x] weapons - [x] phasers - [x] torpedoes -- [ ] computer +- [x] computer - [x] 0 - output of all short and long range scans (requires tracking if a system has been scanned) - [x] 1 - klingons, starbases, stardate and damage control - - [ ] 2 - photon torpedo data: direction and distance to all local klingons + - [x] 2 - photon torpedo data: direction and distance to all local klingons - [x] 3 - starbase distance and dir locally - [x] 4 - direction/distance calculator (useful for nav actions I guess) - [x] 5 - galactic name map