python_curses_game_2021/proj/main.py

70 lines
1.1 KiB
Python
Raw Normal View History

2021-04-12 21:17:06 +03:00
import curses
2021-04-12 22:11:38 +03:00
import random
2021-04-12 21:17:06 +03:00
2021-04-12 22:11:38 +03:00
SIMPLE_COLOR = 1
ACTIVE_COLOR = 2
2021-04-12 21:17:06 +03:00
2021-04-12 22:11:38 +03:00
def begin_curses():
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.curs_set(0)
stdscr.keypad(True)
2021-04-12 21:17:06 +03:00
2021-04-12 22:11:38 +03:00
curses.start_color()
2021-04-12 21:17:06 +03:00
2021-04-12 22:11:38 +03:00
curses.init_pair(SIMPLE_COLOR, curses.COLOR_WHITE, curses.COLOR_BLACK)
curses.init_pair(ACTIVE_COLOR, curses.COLOR_BLACK, curses.COLOR_WHITE)
2021-04-12 21:17:06 +03:00
2021-04-12 22:11:38 +03:00
return stdscr
2021-04-12 21:17:06 +03:00
2021-04-12 22:11:38 +03:00
def end_curses(stdscr):
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
def generate_map(map, seed, sz_x, sz_y, map_symbols):
random.seed(seed)
for i in range(0, sz_x):
map.append(str())
for j in range(0, sz_y):
x = random.randint(0, len(map_symbols) - 1)
map[i] += map_symbols[x]
def game_step(map):
pass
def draw(stdscr, map):
stdscr.addstr(0, 0, "Hello World!", curses.color_pair(SIMPLE_COLOR))
def input(stdscr):
2021-04-12 21:17:06 +03:00
stdscr.getkey()
2021-04-12 22:11:38 +03:00
def main():
map_symbols = [' ', '#', '$', '&', '*']
stdscr = begin_curses()
map = []
generate_map(map, 2434343, 100, 100, map_symbols)
while(True):
stdscr.clear()
game_step(map)
draw(stdscr, map)
stdscr.refresh()
input(stdscr)
end_curses(stdscr)
main()