blob: 9d46e6eb600a1b52972063ccea9bee5cf59d9f29 [file] [log] [blame]
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +00001#!/usr/bin/env python
2#
3# $Id$
4#
5# somebody should probably check the randrange()s...
6
7import curses
8from random import randrange
9
10def next_j(j):
11 if j == 0:
12 j = 4
13 else:
14 j -= 1
15
16 if curses.has_colors():
17 z = randrange(0, 3)
18 color = curses.color_pair(z)
19 if z:
20 color = color | curses.A_BOLD
21 stdscr.attrset(color)
22
23 return j
24
25def main(win):
26 # we know that the first argument from curses.wrapper() is stdscr.
27 # Initialize it globally for convenience.
28 global stdscr
29 stdscr = win
Tim Peterse6ddc8b2004-07-18 05:56:09 +000030
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000031 if curses.has_colors():
32 bg = curses.COLOR_BLACK
33 curses.init_pair(1, curses.COLOR_BLUE, bg)
34 curses.init_pair(2, curses.COLOR_CYAN, bg)
Tim Peterse6ddc8b2004-07-18 05:56:09 +000035
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000036 curses.nl()
37 curses.noecho()
38 # XXX curs_set() always returns ERR
39 # curses.curs_set(0)
40 stdscr.timeout(0)
Tim Peterse6ddc8b2004-07-18 05:56:09 +000041
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000042 c = curses.COLS - 4
43 r = curses.LINES - 4
44 xpos = [0] * c
45 ypos = [0] * r
46 for j in range(4, -1, -1):
47 xpos[j] = randrange(0, c) + 2
48 ypos[j] = randrange(0, r) + 2
Tim Peterse6ddc8b2004-07-18 05:56:09 +000049
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000050 j = 0
Thomas Wouters73e5a5b2006-06-08 15:35:45 +000051 while True:
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000052 x = randrange(0, c) + 2
53 y = randrange(0, r) + 2
Tim Peterse6ddc8b2004-07-18 05:56:09 +000054
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000055 stdscr.addch(y, x, ord('.'))
Tim Peterse6ddc8b2004-07-18 05:56:09 +000056
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000057 stdscr.addch(ypos[j], xpos[j], ord('o'))
Tim Peterse6ddc8b2004-07-18 05:56:09 +000058
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000059 j = next_j(j)
60 stdscr.addch(ypos[j], xpos[j], ord('O'))
Tim Peterse6ddc8b2004-07-18 05:56:09 +000061
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000062 j = next_j(j)
63 stdscr.addch( ypos[j] - 1, xpos[j], ord('-'))
64 stdscr.addstr(ypos[j], xpos[j] - 1, "|.|")
65 stdscr.addch( ypos[j] + 1, xpos[j], ord('-'))
Tim Peterse6ddc8b2004-07-18 05:56:09 +000066
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000067 j = next_j(j)
68 stdscr.addch( ypos[j] - 2, xpos[j], ord('-'))
69 stdscr.addstr(ypos[j] - 1, xpos[j] - 1, "/ \\")
70 stdscr.addstr(ypos[j], xpos[j] - 2, "| O |")
71 stdscr.addstr(ypos[j] + 1, xpos[j] - 1, "\\ /")
72 stdscr.addch( ypos[j] + 2, xpos[j], ord('-'))
Tim Peterse6ddc8b2004-07-18 05:56:09 +000073
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000074 j = next_j(j)
75 stdscr.addch( ypos[j] - 2, xpos[j], ord(' '))
76 stdscr.addstr(ypos[j] - 1, xpos[j] - 1, " ")
77 stdscr.addstr(ypos[j], xpos[j] - 2, " ")
78 stdscr.addstr(ypos[j] + 1, xpos[j] - 1, " ")
79 stdscr.addch( ypos[j] + 2, xpos[j], ord(' '))
Tim Peterse6ddc8b2004-07-18 05:56:09 +000080
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000081 xpos[j] = x
82 ypos[j] = y
83
84 ch = stdscr.getch()
85 if ch == ord('q') or ch == ord('Q'):
Thomas Wouters73e5a5b2006-06-08 15:35:45 +000086 return
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000087 elif ch == ord('s'):
88 stdscr.nodelay(0)
89 elif ch == ord(' '):
90 stdscr.nodelay(1)
91
92 curses.napms(50)
Tim Peterse6ddc8b2004-07-18 05:56:09 +000093
Andrew M. Kuchling15c3c2b2000-12-15 00:41:48 +000094curses.wrapper(main)