diff --git a/84_Super_Star_Trek/rust/src/commands.rs b/84_Super_Star_Trek/rust/src/commands.rs index 0675ee4f..86c72f98 100644 --- a/84_Super_Star_Trek/rust/src/commands.rs +++ b/84_Super_Star_Trek/rust/src/commands.rs @@ -1,7 +1,7 @@ -use crate::{model::{Galaxy, Pos, COURSES, EndPosition}, view, input}; +use crate::{model::{Galaxy, Pos, COURSES, EndPosition, self}, view, input}; pub fn perform_short_range_scan(galaxy: &Galaxy) { - if galaxy.enterprise.damaged.contains_key(view::keys::SHORT_RANGE_SCAN) { + if galaxy.enterprise.damaged.contains_key(model::systems::SHORT_RANGE_SCAN) { view::scanners_out(); return; } @@ -11,7 +11,7 @@ pub fn perform_short_range_scan(galaxy: &Galaxy) { pub fn get_amount_and_set_shields(galaxy: &mut Galaxy, provided: Vec) { - if galaxy.enterprise.damaged.contains_key(view::keys::SHIELD_CONTROL) { + if galaxy.enterprise.damaged.contains_key(model::systems::SHIELD_CONTROL) { view::inoperable("Shield Control"); return; } @@ -45,7 +45,7 @@ pub fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy, provided: Vec let course = course.unwrap(); let mut max_warp = 8.0; - if galaxy.enterprise.damaged.contains_key(view::keys::NAVIGATION) { + if galaxy.enterprise.damaged.contains_key(model::systems::WARP_ENGINES) { max_warp = 0.2; } @@ -77,8 +77,6 @@ fn move_enterprise(course: u8, warp_speed: f32, galaxy: &mut Galaxy) { let end = find_end_quadrant_sector(ship.quadrant, ship.sector, course, warp_speed); - // todo account for engine damage - if end.energy_cost > ship.total_energy { view::insuffient_warp_energy(warp_speed); return diff --git a/84_Super_Star_Trek/rust/src/main.rs b/84_Super_Star_Trek/rust/src/main.rs index ecde0476..5db8350c 100644 --- a/84_Super_Star_Trek/rust/src/main.rs +++ b/84_Super_Star_Trek/rust/src/main.rs @@ -26,9 +26,9 @@ fn main() { continue; } match command[0].to_uppercase().as_str() { - view::keys::SHORT_RANGE_SCAN => commands::perform_short_range_scan(&galaxy), - view::keys::NAVIGATION => commands::gather_dir_and_speed_then_move(&mut galaxy, command[1..].into()), - view::keys::SHIELD_CONTROL => commands::get_amount_and_set_shields(&mut galaxy, command[1..].into()), + model::systems::SHORT_RANGE_SCAN => commands::perform_short_range_scan(&galaxy), + model::systems::WARP_ENGINES => commands::gather_dir_and_speed_then_move(&mut galaxy, command[1..].into()), + model::systems::SHIELD_CONTROL => commands::get_amount_and_set_shields(&mut galaxy, command[1..].into()), _ => view::print_command_help() } diff --git a/84_Super_Star_Trek/rust/src/model.rs b/84_Super_Star_Trek/rust/src/model.rs index a078df05..f46cc548 100644 --- a/84_Super_Star_Trek/rust/src/model.rs +++ b/84_Super_Star_Trek/rust/src/model.rs @@ -64,6 +64,16 @@ impl Enterprise { } } +pub mod systems { + pub const SHORT_RANGE_SCAN: &str = "SRS"; + pub const WARP_ENGINES: &str = "NAV"; + pub const SHIELD_CONTROL: &str = "SHE"; + + pub const ALL: [&str; 3] = [ + SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL + ]; +} + pub struct EndPosition { pub quadrant: Pos, pub sector: Pos, diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index 68934549..e7bc5516 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -1,15 +1,5 @@ use crate::model::{Galaxy, Pos, EndPosition, SectorStatus}; -pub mod keys { - pub const SHORT_RANGE_SCAN: &str = "SRS"; - pub const NAVIGATION: &str = "NAV"; - pub const SHIELD_CONTROL: &str = "SHE"; - - pub const ALL_SYSTEMS: [&str; 3] = [ - SHORT_RANGE_SCAN, NAVIGATION, SHIELD_CONTROL - ]; -} - pub fn enterprise() { println!("