Change Views when paused

This commit is contained in:
luxick
2015-08-26 13:26:29 +02:00
parent 9dd23d262e
commit c21413c789
2 changed files with 15 additions and 15 deletions

View File

@@ -33,7 +33,7 @@ class Mayorgotchi:
def give_overview(self): def give_overview(self):
result = '' result = ''
tmp = self.get_status_list() tmp = self.get_status_list()
result += 'Village of Mayor {0:10} Population:{1:5} Dead:{2:5} Idle:{3:5} Eating:{4:5} Sleeping:{5:5} Bathing:{6:5} Playing:{7:5} Working:{8:5}\n'.format(self.name,str(len(self.mygotchis)),str(self.graveyard),str(len(tmp[0])), str(len(tmp[1])), str(len(tmp[2])), str(len(tmp[3])), str(len(tmp[4])), str(len(tmp[5]))) result += 'Village of Mayor {0:13} Population:{1:5} Dead:{2:5} Idle:{3:5} Eating:{4:5} Sleeping:{5:5} Bathing:{6:5} Playing:{7:5} Working:{8:5}\n'.format(self.name,str(len(self.mygotchis)),str(self.graveyard),str(len(tmp[0])), str(len(tmp[1])), str(len(tmp[2])), str(len(tmp[3])), str(len(tmp[4])), str(len(tmp[5])))
return result return result
def get_status_list(self): def get_status_list(self):
@@ -68,7 +68,7 @@ class Mayorgotchi:
if n.status is 'Idle': if n.status is 'Idle':
freegotchis.append(n) freegotchis.append(n)
if len(freegotchis) > 0: if len(freegotchis) > 0:
return freegotchis[random.randrange(0,len(freegotchis),1)] return freegotchis[random.randrange(0, len(freegotchis), 1)]
else: else:
return None return None

26
test.py
View File

@@ -13,6 +13,7 @@ ticks = 0
kingdomview = True kingdomview = True
villagenr = 0 villagenr = 0
percentage = True percentage = True
paused = False
def make_list(number): def make_list(number):
tmp = [] tmp = []
@@ -30,22 +31,24 @@ curses.curs_set(0)
stdscr.keypad(1) stdscr.keypad(1)
stdscr.nodelay(1) stdscr.nodelay(1)
height,width = stdscr.getmaxyx() height, width = stdscr.getmaxyx()
win = curses.newpad(16383, width) win = curses.newpad(16383, width)
while True: while True:
win.move(0,0) height, width = stdscr.getmaxyx()
win.addstr(0,0,'Tamagotchi Colony (alpha) - currently at tick '+str(ticks)+'.\n') win.move(0, 0)
win.addstr(0, 0, 'Tamagotchi Colony (alpha) - currently at tick '+str(ticks)+'.\n')
if kingdomview: if kingdomview:
win.addstr(2,0,'[q]:Exit [p]:Pause [v]:Village View\n') win.addstr(2, 0, '[q]:Exit [p]:Pause [v]:Village View\n')
win.addstr(4,0,king.show_kingdom()) win.addstr(4, 0, king.show_kingdom())
else: else:
win.addstr(2,0,'[q]:Exit [p]:Pause [v]:Kingdom View [n/m]:Previous/Next Village\n') win.addstr(2, 0, '[q]:Exit [p]:Pause [v]:Kingdom View [n/m]:Previous/Next Village\n')
win.addstr(4,0,king.myvillages[villagenr].give_status(percentage)) win.addstr(4, 0, king.myvillages[villagenr].give_status(percentage))
king.step() if not paused:
ticks += 1 king.step()
ticks += 1
win.clrtoeol() win.clrtoeol()
win.clrtobot() win.clrtobot()
win.refresh(0, 0, 0, 0, height-1, width-1) win.refresh(0, 0, 0, 0, height-1, width-1)
@@ -54,10 +57,7 @@ while True:
if key == ord('q'): if key == ord('q'):
break break
elif key == ord('p'): elif key == ord('p'):
while True: paused = not paused
unpause_key =stdscr.getch()
if unpause_key == ord('p'):
break
elif key == ord('v'): elif key == ord('v'):
kingdomview = not kingdomview kingdomview = not kingdomview
elif key == ord('n'): elif key == ord('n'):