Your program has to take a multi-lined string, like this:
#############
# #
# p #
# #
#############
p
is the player and #
is a block.
Now under that in the terminal should be an input line saying:
How do you want to move?
If the player types l
he has to walk left when there isn't a block, else, when there is a block, he can't go through and doesn't move of course, now the output in the terminal has to be updated (and the previous output cleared/overwritten):
#############
# #
# p #
# #
#############
He can type l
for left, r
for right, u
for up and d
for down.
The input will always be multiline, but won't always be padded with spaces into a perfect rectangle. In addition, the hashes can be anywhere in the string, and won't always be connected to each other. For example:
## ##
# #
## p
#
is a valid dungeon. (note the lack of trailing spaces on each line)
If the player goes outside of the string, he doesn't have to be displayed. But if he comes back later, he must be displayed again.
And the boundaries of "outside" the string are the length(longest_line)
by number_of_lines
rectangle, so even if one line isn't padded with spaces on the right, that location isn't considered out of bounds. Example using the earlier dungeon:
## ##
# #p
##
#
The second line didn't have a space where the p is now, but that doesn't matter.
Finally, your program must loop forever taking input.
Test cases
Test case 1:
####
# p#
#
####
How do you want to move?
d
####
# #
# p
####
Test case 2:
####
p#
#
####
How do you want to move?
l
####
p #
#
####
How do you want to move?
d
####
#
p #
####
How do you want to move?
l
####
#
p #
####
How do you want to move?
l
####
#
#
####
How do you want to move?
r
####
#
p #
####
Of course, these aren't complete. Your code should loop forever and clear the screen between each output.
Your output is allowed to prompt for input as How do you want to move?\n<input>
or How do you want to move?<input>
(i.e. you don't need the input on a blank line), and you don't need a empty line between the final line of the dungeon and the prompt. (they can't be on the same line however)
Standard loopholes are disallowed ! This is code-golf, so the shortest code in bytes wins!
l
,r
,u
, ord
) can be anything, not just "How do you want to move"? It doesn't really affect the answers except for golfyness. \$\endgroup\$