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 Python Collections (2016, retired 2019) Dungeon Game Win or Lose

Whats wrong with my code when i try to show the monster?

hi, I'm trying to show the monster when the player step on it:

def draw_map(player):
    print(" _" * 5)
    tile = "|{}"
    for cell in CELLS:
        x, y = cell
        if x < 4:
            line_end  = ""
            if cell == player:
                output = tile.format("X") # represent the player, The x is the player
            else:
                output = tile.format("_")
            if cell == monster:
                output = tile.format("M")
            else:
                output = tile.format("_")
        else:
            line_end = "\n"
            if cell == player:
                output = tile.format("X|") #this represent the right wall(>)
            else:
                output = tile.format("_|")
            if cell == monster:
                output = tile.format("M|")
            else:
                output = tile.format("_|")

        print(output, end = line_end)

i keep getting this error: TabError: inconsistent use of tabs and spaces in indentation

i triple checked the code and the indentation is ok

any help?

3 Answers

Ronald Williams
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ronald Williams
Java Web Development Techdegree Graduate 25,021 Points

Hi noob developer ! I think there is something wrong with these python challenges that need to be fixed. For some reason I have found that some challenges require all tab indents to be spaces.

It's not a challange , im trying to add this feature to the game when the player step on the monster i want to show M

I pasted the code into a workspace and didn't receive a tab error but did receive a monster not defined error. Won't this code show where the monster is throughout the game?

Kris nikolaisen, the code suppose to show when the player step on the monster

Code modified was to in draw_map

1) Add monster parameter

2) Check if cell had both the monster and the player. If so then display M.

def draw_map(player, monster):
    print(" _" * 5)
    tile = "|{}"
    for cell in CELLS:
        x, y = cell
        if x < 4:
            line_end  = ""
            if cell == monster and cell == player:
                output = tile.format("M")
            elif cell == player:
                output = tile.format("X") # represent the player, The x is the player
            else:
                output = tile.format("_")
        else:
            line_end = "\n"
            if cell == monster and cell == player:
                output = tile.format("M|")
            elif cell == player:
                output = tile.format("X|") #this represent the right wall(>)
            else:
                output = tile.format("_|")

        print(output, end = line_end)

In game_loop

1) Call draw_map with new monster parameter

2) If player==monster, clear screen and redraw map before displaying 'Better luck next time!' message

def game_loop():
    monster, door, player = get_locations()
    playing = True

    while playing:
        clear_screen()
        draw_map(player, monster)
        valid_moves = get_moves(player)

        print("You're currently in room {}".format(player))
        print("You can move {}".format(", ".join(valid_moves)))
        print("Enter QUIT to quit")

        move = input("> ")
        move = move.upper()

        if move == 'QUIT':
            print("\n ** See you next time! **\n")
            break
        if move in valid_moves:
            player = move_player(player, move)

            if player == monster:
                clear_screen()
                draw_map(player, monster)
                print("\n ** Oh no! The monster got you! Better luck next time! **\n")
                playing = False