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
Jenna Dalgety
7,791 Pointsdungeon.py drawing map function
Here's the layout of my map when I start the program:
treehouse:~/workspace$ python dungeon.py
Welcome to the dungeon!
You are currently in room (4, 1)
_ _ _ _ _ _ _ _
|_|
|_|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|_|
|X|_|_|_|_|_|_|_|
|_|_|_|_|O|_|_|_|
|_|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_You can move ['LEFT', 'RIGHT', 'UP', 'DOWN']
Enter QUIT to quit
>
I'll follow up with my code next. I've been banging my head against a wall trying to figure out why it's appending a whole cell at the top of the dungeon and starting my available moves string on the same line as the end of my map. Any help/guidance is appreciated.
[MOD: added ```python formatting -cf]
1 Answer
Chris Freeman
Treehouse Moderator 68,468 PointsI see an issue with the loop variable I as a module of size. On the first loop, I has a value 0 which is a True modulo of and value:
>>> size = 10
>>> 0 % size == 0
True
If 1 is added before the test, it seems to correct the line alignment:
for i in range(len(DUNGEON)):
if (i + 1) % (size) == 0:
dungeon_array.append(i)
Addition correction might be needed in position reporting to handle the zero-based counting.
Jenna Dalgety
7,791 PointsOh, wow! So, all I had to do was skip that first test so as not to test 0. Totally understand and now see what type of affect testing 0 had on the dungeon.
Thank you much!
Jenna Dalgety
7,791 PointsJenna Dalgety
7,791 Points[MOD: added ```python formatting -cf]