Python Python Collections (2016, retired 2019) Dungeon Game Movement

Virginia Hickman
Virginia Hickman
1,541 Points

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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 50,936 Points

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