# Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 10  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. Printing 2d level to screen without clearing the screen, efficiently
2. import os
3. import time
4. import random
5. clear = lambda: os.system('clear')
6.
7. g = '33[32m' + '# '
8. t = '33[31m' + '^ '
9. l = [g, g, g, g, g, g,
10.      g, g, g, g, g, g,
11.      g, g, g, g, g, g,
12.      g, g, g, g, g, g,
13.      g, g, g, g, g, g,
14.      g, g, g, g, g, g]
15.
16. def level():
17.     i = 0
18.     while i < 1000:
19.         print l[0] + l[1] + l[2] + l[3] + l[4] + l[5]
20.         print l[6] + l[7] + l[8] + l[9] + l[10] + l[11]
21.         print l[12] + l[13] + l[14] + l[15] + l[16] + l[17]
22.         print l[18] + l[19] + l[20] + l[21] + l[22] + l[23]
23.         print l[24] + l[25] + l[26] + l[27] + l[28] + l[29]
24.         print l[30] + l[31] + l[32] + l[33] + l[34] + l[35]
25.         i += 1
26.
27.         for b in l:
28.             ch = round(random.random())
29.             if ch:
30.                 l[l.index(b)] = g
31.             else:
32.                 l[l.index(b)] = t
33.         clear()
34. level()