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 Movement

Dungeon Game Type Error

I keep getting the type error, TypeError: can only join an iterable, in my join method in the while loop.

import random
import os

#draw grib
#pick random location for player
#pick random location for exit door
#pick random locaton for monster
#draw player in the grid
#take input for movement
#move the player, unless invalid move (past edges of grid)
#check for win or loss
#clear screen and redraw grid

CELLS = [(0,0),(1,0),(2,0),(3,0),(4,0),
         (0,1),(1,1),(2,1),(3,1),(4,1),
         (0,2),(1,2),(2,2),(3,2),(4,2),
         (0,3),(1,3),(2,3),(3,3),(4,3),
         (0,4),(1,4),(2,4),(3,4),(4,4)
]

def get_locations():
    return random.sample(CELLS,3)

def move_player(player,move):
    #Get the player's location
    #If move == LEFT, x-1
    #If move == RIGHT, x+1
    #If move == UP, y-1
    #If move == DOWN, y+1
    return player

def get_moves(player):
    x,y=player
    moves = ["LEFT","RIGHT","UP","DOWN"]
    if x == 0:
        moves.remove("LEFT")
    if x == 4:
        moves.remove("RIGHT")
    if y == 0:
        moves.remove("UP")
    if y == 4:
        moves.remove("DOWN")

    #If player's y == 0, they can't move up
    #If player's y == 4, they can't move down

def clear_screen():
    os.system('cls' if os.name == 'nt' else 'clear')

moster, door, player = get_locations()


while True:
    valid_moves = get_moves(player)
    print("Welcome to the dungeon")
    print("You're currently in {}".format(player))
    print("You can move {}".format(", ".join(valid_moves)))
    print("Enter QUIT to quit")

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

    if move == "QUIT":
        break
    #Good move? Change the player postition
    #Bad move. Don't change anything
    #On the door? They win
    #On the monster? They lose
    #Otherwise. Loop over again

1 Answer

Your get_moves function doesn't have a return statement. It should return moves.