mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-24 20:10:15 -08:00
started work on photon torpedoes (final system)
also moved all prompt text into views submodule
This commit is contained in:
@@ -19,7 +19,7 @@ pub fn get_amount_and_set_shields(galaxy: &mut Galaxy, provided: Vec<String>) {
|
||||
}
|
||||
|
||||
view::energy_available(galaxy.enterprise.total_energy);
|
||||
let value = input::param_or_prompt_value(&provided, 0, "Number of units to shields", 0, i32::MAX);
|
||||
let value = input::param_or_prompt_value(&provided, 0, view::prompts::SHIELDS, 0, i32::MAX);
|
||||
if value.is_none() {
|
||||
view::shields_unchanged();
|
||||
return;
|
||||
@@ -38,7 +38,7 @@ pub fn get_amount_and_set_shields(galaxy: &mut Galaxy, provided: Vec<String>) {
|
||||
|
||||
pub fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy, provided: Vec<String>) {
|
||||
|
||||
let course = input::param_or_prompt_value(&provided, 0, "Course (1-9)?", 1, 9);
|
||||
let course = input::param_or_prompt_value(&provided, 0, view::prompts::COURSE, 1, 9);
|
||||
if course.is_none() {
|
||||
view::bad_nav();
|
||||
return;
|
||||
@@ -51,7 +51,7 @@ pub fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy, provided: Vec<String>
|
||||
max_warp = 0.2;
|
||||
}
|
||||
|
||||
let speed = input::param_or_prompt_value(&provided, 1, format!("Warp Factor (0-{})?", max_warp).as_str(), 0.0, 8.0);
|
||||
let speed = input::param_or_prompt_value(&provided, 1, &view::prompts::warp_factor(max_warp), 0.0, 8.0);
|
||||
if speed.is_none() {
|
||||
view::bad_nav();
|
||||
return;
|
||||
@@ -244,7 +244,7 @@ pub fn run_damage_control(galaxy: &mut Galaxy) {
|
||||
let repair_time = (ship.damaged.len() as f32 * 0.1 + repair_delay).max(0.9);
|
||||
|
||||
view::repair_estimate(repair_time);
|
||||
if !input::prompt_yes_no("Will you authorize the repair order") {
|
||||
if !input::prompt_yes_no(view::prompts::REPAIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ pub fn access_computer(galaxy: &Galaxy, provided: Vec<String>) {
|
||||
|
||||
let operation : i32;
|
||||
loop {
|
||||
let entered = input::param_or_prompt_value(&provided, 0, "Computer active and waiting command?", 0, 5);
|
||||
let entered = input::param_or_prompt_value(&provided, 0, view::prompts::COMPUTER, 0, 5);
|
||||
if entered.is_none() {
|
||||
view::computer_options();
|
||||
} else {
|
||||
@@ -310,7 +310,7 @@ pub fn get_power_and_fire_phasers(galaxy: &mut Galaxy, provided: Vec<String>) {
|
||||
view::phasers_locked(available_energy);
|
||||
let mut power: f32;
|
||||
loop {
|
||||
let setting = param_or_prompt_value(&provided, 0, "Number of units to fire", 0, available_energy);
|
||||
let setting = param_or_prompt_value(&provided, 0, view::prompts::PHASERS, 0, available_energy);
|
||||
if setting.is_some() {
|
||||
power = setting.unwrap() as f32;
|
||||
break;
|
||||
@@ -349,4 +349,16 @@ pub fn get_power_and_fire_phasers(galaxy: &mut Galaxy, provided: Vec<String>) {
|
||||
quadrant.klingons.retain(|k| k.energy > 0.0);
|
||||
|
||||
klingons_fire(galaxy);
|
||||
}
|
||||
|
||||
pub fn gather_dir_and_launch_torpedo(galaxy: &mut Galaxy, provided: Vec<String>) {
|
||||
if galaxy.enterprise.damaged.contains_key(systems::TORPEDOES) {
|
||||
view::inoperable(&systems::name_for(systems::TORPEDOES));
|
||||
return;
|
||||
}
|
||||
|
||||
if galaxy.enterprise.photon_torpedoes == 0 {
|
||||
view::no_torpedoes_remaining();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,13 @@ fn main() {
|
||||
|
||||
view::enterprise();
|
||||
view::intro(&galaxy);
|
||||
let _ = input::prompt("Press Enter when ready to accept command");
|
||||
let _ = input::prompt(view::prompts::WHEN_READY);
|
||||
|
||||
view::starting_quadrant(&galaxy.enterprise.quadrant);
|
||||
view::short_range_scan(&galaxy);
|
||||
|
||||
loop {
|
||||
let command = input::prompt("Command?");
|
||||
let command = input::prompt(view::prompts::COMMAND);
|
||||
if command.len() == 0 {
|
||||
continue;
|
||||
}
|
||||
@@ -36,7 +36,8 @@ fn main() {
|
||||
systems::LONG_RANGE_SCAN => commands::perform_long_range_scan(&mut galaxy),
|
||||
systems::COMPUTER => commands::access_computer(&galaxy, command[1..].into()),
|
||||
systems::PHASERS => commands::get_power_and_fire_phasers(&mut galaxy, command[1..].into()),
|
||||
"XXX" => galaxy.enterprise.destroyed = true,
|
||||
systems::TORPEDOES => commands::gather_dir_and_launch_torpedo(&mut galaxy, command[1..].into()),
|
||||
systems::RESIGN => galaxy.enterprise.destroyed = true,
|
||||
_ => view::print_command_help()
|
||||
}
|
||||
|
||||
|
||||
@@ -118,9 +118,12 @@ pub mod systems {
|
||||
pub const LONG_RANGE_SCAN: &str = "LRS";
|
||||
pub const COMPUTER: &str = "COM";
|
||||
pub const PHASERS: &str = "PHA";
|
||||
pub const TORPEDOES: &str = "TOR";
|
||||
|
||||
pub const KEYS: [&str; 7] = [
|
||||
SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL, DAMAGE_CONTROL, LONG_RANGE_SCAN, COMPUTER, PHASERS
|
||||
pub const RESIGN: &str = "XXX";
|
||||
|
||||
pub const KEYS: [&str; 8] = [
|
||||
SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL, DAMAGE_CONTROL, LONG_RANGE_SCAN, COMPUTER, PHASERS, TORPEDOES
|
||||
];
|
||||
|
||||
pub fn name_for(key: &str) -> String {
|
||||
@@ -132,6 +135,7 @@ pub mod systems {
|
||||
LONG_RANGE_SCAN => "Long Range Scanners".into(),
|
||||
COMPUTER => "Library-Computer".into(),
|
||||
PHASERS => "Phaser Control".into(),
|
||||
TORPEDOES => "Photon Tubes".into(),
|
||||
_ => "Unknown".into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
use crate::model::{Galaxy, Pos, EndPosition, SectorStatus, Enterprise, systems};
|
||||
|
||||
pub mod prompts {
|
||||
pub const COURSE: &str = "Course (1-9)?";
|
||||
pub const SHIELDS: &str = "Number of units to shields";
|
||||
pub const REPAIR: &str = "Will you authorize the repair order";
|
||||
pub const COMPUTER: &str = "Computer active and waiting command?";
|
||||
pub const PHASERS: &str = "Number of units to fire";
|
||||
pub const WHEN_READY: &str = "Press Enter when ready to accept command";
|
||||
pub const COMMAND: &str = "Command?";
|
||||
|
||||
pub fn warp_factor(max_warp: f32) -> String {
|
||||
format!("Warp Factor (0-{})?", max_warp)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn full_instructions() {
|
||||
println!(
|
||||
" INSTRUCTIONS FOR 'SUPER STAR TREK'
|
||||
@@ -492,4 +506,8 @@ pub fn replay() {
|
||||
The Federation is in need of a new starship commander
|
||||
for a similar mission -- if there is a volunteer
|
||||
let him step forward and enter 'Aye'")
|
||||
}
|
||||
|
||||
pub fn no_torpedoes_remaining() {
|
||||
println!("All photon torpedoes expended")
|
||||
}
|
||||
Reference in New Issue
Block a user