I started making a game in curses, but I feel like I am displaying the map inefficiently and ineffectively.
Here's the code (only the relevant parts):
import curses
world_map = [
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000011111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000011111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000011111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000111111111111111111110000000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000111111111111111111111000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000011111111111111111000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000011111111111100000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000']
def win(stdscr):
curses.init_color(255, 0, 0x64 * 1000 // 0xff, 0)
curses.init_color(254, 0xff * 1000 // 0xff, 0xff * 1000 // 0xff, 0xff * 1000 // 0xff)
curses.init_color(253, 0x82 * 1000 // 0xff, 0x8c * 1000 // 0xff, 0x51 * 1000 // 0xff)
curses.init_color(252, 0xff * 1000 // 0xff, 0xe4 * 1000 // 0xff, 0xb5 * 1000 // 0xff)
curses.init_color(251, 0xc0 * 1000 // 0xff, 0xc0 * 1000 // 0xff, 0xc0 * 1000 // 0xff)
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLUE) # water
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_GREEN) # grass
curses.init_pair(3, curses.COLOR_RED, 255) # trees
curses.init_pair(4, curses.COLOR_RED, 254) # mountains
curses.init_pair(5, curses.COLOR_RED, 253) # swamp
curses.init_pair(6, curses.COLOR_RED, 252) # desert
curses.init_pair(7, curses.COLOR_RED, 251) # village
colors = [curses.color_pair(1), curses.color_pair(2), curses.color_pair(3), curses.color_pair(4), curses.color_pair(5), curses.color_pair(6), curses.color_pair(7)]
while True:
for i in range(30):
for j in range(119):
stdscr.addch(i, j, ' ', colors[int(world_map[i][j])])
stdscr.refresh()
def main():
curses.wrapper(win)
if __name__ == '__main__':
main()
Running this produces this window:
(if you couldn't tell it's just a test)
Is there a better way I could be doing this?