mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-11-09 19:40:48 -05:00
Merge branch 'heatray'
This commit is contained in:
commit
18c761d85d
2 changed files with 13 additions and 8 deletions
|
@ -55,10 +55,15 @@ const Alien = struct {
|
||||||
.health = strength * 5,
|
.health = strength * 5,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Your trusty weapon. Zap those aliens!
|
||||||
|
const HeatRay = struct {
|
||||||
|
damage: u8,
|
||||||
|
|
||||||
// We love this method:
|
// We love this method:
|
||||||
pub fn zap(self: *Alien, damage: u8) void {
|
pub fn zap(self: *HeatRay, alien: *Alien) void {
|
||||||
self.health -= if (damage >= self.health) self.health else damage;
|
alien.health -= if (self.damage >= alien.health) alien.health else self.damage;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -74,7 +79,7 @@ pub fn main() void {
|
||||||
};
|
};
|
||||||
|
|
||||||
var aliens_alive = aliens.len;
|
var aliens_alive = aliens.len;
|
||||||
var heat_ray_strength: u8 = 7; // We've been given a heat ray weapon.
|
var heat_ray = HeatRay{ .damage = 7 }; // We've been given a heat ray weapon.
|
||||||
|
|
||||||
// We'll keep checking to see if we've killed all the aliens yet.
|
// We'll keep checking to see if we've killed all the aliens yet.
|
||||||
while (aliens_alive > 0) {
|
while (aliens_alive > 0) {
|
||||||
|
@ -83,8 +88,8 @@ pub fn main() void {
|
||||||
// Loop through every alien...
|
// Loop through every alien...
|
||||||
for (aliens) |*alien| {
|
for (aliens) |*alien| {
|
||||||
|
|
||||||
// *** Zap the Alien Here! ***
|
// *** Zap the alien with the heat ray here! ***
|
||||||
???.zap(heat_ray_strength);
|
???.zap(???);
|
||||||
|
|
||||||
// If the alien's health is still above 0, it's still alive.
|
// If the alien's health is still above 0, it's still alive.
|
||||||
if (alien.health > 0) aliens_alive += 1;
|
if (alien.health > 0) aliens_alive += 1;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
87c87
|
92c92
|
||||||
< ???.zap(heat_ray_strength);
|
< ???.zap(???);
|
||||||
---
|
---
|
||||||
> alien.zap(heat_ray_strength);
|
> heat_ray.zap(alien);
|
||||||
|
|
Loading…
Reference in a new issue