bug fix: program should no longer crash when list is longer than terminal window

This commit is contained in:
luxick
2015-08-25 12:41:37 +02:00
parent 15983586fc
commit dd28c63582

36
test.py
View File

@@ -20,24 +20,30 @@ king = Kinggotchi()
for n in range(0, 10): for n in range(0, 10):
king.add_village(Mayorgotchi(make_list(startnr))) king.add_village(Mayorgotchi(make_list(startnr)))
screen = curses.initscr() stdscr = curses.initscr()
curses.noecho() curses.noecho()
curses.curs_set(0) curses.curs_set(0)
screen.keypad(1) stdscr.keypad(1)
screen.nodelay(1) stdscr.nodelay(1)
height,width = stdscr.getmaxyx()
win = curses.newpad(16383, width)
while True: while True:
screen.move(0,0) win.move(0,0)
screen.addstr('Simulation running. Press [q] to exit.\n') win.addstr(0,0,'Simulation running. Press [q] to exit.\n')
screen.addstr('----------------------After '+str(ticks)+' ticks------------------------------\n') win.addstr(1,0,'----------------------After '+str(ticks)+' ticks------------------------------\n')
screen.addstr(king.show_kingdom()) win.addstr(3,0,king.show_kingdom())
king.step() king.step()
ticks += 1 ticks += 1
win.clrtoeol()
win.clrtobot()
win.refresh(0, 0, 0, 0, height-1, width-1)
key = stdscr.getch()
if key == ord('q'):
break
elif key < 0:
time.sleep(ticklenght)
screen.clrtobot()
key = screen.getch()
if key == ord('q'):
break
elif key < 0:
time.sleep(ticklenght)
curses.endwin() curses.endwin()