I am trying to program an ascii compass for a text adventure. I found something like I want to do at this url:
I did this modification for me:
north = "The Hills"
west = "A realy dark room"
#west = "A longer text destroy the positions"
east = "Entrance to the Dungeon"
south = "[X]"
n = "N"
s = "S"
vert_line = "║"
hzt_line = " ⯇ W ══ (C) ══ E ⯈ "
print(north.center(72, " "))
print(r"▲".rjust(len(west)+10))
print(r""+n.rjust(len(west)+10))
print(r""+vert_line.rjust(len(west)+10))
print(r""+vert_line.rjust(len(west)+10))
print(west.rjust(len(east)) + hzt_line + east)
print(r""+vert_line.rjust(len(west)+10))
print(r""+vert_line.rjust(len(west)+10))
print(r""+s.rjust(len(west)+10))
print(r"▼".rjust(len(west)+10))
print(south.center(len(west)+len(hzt_line)+len(east)-5, " "))
The problem is the calculation of the correct whitespace for the labels. It depends on the length of the text and breaks out of the center.
I'm also stuck at the calculation for the whitespace .. the result should be like this:
This is up
▲
N
|
To the left ◀ W ── [C] ── E ⯈ Dining Room
|
S
▼
Kitchen
The code looks also really ugly, maybe anyone knows a smarter solution.
Thank you very much for help!
Rufnex
I ran into a problem playing with your code. For some reason the left arrow graphic messes up the centering. When I changed the character, this worked well:
north = "The Hills"
west = "A realy dark room"
east = "Entrance to the Dungeon"
south = "[X]"
n = "N"
s = "S"
vert_line = "║"
#hzt_line = " ⯇ W ══ (C) ══ E ⯈ " # for some reason the left arrow graphic messes up the centering
hzt_line = " < W == (C) == E > "
# synchronize east/west lengths and get line length
labelsize= max(len(west),len(east))
westpad = west.rjust(labelsize)
eastpad = east.ljust(labelsize)
long_line = westpad+hzt_line+eastpad
line_length = len(long_line)
# print compass
print(north.center(line_length))
print(r"▲".center(line_length))
print(n.center(line_length))
print(vert_line.center(line_length))
print(vert_line.center(line_length))
print(long_line.center(line_length))
print(vert_line.center(line_length))
print(vert_line.center(line_length))
print(s.center(line_length))
print(r"▼".center(line_length))
print(south.center(line_length))