Michael-F-Bryan / adventures.michaelfbryan.com

A simple blog for documenting my thoughts and adventures
http://adventures.michaelfbryan.com/
15 stars 3 forks source link

[posts/rust-best-practices/bad-habits] #54

Closed daveloyall closed 2 years ago

daveloyall commented 2 years ago

Hi.

Depending on the situation, it might make sense to take a callback argument in the Monster::take_damage() method.

Ok. But, the code in the playground doesn't seem to work.

Isn't it supposed to loop until the play has inflicted at least 100 damage?

I tried taking out that break; near the bottom, but then it just runs for a really long time. Way over 100 damage.

I'm not sure yet, but since the post is live already, I thought I would let you know.

Cheers! By the way, I am enjoying your work and engaging with it, as you can see. :)

Michael-F-Bryan commented 2 years ago

Yeah, there was a bug where I was creating monsters using Monster::default(), but because the Default implementation was derived each monster would be created with zero health. That meant we never actually dealt any damage because of the let damage_received = cmp::min(self.health, amount).

Someone else caught me not properly testing my code after refactoring it, and I fixed the issue in f3a82d116da214bc71486da524b9492142acdc8b.