Bummer! You must be logged in to access this page.

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Combat System

Code : https://w.trhou.se/cd0p50wlc3

If you run this application and attack you will be able to attack the enemy , and the enemy will then attack you back but once that action has been done it prints you back the attacking menu without changes on the health of the enemy.

If anyone skilled enough could help me out it'd be much appricated :}

2 Answers

Steven Parker
Steven Parker
243,318 Points

On line 121, you have:

        enemy.health = PAttack

:point_right: But you probably meant to write this:

        enemy.health -= PAttack

Another issue I found was with these lines 114/115:

    PAttack = random.randint(PlayerIG.attack / 2, PlayerIG.attack)
    EAttack = random.randint(PlayerIG.attack / 2, enemy.attack)

The enemy's value is computed from the player, and both cause an error if the attack is an odd number.

You probably want this:

    PAttack = random.randint(math.floor(PlayerIG.attack / 2), PlayerIG.attack)
    EAttack = random.randint(math.floor(enemy.attack / 2), enemy.attack)

You'll also need to import math.

And one more issue on line 125:

    if enemy.health == 0:

You probably want this:

    if enemy.health <= 0:

And there's a similar problem on line 134.

Thanks a lot for taking to time to read my code and answer me that fast :}

Much appriciated :]