From 050765e89f084d2f0e6fb470ebe31a92772403b8 Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 6 Mar 2023 09:37:45 +1300 Subject: [PATCH] minor bug fix for 0 path trying to exit the perimeter --- 84_Super_Star_Trek/rust/src/commands.rs | 7 +++++++ 84_Super_Star_Trek/rust/src/view.rs | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/84_Super_Star_Trek/rust/src/commands.rs b/84_Super_Star_Trek/rust/src/commands.rs index d2eefc61..c1c4bc8d 100644 --- a/84_Super_Star_Trek/rust/src/commands.rs +++ b/84_Super_Star_Trek/rust/src/commands.rs @@ -151,6 +151,13 @@ fn move_enterprise(course: f32, warp_speed: f32, galaxy: &mut Galaxy) { } } + if path.len() == 0 { + if hit_edge { + view::hit_edge(ship.quadrant, ship.sector); + } + return; + } + let energy_cost = path.len() as u16 + 10; if energy_cost > ship.total_energy { diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index c276dee2..caf6b74d 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -199,7 +199,7 @@ pub fn intro(model: &Galaxy) { "Your orders are as follows: Destroy the {} Klingon warships which have invaded the galaxy before they can attack federation headquarters - on stardate {}. This gives you {} days. {} in the galaxy for resupplying your ship.\n", + on stardate {:.1}. This gives you {} days. {} in the galaxy for resupplying your ship.\n", model.remaining_klingons(), model.final_stardate, model.final_stardate - model.stardate, star_base_message) } @@ -253,7 +253,7 @@ pub fn short_range_scan(model: &Galaxy) { } let data : [String; 8] = [ - format!("Stardate {}", model.stardate), + format!("Stardate {:.1}", model.stardate), format!("Condition {}", condition), format!("Quadrant {}", model.enterprise.quadrant), format!("Sector {}", model.enterprise.sector), @@ -300,7 +300,7 @@ pub fn print_command_help() { pub fn end_game_failure(galaxy: &Galaxy) { println!( -"Is is stardate {}. +"Is is stardate {:.1}. There were {} Klingon battle cruisers left at the end of your mission. ", galaxy.stardate, galaxy.remaining_klingons()); @@ -519,7 +519,7 @@ pub fn starbase_shields() { pub fn repair_estimate(repair_time: f32) { println!( "Technicians standing by to effect repairs to your ship; -Estimated time to repair: {repair_time} stardates.") +Estimated time to repair: {repair_time:.1} stardates.") } pub fn no_damage(sector: Pos) { @@ -613,7 +613,7 @@ pub fn status_report(galaxy: &Galaxy) { println!(" Status report: Klingons left: {klingon_count} -Mission must be completed in {time_remaining} stardates. +Mission must be completed in {time_remaining:.1} stardates. The Federation is maintaining {star_bases} starbase{plural_starbase} in the galaxy. ") }