I have used a dictionary to allow a user to input something, but the next problem is using a second word as a parameter for the called function. At the moment, I have:
def moveSouth():
Player.makeMove("south")
def moveNorth():
Player.makeMove("north")
def moveEast():
Player.makeMove("east")
def moveWest():
Player.makeMove("west")
function_dict = {'move south':moveSouth, 'wait':wait, 'sleep':sleep,
'move north':moveNorth, 'move':move, 'look':look,
'move east':moveEast,
'move west':moveWest}
And to get the input:
command = input("> ")
command = command.lower()
try:
function_dict[command]()
except KeyError:
i = random.randint(0,3)
print(responses[i])
However, rather than having to have 4 different functions to make a move, I was hoping there would be a way so that when the user inputs “move south”, it uses the first word to call the function, and then ‘south’ as a parameter for the direction in that function.
split()the input and then pass each part in separately.