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


Malcolm Robertson
Malcolm Robertson
8,478 Points

game.py not running (no errors)

I have nearly spent as much time trying to identify the problem with this code as writing it!

I presume it is some sort or indent error although I cant find the problem.

I have tried this locally (python2 and 3) and via the work space. No errors just no game interaction.

I have checked indentation although the code I downloaded from the treehouse site that I can get to work seems to have two spaces in the indentation from column 1 to the start of all def's in the code.

Initially i have some mis-keyed errors that python picked up on and I corrected which makes me think that python is moving through the code but It is not picking up the below setup()?

import sys

from character import Character
from monster import Dragon
from monster import Goblin
from monster import Troll

class Game:
    def setup(self):
        self.player = Character()
        self.monster = [
        self.monster = self.get_next_monster()

    def get_next_monster(self):
            return self.monster.pop(0)
        except IndexError:
            return None

    def monster_turn(self):
        if self.monster.acttack():
            print("{} is attacking!").format(self.monster)
        # if so, tell the player
            if input('Do you want to Dodge [Y]es or [N]o?').lower():
                if self.player.dodge():
                #check if the player wants to dodge_limit
                    print('You doged the attack')
                #if so see if the dodge is successful

                #if it is move on
                    print('You got hit!')
                    self.player.hit_points -= 1
                    #if its not remove one player hit point.
                print('{} hit you for 1 point').format(self.monster)
                self.player.hit_points -= 1
            print("{} isn't attacking this turn").format(self.monster)

        #if the monster is not attacking tell the player too.

    def player_turn(self):
        #let the player attack, rest or Quit
        player_action = input('Would you like to [A]ttack, [R]est or [Q]uit ?').lower()
        #if they attack:
        if player_action == 'a':
            print("You are attacking {}").format(self.monster)
            #see if the acttack is successful
            if self.player.attack():
                if self.monster.dodge():
                    print("{} dodged your attack!").format(self.monster)
                    if self.player.leveled_up():
                        self.monster.hit_points -= 2
                        self.monster.hit_points -= 1
                    print("Good Hit, you hit {} with your {}!").format(self.monster, self.player.weapon)
                #if not dodged subtract the right number of hit points from
                # the monster
            #if dodge print that
                print('You missed')
        #if not a good attach tel player
        elif player_action == 'r':
        #if they rest call the player .rest () method

        #if they quit exit Game
        elif player_action == 'q':
        #if anything else re-run the method.

    def cleanup(self):
        if self.monster.hit_points <= 0:
            self.player.experience += self.monster.experience
            print("You Killed {}").format(self.monster)
            self.monster = self.get_next_monster()
        #if monster has no hit points
        #up the player experience
        #print a message
        #Get a new monster

    def __int__(self):

        while self.player.hit_points and (self.monster or self.monsters):

        if self.player.hit_points:
            print('You Win!')
        elif self.monster or self.monsters:
            print('You Loose!')


Thanks for your help.

2 Answers

Idan Melamed
Idan Melamed
16,285 Points

Hi Malcolm,

Have you tried running the pdb?

Edit - The first thing the game asks the user to do is to write his name. The game does that from character.py. Maybe the problem is there?

Malcolm Robertson
Malcolm Robertson
8,478 Points

Hi Idan,

I have run through it but I have not experience with pdb so will need to look that up and get some understanding of what I am looking for.

Thanks for the suggestion.

Idan Melamed
Idan Melamed
16,285 Points

My pleasure. If running the game doesn't throw any errors, I would check out character.py and try to see why the line that asks the user for his name doesn't run.