mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-10 04:07:28 -08:00
implemented damage command
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{model::{Galaxy, Pos, COURSES, EndPosition, self}, view, input};
|
||||
use crate::{model::{Galaxy, Pos, COURSES, EndPosition, self, Enterprise, systems}, view, input};
|
||||
|
||||
pub fn perform_short_range_scan(galaxy: &Galaxy) {
|
||||
if galaxy.enterprise.damaged.contains_key(model::systems::SHORT_RANGE_SCAN) {
|
||||
@@ -146,3 +146,17 @@ fn move_klingons_and_fire(galaxy: &mut Galaxy) {
|
||||
quadrant.klingons[k].fire_on(&mut galaxy.enterprise);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_damage_control(enterprise: &Enterprise) {
|
||||
if enterprise.damaged.contains_key(model::systems::DAMAGE_CONTROL) {
|
||||
view::inoperable("Damage Control");
|
||||
return;
|
||||
}
|
||||
|
||||
println!("Device State of Repair");
|
||||
for i in 0..systems::NAMES.len() {
|
||||
let damage = enterprise.damaged.get(systems::ALL[i]).unwrap_or(&0.0);
|
||||
println!("{:<25}{}", systems::NAMES[i], damage)
|
||||
}
|
||||
println!();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ fn main() {
|
||||
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()),
|
||||
model::systems::DAMAGE_CONTROL => commands::display_damage_control(&galaxy.enterprise),
|
||||
_ => view::print_command_help()
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ impl Enterprise {
|
||||
|
||||
view::shields_hit(self.shields);
|
||||
|
||||
// take damage if strength is greater than 20
|
||||
if hit_strength >= 20 {
|
||||
self.take_damage(hit_strength)
|
||||
}
|
||||
@@ -77,17 +76,24 @@ impl Enterprise {
|
||||
|
||||
let system = systems::ALL[rng.gen_range(0..systems::ALL.len())].to_string();
|
||||
let damage = hit_past_shield + rng.gen::<f32>() * 0.5;
|
||||
self.damaged.entry(system).and_modify(|d| *d += damage).or_insert(damage);
|
||||
self.damaged.entry(system).and_modify(|d| *d -= damage).or_insert(-damage);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod systems {
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub const SHORT_RANGE_SCAN: &str = "SRS";
|
||||
pub const WARP_ENGINES: &str = "NAV";
|
||||
pub const SHIELD_CONTROL: &str = "SHE";
|
||||
pub const DAMAGE_CONTROL: &str = "DAM";
|
||||
|
||||
pub const ALL: [&str; 3] = [
|
||||
SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL
|
||||
pub const ALL: [&str; 4] = [
|
||||
SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL, DAMAGE_CONTROL
|
||||
];
|
||||
|
||||
pub const NAMES: [&str; 4] = [
|
||||
"Short Range Scanners", "Warp Engines", "Shield Control", "Damage Control"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Started after movement and display of stats was finished (no energy management o
|
||||
- [x] shield control
|
||||
- [x] shield hit absorption
|
||||
- [x] subsystem damage
|
||||
- [ ] and support for reports
|
||||
- [x] and support for reports
|
||||
- [ ] random system damage on move
|
||||
- [ ] lrs?
|
||||
- [ ] stranded...
|
||||
|
||||
Reference in New Issue
Block a user