Fix Pep8 issues related to \
[functest.git] / functest / utils / functest_vacation.py
1 from os import environ
2 from curses import initscr, curs_set, newwin, endwin
3 from curses import KEY_RIGHT, KEY_LEFT, KEY_DOWN, KEY_UP
4 from random import randrange
5
6
7 def main():
8     environ["TERM"] = 'Eterm'
9     initscr()
10     curs_set(0)
11     try:
12         win = newwin(16, 60, 0, 0)
13         win.keypad(True)
14         win.nodelay(True)
15         win.border('|', '|', '-', '-', '+', '+', '+', '+')
16         win.addch(4, 44, '@')
17         win.addstr(0, 5, ' Eat all the OPNFV bugs by FunTest! ')
18         win.addstr(15, 7, ' Left,Right,Up,Down: move; other keys: quit ')
19         snake = [[20, 7], [19, 7], [18, 7], [17, 7],
20                  [16, 7], [15, 7], [14, 7], [13, 7]]
21         key = KEY_RIGHT
22         body = '~FUNTEST'
23         ind = 0
24         while key != 27:
25             win.addstr(0, 44, ' Score: ' + str(len(snake) - len(body)) + ' ')
26             win.timeout(140 - 2 * len(snake))
27             getkey = win.getch()
28             key = key if getkey == -1 else getkey
29             snake.insert(
30                 0, [snake[0][0] + (key == KEY_RIGHT and 1 or
31                                    key == KEY_LEFT and -1),
32                     snake[0][1] + (key == KEY_DOWN and 1 or
33                                    key == KEY_UP and -1)])
34             win.addch(snake[len(snake) - 1][1], snake[len(snake) - 1][0], ' ')
35             if win.inch(snake[0][1], snake[0][0]) & 255 == 32:
36                 snake.pop()
37             elif win.inch(snake[0][1], snake[0][0]) & 255 == ord('@'):
38                 c = [n for n in [[randrange(1, 58, 1), randrange(1, 14, 1)]
39                      for x in range(len(snake))] if n not in snake]
40                 win.addch(c == [] and 4 or c[0][1],
41                           c == [] and 44 or c[0][0], '@')
42             else:
43                 break
44             ind += 1
45             win.addch(snake[0][1], snake[0][0], body[ind % len(body)])
46     finally:
47         endwin()
48
49     print '\nSnake.PY-26lines by Kris Cieslak (defaultset.blogspot.com).'
50     print 'OPNFV adaptation by Functest dream team.'
51     score = str(len(snake) - len(body) - 1)
52     print ('Thanks for playing, your score: %s.' % score)
53     print 'Find and fix more bugs in your real OPNFV setup!\n'