moved interface to its own class, minor interface updates
This commit is contained in:
69
cli.py
Normal file
69
cli.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=UTF-8
|
||||||
|
|
||||||
|
from config import *
|
||||||
|
import curses
|
||||||
|
import time
|
||||||
|
|
||||||
|
class cursesUI:
|
||||||
|
kingdomview = True
|
||||||
|
villagenr = 0
|
||||||
|
percentage = True
|
||||||
|
running = True
|
||||||
|
|
||||||
|
def __init__(self,start_paused):
|
||||||
|
self.kingdomview = True
|
||||||
|
self.villagenr = 0
|
||||||
|
self.percentage = True
|
||||||
|
self.running = True
|
||||||
|
self.paused = start_paused
|
||||||
|
|
||||||
|
self.stdscr = curses.initscr()
|
||||||
|
curses.noecho()
|
||||||
|
curses.curs_set(0)
|
||||||
|
self.stdscr.keypad(1)
|
||||||
|
self.stdscr.nodelay(1)
|
||||||
|
|
||||||
|
height, width = self.stdscr.getmaxyx()
|
||||||
|
self.win = curses.newpad(16383, width)
|
||||||
|
|
||||||
|
def build_screen(self, king, ticks):
|
||||||
|
|
||||||
|
height, width = self.stdscr.getmaxyx()
|
||||||
|
self.win.move(0, 0)
|
||||||
|
self.win.addstr(0, 0, 'Tamagotchi Colony (alpha) - currently at tick '+str(ticks)+'.')
|
||||||
|
|
||||||
|
if self.kingdomview:
|
||||||
|
self.win.addstr(1, 0, '-----------------------------------')
|
||||||
|
self.win.addstr(2, 0, '[q]Exit [p]Pause [v]Village View')
|
||||||
|
self.win.addstr(3, 0, '-----------------------------------')
|
||||||
|
self.win.addstr(5, 0, king.show_kingdom())
|
||||||
|
else:
|
||||||
|
self.win.addstr(1, 0, '------------------------------------------------------------------')
|
||||||
|
self.win.addstr(2, 0, '[q]Exit [p]Pause [v]Kingdom View [n/m]Previous/Next [s]Percentage')
|
||||||
|
self.win.addstr(3, 0, '------------------------------------------------------------------')
|
||||||
|
self.win.addstr(5, 0, king.myvillages[self.villagenr].give_status(self.percentage))
|
||||||
|
|
||||||
|
self.win.clrtoeol()
|
||||||
|
self.win.clrtobot()
|
||||||
|
self.win.refresh(0, 0, 0, 0, height-1, width-1)
|
||||||
|
|
||||||
|
key = self.stdscr.getch()
|
||||||
|
if key == ord('q'):
|
||||||
|
self.running = False
|
||||||
|
elif key == ord('p'):
|
||||||
|
self.paused = not self.paused
|
||||||
|
elif key == ord('v'):
|
||||||
|
self.kingdomview = not self.kingdomview
|
||||||
|
elif key == ord('n'):
|
||||||
|
self.villagenr -= 1
|
||||||
|
elif key == ord('m'):
|
||||||
|
self.villagenr += 1
|
||||||
|
elif key == ord('s'):
|
||||||
|
self.percentage = not self.percentage
|
||||||
|
elif key < 0:
|
||||||
|
time.sleep(ticklenght)
|
||||||
|
if not self.running:
|
||||||
|
curses.endwin()
|
||||||
|
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
# The lenght of one game cycle in milliseconds
|
# The lenght of one game cycle in milliseconds
|
||||||
ticklenght = 0.005
|
ticklenght = 0.005
|
||||||
# Number of Tamagotchis to be created at the start of the simulation
|
# Number of Tamagotchis to be created at the start of the simulation
|
||||||
startnr = 100
|
startnr = 60
|
||||||
# The amount of points a Tamagotchi loses per tick
|
# The amount of points a Tamagotchi loses per tick
|
||||||
decayaspeed = 1
|
decayaspeed = 1
|
||||||
# If the hunger stat falls below this level Tamagotchis can be fed
|
# If the hunger stat falls below this level Tamagotchis can be fed
|
||||||
@@ -28,3 +28,5 @@ max_workpower = 6
|
|||||||
# This defines the bounds of how much a Tamagotchi can recover when eating/sleeping/playing etc.
|
# This defines the bounds of how much a Tamagotchi can recover when eating/sleeping/playing etc.
|
||||||
min_recovery = 10
|
min_recovery = 10
|
||||||
max_recovery = 20
|
max_recovery = 20
|
||||||
|
|
||||||
|
start_paused = False
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ class Kinggotchi:
|
|||||||
result = 'I am Kinggotchi '+str(self.name)+'.\nIn my Kingdom live '+str(self.all_tamagotchis())+' Tamagotichs.\nIn my Kingdom '+str(self.all_dead())+' Tamagotchis have died so far.\n\nThese are the '+str(len(self.myvillages))+' Villages in my Kingdom:\n'
|
result = 'I am Kinggotchi '+str(self.name)+'.\nIn my Kingdom live '+str(self.all_tamagotchis())+' Tamagotichs.\nIn my Kingdom '+str(self.all_dead())+' Tamagotchis have died so far.\n\nThese are the '+str(len(self.myvillages))+' Villages in my Kingdom:\n'
|
||||||
|
|
||||||
for n in self.myvillages:
|
for n in self.myvillages:
|
||||||
# result += '-----------------------------------------------------------------------------------------\n'
|
|
||||||
result += n.give_overview()
|
result += n.give_overview()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -37,6 +36,4 @@ class Kinggotchi:
|
|||||||
result = 0
|
result = 0
|
||||||
for n in self.myvillages:
|
for n in self.myvillages:
|
||||||
result += n.graveyard
|
result += n.graveyard
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
50
test.py
50
test.py
@@ -1,19 +1,16 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# coding=UTF-8
|
||||||
|
|
||||||
from mayorgotchi import Mayorgotchi
|
from mayorgotchi import Mayorgotchi
|
||||||
from kinggotchi import Kinggotchi
|
from kinggotchi import Kinggotchi
|
||||||
from util import Util
|
from util import Util
|
||||||
from config import *
|
from config import *
|
||||||
|
from cli import *
|
||||||
import time
|
import time
|
||||||
import curses
|
import curses
|
||||||
|
|
||||||
# Temporary test section
|
# Temporary test section
|
||||||
ticks = 0
|
ticks = 0
|
||||||
kingdomview = True
|
|
||||||
villagenr = 0
|
|
||||||
percentage = True
|
|
||||||
paused = False
|
|
||||||
|
|
||||||
def make_list(number):
|
def make_list(number):
|
||||||
tmp = []
|
tmp = []
|
||||||
@@ -25,46 +22,13 @@ king = Kinggotchi()
|
|||||||
for n in range(0, 30):
|
for n in range(0, 30):
|
||||||
king.add_village(Mayorgotchi(make_list(startnr)))
|
king.add_village(Mayorgotchi(make_list(startnr)))
|
||||||
|
|
||||||
stdscr = curses.initscr()
|
ui = cursesUI(True)
|
||||||
curses.noecho()
|
|
||||||
curses.curs_set(0)
|
|
||||||
stdscr.keypad(1)
|
|
||||||
stdscr.nodelay(1)
|
|
||||||
|
|
||||||
height, width = stdscr.getmaxyx()
|
|
||||||
win = curses.newpad(16383, width)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
height, width = stdscr.getmaxyx()
|
ui.build_screen(king,ticks)
|
||||||
win.move(0, 0)
|
|
||||||
win.addstr(0, 0, 'Tamagotchi Colony (alpha) - currently at tick '+str(ticks)+'.\n')
|
|
||||||
|
|
||||||
if kingdomview:
|
if not ui.paused:
|
||||||
win.addstr(2, 0, '[q]:Exit [p]:Pause [v]:Village View\n')
|
|
||||||
win.addstr(4, 0, king.show_kingdom())
|
|
||||||
else:
|
|
||||||
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))
|
|
||||||
|
|
||||||
if not paused:
|
|
||||||
king.step()
|
king.step()
|
||||||
ticks += 1
|
ticks += 1
|
||||||
win.clrtoeol()
|
if not ui.running:
|
||||||
win.clrtobot()
|
break
|
||||||
win.refresh(0, 0, 0, 0, height-1, width-1)
|
|
||||||
|
|
||||||
key = stdscr.getch()
|
|
||||||
if key == ord('q'):
|
|
||||||
break
|
|
||||||
elif key == ord('p'):
|
|
||||||
paused = not paused
|
|
||||||
elif key == ord('v'):
|
|
||||||
kingdomview = not kingdomview
|
|
||||||
elif key == ord('n'):
|
|
||||||
villagenr -= 1
|
|
||||||
elif key == ord('m'):
|
|
||||||
villagenr += 1
|
|
||||||
elif key < 0:
|
|
||||||
time.sleep(ticklenght)
|
|
||||||
|
|
||||||
curses.endwin()
|
|
||||||
Reference in New Issue
Block a user