phasers! completed this

This commit is contained in:
Christopher
2023-03-03 14:49:06 +13:00
parent 188b17d152
commit a8c55988ad
4 changed files with 35 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -25,7 +25,7 @@ pub struct StarBase {
pub struct Klingon {
pub sector: Pos,
energy: f32
pub energy: f32
}
impl Klingon {

View File

@@ -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
}

View File

@@ -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)