From 134b17f77e1feb2bc5d1f56452605d69fc9b5490 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 2 Mar 2023 19:59:57 +1300 Subject: [PATCH] implemented computer with region map --- 84_Super_Star_Trek/rust/src/commands.rs | 31 ++++- 84_Super_Star_Trek/rust/src/main.rs | 1 + 84_Super_Star_Trek/rust/src/model.rs | 6 +- 84_Super_Star_Trek/rust/src/view.rs | 166 ++++++++++++++++++++++-- 84_Super_Star_Trek/rust/tasks.md | 9 ++ 5 files changed, 194 insertions(+), 19 deletions(-) diff --git a/84_Super_Star_Trek/rust/src/commands.rs b/84_Super_Star_Trek/rust/src/commands.rs index 099b5496..db3d4a32 100644 --- a/84_Super_Star_Trek/rust/src/commands.rs +++ b/84_Super_Star_Trek/rust/src/commands.rs @@ -14,7 +14,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(model::systems::SHIELD_CONTROL) { - view::inoperable("Shield Control"); + view::inoperable(&systems::name_for(systems::SHIELD_CONTROL)); return; } @@ -204,7 +204,7 @@ fn move_klingons_and_fire(galaxy: &mut Galaxy) { pub fn display_damage_control(enterprise: &Enterprise) { if enterprise.damaged.contains_key(model::systems::DAMAGE_CONTROL) { - view::inoperable("Damage Control"); + view::inoperable(&systems::name_for(systems::DAMAGE_CONTROL)); return; } @@ -217,10 +217,33 @@ pub fn display_damage_control(enterprise: &Enterprise) { } pub fn perform_long_range_scan(galaxy: &Galaxy) { - if galaxy.enterprise.damaged.contains_key(model::systems::SHORT_RANGE_SCAN) { - view::inoperable("Long Range Scanners"); + if galaxy.enterprise.damaged.contains_key(model::systems::LONG_RANGE_SCAN) { + view::inoperable(&systems::name_for(systems::LONG_RANGE_SCAN)); return; } view::long_range_scan(galaxy); +} + +pub fn access_computer(galaxy: &Galaxy, provided: Vec) { + if galaxy.enterprise.damaged.contains_key(model::systems::COMPUTER) { + view::inoperable(&systems::name_for(systems::COMPUTER)); + return; + } + + let operation : i32; + loop { + let entered = input::param_or_prompt_value(&provided, 0, "Computer active and waiting command?", 0, 5); + if entered.is_none() { + view::computer_options(); + } else { + operation = entered.unwrap(); + break; + } + } + + match operation { + 5 => view::galaxy_region_map(), + _ => todo!() // todo implement others + } } \ No newline at end of file diff --git a/84_Super_Star_Trek/rust/src/main.rs b/84_Super_Star_Trek/rust/src/main.rs index 385d122c..f7db0845 100644 --- a/84_Super_Star_Trek/rust/src/main.rs +++ b/84_Super_Star_Trek/rust/src/main.rs @@ -31,6 +31,7 @@ fn main() { model::systems::SHIELD_CONTROL => commands::get_amount_and_set_shields(&mut galaxy, command[1..].into()), model::systems::DAMAGE_CONTROL => commands::display_damage_control(&galaxy.enterprise), model::systems::LONG_RANGE_SCAN => commands::perform_long_range_scan(&galaxy), + model::systems::COMPUTER => commands::access_computer(&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 f231124c..549031db 100644 --- a/84_Super_Star_Trek/rust/src/model.rs +++ b/84_Super_Star_Trek/rust/src/model.rs @@ -110,9 +110,10 @@ pub mod systems { pub const SHIELD_CONTROL: &str = "SHE"; pub const DAMAGE_CONTROL: &str = "DAM"; pub const LONG_RANGE_SCAN: &str = "LRS"; + pub const COMPUTER: &str = "COM"; - pub const KEYS: [&str; 5] = [ - SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL, DAMAGE_CONTROL, LONG_RANGE_SCAN + pub const KEYS: [&str; 6] = [ + SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL, DAMAGE_CONTROL, LONG_RANGE_SCAN, COMPUTER ]; pub fn name_for(key: &str) -> String { @@ -122,6 +123,7 @@ pub mod systems { SHIELD_CONTROL => "Shield Control".into(), DAMAGE_CONTROL => "Damage Control".into(), LONG_RANGE_SCAN => "Long Range Scanners".into(), + COMPUTER => "Library-Computer".into(), _ => "Unknown".into() } } diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index fc4a4735..e4fbed20 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -1,5 +1,114 @@ use crate::model::{Galaxy, Pos, EndPosition, SectorStatus}; +pub fn full_instructions() { + println!( +" INSTRUCTIONS FOR 'SUPER STAR TREK' + + 1. When you see \"Command ?\" printed, enter one of the legal + commands (NAV, SRS, LRS, PHA, TOR, SHE, DAM, COM, OR XXX). + 2. If you should type in an illegal command, you'll get a short + list of the legal commands printed out. + 3. Some commands require you to enter data (for example, the + 'NAV' command comes back with 'Course (1-9) ?'.) If you + type in illegal data (like negative numbers), then command + will be aborted. + + The galaxy is divided into an 8 X 8 quadrant grid, + and each quadrant is further divided into an 8 X 8 sector grid. + + You will be assigned a starting point somewhere in the + galaxy to begin a tour of duty as commander of the starship + Enterprise; your mission: to seek and destroy the fleet of + Klingon warships which are menacing the United Federation of + Planets. + + You have the following commands available to you as captain + of the starship Enterprise: + + NAV command = Warp Engine Control + Course is in a circular numerical 4 3 2 + vector arrangement as shown . . . + integer and real values may be ... + used. (Thus course 1.5 is half- 5 ---*--- 1 + way between 1 and 2. ... + . . . + Values may approach 9.0, which 6 7 8 + itself is equivalent to 1.0 + COURSE + One warp factor is the size of + one quadrant. Therefore, to get + from quadrant 6,5 to 5,5, you WOULD + use course 3, warp factor 1. + + SRS command = Short Range Sensor Scan + Shows you a scan of your present quadrant. + + Symbology on your sensor screen is as follows: + <*> = Your starship's position + +K+ = Klingon battle cruiser + >!< = Federation starbase (refuel/repair/re-arm here!) + * = Star + + A condensed 'status report' will also be presented. + + LRS command = Long Range Sensor Scan + Shows conditions in space for one quadrant on each side + of the Enterprise (which is in the middle of the scan). + The scan is coded in the form ###, where the units digit + is the number of stars, the tens digit is the number of + starbases, and the hundreds digit is the number of + Klingons. + + Example - 207 = 2 Klingons, No starbases, & 7 stars. + + PHA command = Phaser Control + Allows you to destroy the Klingon battle cruisers by + zapping them with suitably large units of energy to + deplete their shield power. (Remember, Klingons have + phasers, too!) + + TOR command = Photon Torpedo Control + Torpedo course is the same as used in warp engine control. + If you hit the Klingon vessel, he is destroyed and + cannot fire back at you. If you miss, you are subject to + his phaser fire. In either case, you are also subject to + the phaser fire of all other Klingons in the quadrant. + + The library-computer (COM command) has an option to + compute torpedo trajectory for you (Option 2). + + SHE command = Shield Control + Defines the number of energy units to be assigned to the + shields. Energy is taken from total ship's energy. Note + that the status display total energy includes shield energy. + + DAM command = Damage Control Report + Gives the state of repair of all devices. Where a negative + 'state of repair' shows that the device is temporarily + damaged. + + COM command = Library-Computer + The library-computer contains six options: + Option 0 = Cumulative Galactic Record + This option shows computer memory of the results of all + previous short and long range sensor scans. + Option 1 = Status Report + This option shows the number of Klingons, Stardates, + and starbases remaining in the game. + Option 2 = Photon Torpedo Data + Which gives directions and distance from the Enterprise + to all Klingons in your quadrant. + Option 3 = Starbase Nav Data + This option gives direction and distance to any + starbase within your quadrant. + Option 4 = Direction/Distance Calculator + This option allows you to enter coordinates for + direction/distance calculations. + Option 5 = Galactic Region Name Map + This option prints the names of the sixteen major + galactic regions referred to in the game.") +} + pub fn enterprise() { println!(" @@ -34,10 +143,11 @@ pub fn intro(model: &Galaxy) { if star_bases > 1 { star_base_message = format!("There are {} starbases", star_bases); } - println!("Your orders are as follows: + println!( +"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", + the galaxy before they can attack federation headquarters + on stardate {}. 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) } @@ -69,7 +179,8 @@ fn quadrant_name(quadrant: &Pos) -> String { } pub fn starting_quadrant(quadrant: &Pos) { - println!("\nYour mission begins with your starship located + println!( +"\nYour mission begins with your starship located in the galactic quadrant, '{}'.\n", quadrant_name(quadrant)) } @@ -118,7 +229,8 @@ pub fn short_range_scan(model: &Galaxy) { } pub fn print_command_help() { - println!("Enter one of the following: + println!( +"Enter one of the following: NAV (To set course) SRS (For short range sensor scan) LRS (For long range sensor scan) @@ -132,7 +244,8 @@ pub fn print_command_help() { } pub fn end_game_failure(galaxy: &Galaxy) { - println!("Is is stardate {}. + println!( +"Is is stardate {}. There were {} Klingon battle cruisers left at the end of your mission. ", galaxy.stardate, galaxy.remaining_klingons()); @@ -151,10 +264,11 @@ pub fn enterprise_hit(hit_strength: &u16, from_sector: &Pos) { } pub fn hit_edge(end: &EndPosition) { - println!("Lt. Uhura report message from Starfleet Command: - 'Permission to attempt crossing of galactic perimeter + println!( +"Lt. Uhura report message from Starfleet Command: + 'Permission to attempt crossing of galactic perimeter is hereby *Denied*. Shut down your engines.' - Chief Engineer Scott reports, 'Warp engines shut down + Chief Engineer Scott reports, 'Warp engines shut down at sector {} of quadrant {}.'", end.quadrant, end.sector); } @@ -167,7 +281,8 @@ pub fn danger_shields() { } pub fn insuffient_warp_energy(warp_speed: f32) { - println!("Engineering reports, 'Insufficient energy available + println!( +"Engineering reports, 'Insufficient energy available for maneuvering at warp {warp_speed} !'") } @@ -188,7 +303,8 @@ pub fn ridiculous() { } pub fn shields_set(value: u16) { - println!("Deflector control room report: + println!( +"Deflector control room report: 'Shields now at {value} units per your command.'") } @@ -205,7 +321,8 @@ pub fn scanners_out() { } pub fn damaged_engines(max_warp: f32, warp_factor: f32) { - println!("Warp engines are damaged. Maximum speed = warp {max_warp} + println!( +"Warp engines are damaged. Maximum speed = warp {max_warp} Chief Engineer Scott reports, 'The engines won't take warp {warp_factor} !'") } @@ -253,7 +370,30 @@ pub fn long_range_scan(galaxy: &Galaxy) { } pub fn stranded() { - println!("** FATAL ERROR ** You've just stranded your ship in space + println!( +"** FATAL ERROR ** You've just stranded your ship in space You have insufficient maneuvering energy, and shield control is presently incapable of cross-circuiting to engine room!!") } + +pub fn computer_options() { + println!( +" 0 = Cumulative galactic record + 1 = Status report + 2 = Photon torpedo data + 3 = Starbase nav data + 4 = Direction/distance calculator + 5 = Galaxy 'region name' map") +} + +pub fn galaxy_region_map() { + println!( +" The Galaxy + 1 2 3 4 5 6 7 8 + ----- ----- ----- ----- ----- ----- ----- -----"); + for i in (0..REGION_NAMES.len()-1).step_by(2) { + println!( +"{} {:^23} {:^23} + ----- ----- ----- ----- ----- ----- ----- -----", (i/2)+1, REGION_NAMES[i], REGION_NAMES[i+1]); + } +} diff --git a/84_Super_Star_Trek/rust/tasks.md b/84_Super_Star_Trek/rust/tasks.md index a2729d9b..46ba7d6a 100644 --- a/84_Super_Star_Trek/rust/tasks.md +++ b/84_Super_Star_Trek/rust/tasks.md @@ -26,7 +26,16 @@ Started after movement and display of stats was finished (no energy management o - [ ] weapons - [ ] phasers - [ ] torpedoes +- [ ] computer + - [ ] 0 - output of all short and long range scans (requires tracking if a system has been scanned) + - [ ] 1 - klingons, starbases, stardate and damage control + - [ ] 2 - photon torpedo data: direction and distance to all local klingons + - [ ] 3 - starbase distance and dir locally + - [ ] 4 - direction/distance calculator (useful for nav actions I guess) + - [x] 5 - galactic name map + - [ ] restarting the game - [ ] time progression - check all areas where time should move, and adjust accordingly - [ ] intro instructions +- [ ] victory