-
Notifications
You must be signed in to change notification settings - Fork 8
/
worstrl.py
72 lines (58 loc) · 1.87 KB
/
worstrl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
# extremely minimal "roguelike" walking simulator.
# just Python 3 and curses in 80x24 terminal.
# hjkl or arrows to move, q or ESC quits, w for cheat mode.
import curses
from curses import wrapper
import random
XMIN = 1
XMAX = 80
YMIN = 1
YMAX = 24
def main(stdscr):
curses.curs_set(0)
stdscr.clear()
win = curses.newwin(YMAX, XMAX, 0, 0)
ypos = random.randint(YMIN+1,YMAX-1)
xpos = random.randint(XMIN+1,XMAX-1)
ystair = random.randint(YMIN+1,YMAX-1)
xstair = random.randint(XMIN+1,XMAX-1)
while True:
win.clear()
win.border("|","|","-","-","+","+","+","+")
win.addch(ypos-1,xpos-1,"@")
win.addch(ystair-1,xstair-1,">")
stdscr.refresh()
win.refresh()
c = stdscr.getch()
#c = win.getkey()
curses.flushinp()
if c == curses.KEY_LEFT or c == ord("h"):
xpos -= 1
if c == curses.KEY_DOWN or c == ord("j"):
ypos += 1
if c == curses.KEY_UP or c == ord("k"):
ypos -= 1
if c == curses.KEY_RIGHT or c == ord("l"):
xpos += 1
if (xpos < XMIN+1):
xpos = XMIN+1
if (xpos > XMAX-1):
xpos = XMAX-1
if (ypos < YMIN+1):
ypos = YMIN+1
if (ypos > YMAX-1):
ypos = YMAX-1
if c == ord("w"): ## warp around
ypos = random.randint(YMIN+1,YMAX-1)
xpos = random.randint(XMIN+1,XMAX-1)
if (xpos == xstair and ypos == ystair):
ypos = random.randint(YMIN+1,YMAX-1)
xpos = random.randint(XMIN+1,XMAX-1)
ystair = random.randint(YMIN+1,YMAX-1)
xstair = random.randint(XMIN+1,XMAX-1)
if c == ord("q") or c == 27: ## ESC == 27
break
if __name__ == "__main__":
os.putenv('ESCDELAY', '1')
wrapper(main)