Ex43.py Building a small combat system

Hello everybody,

I am having trouble with the Study Drill #5 in exercise 43. It says to try to build a combat system, and I have been trying to figure out how to do this, but it’s giving me a hard time.

Does anyone know how can I more easily handle this study drill or have comments on how you tackled this exercise?

Thank you for the help!

Skip it. That one should probably be removed as it derails people.

1 Like

I did take a crack at this. I got a very basic version working in the game by including a second while loop within the CentralCorridor class (starts line 138). I was going to spin it off into a function, but by that time I felt I had spent too much time on the exercise and moved on.

I also modified my Lifeform class (line 23) to include “stats” that I envisioned using in the combat loop to judge if an attack was successful and how much damage is done.

Here’s the file, it’s pretty verbose. so apologies for that.

My line of thinking was that combat is a loop, I thought of JRPG turn based combat for inspiration.

while enemy is alive: # i.e health is greater than 0

       player attacks

       subtract damage from enemy health

       enemy counter attacks
       subtract damage from player health
       if player is not dead:

            get input to see if  player still wants to fight or retreat


           end game

There probably is a better way to do it, but that’s where I started. Let me know if you have any questions or feedback.

1 Like

Hi zberwaldt,

Thank you for sharing that with me, I tried to build a function and a while-loop as well, but wasn’t able to get it running. This helps on how to structure the for loop better!

I’ll happily share my combat-engine if/when I get it working. I’ve been playing with a generator and yielding to achieved a battle with strikes and damage.

It’s tough and I’ve still got a way to go but I’m learning a lot, which is why I’m doing it. Agree with Zed that it’s a distraction from progress.

1 Like