diff --git a/84_Super_Star_Trek/rust/src/commands.rs b/84_Super_Star_Trek/rust/src/commands.rs index 00ab1377..d55b08ff 100644 --- a/84_Super_Star_Trek/rust/src/commands.rs +++ b/84_Super_Star_Trek/rust/src/commands.rs @@ -10,6 +10,13 @@ pub fn move_enterprise(course: u8, warp_speed: f32, galaxy: &mut Galaxy) { if galaxy.enterprise.quadrant != end.quadrant { view::enter_quadrant(&end.quadrant); + + if galaxy.quadrants[end.quadrant.as_index()].klingons.len() > 0 { + view::condition_red(); + if galaxy.enterprise.shields <= 200 { + view::danger_shields(); + } + } } galaxy.enterprise.quadrant = end.quadrant; diff --git a/84_Super_Star_Trek/rust/src/main.rs b/84_Super_Star_Trek/rust/src/main.rs index 2c1c06be..498c5bd2 100644 --- a/84_Super_Star_Trek/rust/src/main.rs +++ b/84_Super_Star_Trek/rust/src/main.rs @@ -2,8 +2,6 @@ use std::{io::{stdin, stdout, Write, Read}, process::exit, str::FromStr}; use model::Galaxy; -use crate::model::Condition; - mod model; mod commands; mod view; @@ -28,7 +26,7 @@ fn main() { _ => view::print_command_help() } - if galaxy.enterprise.condition == Condition::Destroyed { // todo: also check if stranded + if galaxy.enterprise.destroyed { // todo: also check if stranded view::end_game_failure(&galaxy); break; } @@ -50,7 +48,7 @@ fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy) { } commands::move_klingons_and_fire(galaxy); - if galaxy.enterprise.condition == Condition::Destroyed { + if galaxy.enterprise.destroyed { return; } commands::move_enterprise(course.unwrap(), speed.unwrap(), galaxy); diff --git a/84_Super_Star_Trek/rust/src/model.rs b/84_Super_Star_Trek/rust/src/model.rs index d79089dd..9caa100a 100644 --- a/84_Super_Star_Trek/rust/src/model.rs +++ b/84_Super_Star_Trek/rust/src/model.rs @@ -36,7 +36,8 @@ impl Klingon { } pub struct Enterprise { - pub condition: Condition, + pub destroyed: bool, + pub damaged: bool, // later this could be by subsystem pub quadrant: Pos, pub sector: Pos, pub photon_torpedoes: u8, @@ -45,7 +46,7 @@ pub struct Enterprise { } impl Enterprise { fn take_hit(&mut self, sector: Pos, hit_strength: u16) { - if self.condition == Condition::Destroyed { + if self.destroyed { return; } @@ -55,7 +56,7 @@ impl Enterprise { if self.shields <= 0 { view::enterprise_destroyed(); - self.condition = Condition::Destroyed; + self.destroyed = true } // report shields @@ -63,12 +64,6 @@ impl Enterprise { } } -#[derive(PartialEq, Debug)] -pub enum Condition { - Green, Yellow, Red, - Destroyed, -} - pub struct EndPosition { pub quadrant: Pos, pub sector: Pos, @@ -150,7 +145,8 @@ impl Galaxy { final_stardate: stardate + rng.gen_range(25..=35) as f32, quadrants: quadrants, enterprise: Enterprise { - condition: Condition::Green, + destroyed: false, + damaged: false, quadrant: enterprise_quadrant, sector: enterprise_sector, photon_torpedoes: 28, diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index 774505f5..320cb4eb 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -79,10 +79,16 @@ pub fn enter_quadrant(quadrant: &Pos) { pub fn short_range_scan(model: &Galaxy) { let quadrant = &model.quadrants[model.enterprise.quadrant.as_index()]; + let mut condition = "GREEN"; + if quadrant.klingons.len() > 0 { + condition = "*RED*"; + } else if model.enterprise.damaged { + condition = "YELLOW"; + } let data : [String; 8] = [ format!("Stardate {}", model.stardate), - format!("Condition {:?}", model.enterprise.condition), + format!("Condition {}", condition), format!("Quadrant {}", model.enterprise.quadrant), format!("Sector {}", model.enterprise.sector), format!("Photon torpedoes {}", model.enterprise.photon_torpedoes), @@ -151,3 +157,11 @@ pub fn hit_edge(end: &EndPosition) { Chief Engineer Scott reports, 'Warp engines shut down at sector {} of quadrant {}.'", end.quadrant, end.sector); } + +pub fn condition_red() { + println!("COMBAT AREA CONDITION RED") +} + +pub fn danger_shields() { + println!(" SHIELDS DANGEROUSLY LOW ") +} diff --git a/84_Super_Star_Trek/rust/tasks.md b/84_Super_Star_Trek/rust/tasks.md index 2b532d48..374c1a29 100644 --- a/84_Super_Star_Trek/rust/tasks.md +++ b/84_Super_Star_Trek/rust/tasks.md @@ -6,10 +6,16 @@ Started after movement and display of stats was finished (no energy management o - [x] klingon firing, game over etc - [x] add intro - [x] add entering (and starting in) sector headers -- [ ] conditions and danger messages +- [x] conditions and danger messages - [ ] remove energy on move - [ ] shields + - [ ] shield control + - [ ] shield hit absorption +- [ ] subsystem damage + - and support for reports +- [ ] lrs? - [ ] 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 +- [ ] better command reading - support entering multiple values on a line (e.g. nav 3 0.1)