Hi, I am trying to create a simple roguelike-like, a game with graphics similar to roguelikes, with a few extra twists. I am trying to create a dungeon using a list, here is the code...

background = ['#', '#', '#', '#', '#', '#', '#', '#', '#' /n/
              '#', '.', '.', '.', '.', '.', '.', '.', '#' /n/
              '#', '.', '.', '.', '.', '.', '.', '.', '#' /n/
              '#', '.', '.', '.', '.', '.', '.', '.', '#' /n/
              '#', '.', '.', '.', '.', '.', '.', '.', '#' /n/
              '#', '.', '.', '.', '.', '.', '.', '.', '#' /n/
              '#', '.', '.', '.', '.', '.', '.', '.', '#' /n/
              '#', '#', '#', '#', '#', '#', '#', '#', '#' ]
print background

My problem is that it does not work. I am trying to use '#' for walls, and '.' for the ground. I figured that with using /n/ it would make a raw list, but it doesn't work. Without the /n/, the code just prints to the screen in a jumbled, two line mess. Any suggestions on making this work?

Karim.

Recommended Answers

All 3 Replies

The newline character is '\n' (including the quotes), not \n\.

Hope it helps,
Jeff

Another way to go at it

edge = "# "*8  + "#"
center = "# "  +  ". "*7  +  "#"

print edge
for j in range(0, 6):
   print center
print edge

In any case, you want each line to be a single string, so if you want it all in one list, it will be a list containing 8 strings, one for each line you want to print, not individual characters.

Woooee, that code worked, it got my dungeon created perfectly. Now, say I wanted to insert the player '@' into the middle of all this, how would I do this? I usually used the thing where I placed him in the 3rd string in the list, but I don't know how that would work with your code? Any suggestions?

The basis of what I am doing is trying to create one small dungeon that will allow for the following events:

fighting monsters
talking to NPC's
moving around

Inventory and such will not be implemented until I understand how to complete the following above actions. I am trying to create a roguelike for the Python members of DaniWeb, just a little gift for everyone who has helped me out with my codes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.