-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhatgame.py
84 lines (70 loc) · 2.69 KB
/
hatgame.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
73
74
75
76
77
78
79
80
81
82
83
84
import curses
menu = ['Start', 'Settings', 'Exit']
harry = [
' _ __',
" ___ | ' \ ",
" ___ \ / ___ ,'\_ | .-. \ /|",
" \ / | |,'__ \ ,'\_ | \ | | | | ,' |_ /|",
" _ | | | |\/ \ \ | \ | |\_| _ | |_| | _ '-. .-',' |_ _",
"// | | | |____| | | |\_|| |__ // | | ,'_`. | | '-. .-',' `. ,'\_",
"\\\_| |_,' .-, _ | | | | |\ \ // .| |\_/ | / \ || | | | / |\ \| \ ",
" `-. .-'| |/ / | | | | | | \ \// | | | | | || | | | | |_\ || |\_|",
" | | | || \_| | | | /_\ \ / | |` | | | || | | | | .---'| |",
" | | | |\___,_\ /_\ _ // | | | \_/ || | | | | | /\| |",
" /_\ | | //_____// .||` `._,' | | | | \ `-' /| |",
" /_\ `------' \ | AND `.\ | | `._,' /_\ ",
" \| THE `.\ ",
" ___ _ _ _ _ _ ",
" / __| ___ _ _| |_(_)_ _ __ _ | || |__ _| |_ ",
" \__ \/ _ \ '_| _| | ' \/ _` | | __ / _` | _|",
" |___/\___/_| \__|_|_||_\__, | |_||_\__,_|\__|",
" |___/ ",
]
def print_menu(stdscr, selected_row_idx):
stdscr.clear()
h, w = stdscr.getmaxyx()
maxlen = len(max(harry, key=len))
for idx, row in enumerate(harry):
x = w//2 - maxlen//2
y = idx
stdscr.addstr(y, x, row)
for idx, row in enumerate(menu):
x = w//2 - len(row)//2
y = h//2 - len(menu)//2 + idx + 9
if idx == selected_row_idx:
stdscr.attron(curses.color_pair(1))
stdscr.addstr(y, x, row)
stdscr.attroff(curses.color_pair(1))
else:
stdscr.addstr(y, x, row)
stdscr.refresh()
def print_center(stdscr, text):
stdscr.clear()
h, w = stdscr.getmaxyx()
x = w//2 - len(text)//2
y = h//2
stdscr.addstr(y, x, text)
stdscr.refresh()
def main(stdscr):
# turn off cursor blinking
curses.curs_set(0)
# color scheme for selected row
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
# specify the current selected row
current_row = 0
# print the menu
print_menu(stdscr, current_row)
while 1:
key = stdscr.getch()
if key == curses.KEY_UP and current_row > 0:
current_row -= 1
elif key == curses.KEY_DOWN and current_row < len(menu)-1:
current_row += 1
elif key == 10:
print_center(stdscr, "You selected '{}'".format(menu[current_row]))
stdscr.getch()
# if user selected last row, exit the program
if current_row == len(menu)-1:
break
print_menu(stdscr, current_row)
curses.wrapper(main)