You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

import curses
class Field:
cursor = (0,0)
frame =[
[1,0,0,0,0,0,0,0,0,0,0,0],
[0,1,0,0,0,0,0,0,0,0,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0],
[0,0,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0]
]
def __init__(self):
self.message = ''
self.changed = False
def clear(self):
for line in range(0,len(self.frame)):
curline = self.frame[line]
for col in range(0,len(curline)):
curline[col] = 0
def togglePixel(self):
curline = self.frame[self.cursor[0]]
curline[self.cursor[1]] = 0 if curline[self.cursor[1]] == 1 else 1
self.changed = True
def print_field(self,stdscr):
stdscr.clear()
for line in range(0,len(self.frame)):
curline = self.frame[line]
for col in range(0,len(curline)):
colour = curses.color_pair(1)
if (line,col) == self.cursor:
colour = curses.color_pair(2)
if curline[col] == 0:
stdscr.addstr(line,col,'o ',colour)
else:
stdscr.addstr(line,col,'x ',colour)
stdscr.addstr(line+1,0,'Press Space to toggle, q to quit')
if len(self.message) > 0:
stdscr.addstr(line+2,0,f'{self.message}',curses.color_pair(3))
stdscr.refresh()