mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-05 09:39:32 -08:00
phasers! completed this
This commit is contained in:
@@ -331,7 +331,23 @@ pub fn get_power_and_fire_phasers(galaxy: &mut Galaxy, provided: Vec<String>) {
|
||||
|
||||
let per_enemy = power / quadrant.klingons.len() as f32;
|
||||
|
||||
// fire on each klingon
|
||||
for k in &mut quadrant.klingons {
|
||||
let dist = k.sector.abs_diff(galaxy.enterprise.sector) as f32;
|
||||
let hit_strength = per_enemy / dist * (2.0 + rng.gen::<f32>());
|
||||
if hit_strength < 0.15 * k.energy {
|
||||
view::no_damage(k.sector);
|
||||
} else {
|
||||
k.energy -= hit_strength;
|
||||
view::hit_on_klingon(hit_strength, k.sector);
|
||||
if k.energy > 0.0 {
|
||||
view::klingon_remaining_energy(k.energy);
|
||||
} else {
|
||||
view::klingon_destroyed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
quadrant.klingons.retain(|k| k.energy > 0.0);
|
||||
|
||||
klingons_fire(galaxy);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ pub struct StarBase {
|
||||
|
||||
pub struct Klingon {
|
||||
pub sector: Pos,
|
||||
energy: f32
|
||||
pub energy: f32
|
||||
}
|
||||
|
||||
impl Klingon {
|
||||
|
||||
@@ -461,3 +461,19 @@ pub fn repair_estimate(repair_time: f32) {
|
||||
"Technicians standing by to effect repairs to your ship;
|
||||
Estimated time to repair: {repair_time} stardates.")
|
||||
}
|
||||
|
||||
pub fn no_damage(sector: Pos) {
|
||||
println!("Sensors show no damage to enemy at {sector}")
|
||||
}
|
||||
|
||||
pub fn hit_on_klingon(hit_strength: f32, sector: Pos) {
|
||||
println!("{hit_strength} unit hit on Klingon at sector {sector}")
|
||||
}
|
||||
|
||||
pub fn klingon_remaining_energy(energy: f32) {
|
||||
println!(" (sensors show {energy} units remaining)")
|
||||
}
|
||||
|
||||
pub fn klingon_destroyed() {
|
||||
println!(" Target Destroyed!") // not standard for game but feedback is good. Sorry Mr. Roddenberry
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ Started after movement and display of stats was finished (no energy management o
|
||||
- [x] repair on damage control
|
||||
- [x] protection from shots
|
||||
- [ ] weapons
|
||||
- [ ] phasers
|
||||
- [x] phasers
|
||||
- [ ] torpedoes
|
||||
- [ ] computer
|
||||
- [x] 0 - output of all short and long range scans (requires tracking if a system has been scanned)
|
||||
|
||||
Reference in New Issue
Block a user