Loading plantmanager.py +39 −10 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ class Plant: self.food = 100 self.pot = 10 self.timelastgrown = time.time() self.colour = 0 self.colour = 50 return def grow(self): Loading @@ -27,23 +27,52 @@ class Plant: else: self.colour -= 10 return self.colour += 10 if self.height < self.pot: self.height += 1 return def getattr(self): attrs = {"Height": self.height, "Water": self.water, "Food": self.food, "Colour": self.colour} return attrs def main(stdscr): plant = Plant() stdscr.clear() class Screen: def __init__(self, stdscr, plant): self.stdscr = stdscr self.plant = plant self.statuspos = curses.COLS - 7 curses.curs_set(False) curses.noecho() curses.cbreak() stdscr.keypad(True) while plant.colour > -100: self.stdscr.keypad(True) self.stdscr.clear() return def update(self): self.writeinfo() self.stdscr.refresh() def writeinfo(self): attrs = self.plant.getattr() maxlen = 0 for k in attrs.keys(): if len(k) > maxlen: maxlen = len(k) line = 1 for k, v in attrs.items(): self.stdscr.addstr(line, self.statuspos - maxlen, "{0}:{1}{2: 4}".format(k, " " * (maxlen - len(k)), v)) line += 1 return def main(stdscr): plant = Plant() screen = Screen(stdscr, plant) screen.update() while plant.colour > 0: time.sleep(1) stdscr.addstr(3, 3, "height: {0}; water: {1}; food: {2}; colour: {3};".format(plant.height, plant.water, plant.food, plant.colour)) stdscr.refresh() screen.update() plant.grow() stdscr.addstr(4, 3, "It died") stdscr.refresh() Loading Loading
plantmanager.py +39 −10 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ class Plant: self.food = 100 self.pot = 10 self.timelastgrown = time.time() self.colour = 0 self.colour = 50 return def grow(self): Loading @@ -27,23 +27,52 @@ class Plant: else: self.colour -= 10 return self.colour += 10 if self.height < self.pot: self.height += 1 return def getattr(self): attrs = {"Height": self.height, "Water": self.water, "Food": self.food, "Colour": self.colour} return attrs def main(stdscr): plant = Plant() stdscr.clear() class Screen: def __init__(self, stdscr, plant): self.stdscr = stdscr self.plant = plant self.statuspos = curses.COLS - 7 curses.curs_set(False) curses.noecho() curses.cbreak() stdscr.keypad(True) while plant.colour > -100: self.stdscr.keypad(True) self.stdscr.clear() return def update(self): self.writeinfo() self.stdscr.refresh() def writeinfo(self): attrs = self.plant.getattr() maxlen = 0 for k in attrs.keys(): if len(k) > maxlen: maxlen = len(k) line = 1 for k, v in attrs.items(): self.stdscr.addstr(line, self.statuspos - maxlen, "{0}:{1}{2: 4}".format(k, " " * (maxlen - len(k)), v)) line += 1 return def main(stdscr): plant = Plant() screen = Screen(stdscr, plant) screen.update() while plant.colour > 0: time.sleep(1) stdscr.addstr(3, 3, "height: {0}; water: {1}; food: {2}; colour: {3};".format(plant.height, plant.water, plant.food, plant.colour)) stdscr.refresh() screen.update() plant.grow() stdscr.addstr(4, 3, "It died") stdscr.refresh() Loading