Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8671249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:54:13+00:00 2026-06-12T18:54:13+00:00

I am trying to get a game from exercise 36 in LPTHW to work.

  • 0

I am trying to get a game from exercise 36 in LPTHW to work.

I can get the whole part of the game working except when it gets to the combat. Here is where I think the problem is.

def combat_engine():    
    global wins, hit_points, current_hp
    if monster_current_hp or current_hp > 0:
        print "You can type 'a' for attack, or 'q' for quit, choose one."
        answer = raw_input(":> ")
        if 'a' in answer:
            attack(monster)
            attack('player')
            combat_engine()
        elif 'q' in answer:
            print t.white_on_red("You give up and are devoured by the %s.") % monster
            exit(0)
        else:
            print "I dont understand %s." % answer
            next()
            combat_engine() 
    elif monster_hp == 0:
        print "You defeated the %s, congradulations %s!" % monster, name
        wins = wins + 1
        if wins == 5:
            you_win()
        elif victim == 'player':
            hit_points = hit_points + d6()
            current_hp = hit_points
            print "You feel hardier."
            next()
            barracks()
    elif current_hp == 0:
        print "You have been deafeted by the %s, better luck next time." % monster
        next()
        exit(0)

    else: 
        print "Bug Somewhere"

I believe the bug is somewhere in this function. When i printed out the HP values of each character, the battle was still going on after the monster had been reduced to -2 hp. maybe it a problem with booleans?

What I would like it to do is to either do all the stat adjustments for winning and quit the game if you lose. I just want to get past this so I can start learning about classes and dicts which should make my life much easier. Please let me know if I should post more information, I’m new at this and not the best at posting questions on here yet.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:54:15+00:00Added an answer on June 12, 2026 at 6:54 pm

    in the last part of your code you don’t call the function d100(), but the value d100. That’s surely not what you want to do.

       if d20() >= monster_to_hit and d100() <= monster_crit:
            print "The %s scored a critical hit against you!" % monster
            hit_points = hit_points - (monster_dmg * 3)
            next()
        elif d20 >= monster_to_hit and d100() > crit:
            print "The %s strikes you!"
            hit_points = hit_points - monster_dmg
            next()
    

    when debugging in python, the main word is “print”. You should feel free to print as much as possible so as to understand what’s going on.

    example:

    # attack function
    def attack(victim):
        dice20 = d20()
        dice100 = d100()
    
        print "victim == monster", victim == monster    
    
        print dice20
        print dice100
        print to_hit
        print crit
        print monster_current_hp
        print mod_dmg 
        print mod_dmg * 3
        print monster_to_hit
        print monster_crit
        print hit_points
        print monster_dmg
        print monster_dmg * 3
    
        global monster_current_hp, current_hp, to_hit, crit, hit_points
        if victim == monster:
            if dice20 >= to_hit and dice100 <= crit:
                print "You scored a critical hit against the %s!" % monster
                monster_current_hp = monster_current_hp - (mod_dmg * 3)
                next()
            elif dice20 >= to_hit and dice100 > crit:
                print "You strike the %s!" % monster
                monster_current_hp = monster_current_hp - mod_dmg
                next()
            else:
                print "The %s evades your attack!" % monster
                next()
        else:
            if dice20 >= monster_to_hit and dice100 <= monster_crit:
                print "The %s scored a critical hit against you!" % monster
                hit_points = hit_points - (monster_dmg * 3)
                next()
            elif dice20 >= monster_to_hit and dice100 > crit:
                print "The %s strikes you!"
                hit_points = hit_points - monster_dmg
                next()
    

    do the same in the combat engine so as to see the infinite loop appear. Then remove the useless print that bloat your trace with unuseful information, until you see clearly the reason it loops, because of some value, because of a boolean if test that doesn’t behave the way you expected… something like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to get this Sudoku game working, and I am still failing
I'm trying to get the MKStoreKit working with my Cocos2D game. It look pretty
I'm kinda at my wit's end trying to get my Java game to work
I'm trying to get background music going for my XNA game, but the options
I've been trying to get input with IUP to make a small pong game.
I'm writing a simple game in Java and are trying to get the coordinates
Creating a simple RPG game, first time using XNA. Trying to get my character
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I'm trying to get the location of the touch event on the screen from
I am working on a game like Mafia Wars and i am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.