Commit 4a375e73 authored by The Heavy's avatar The Heavy 🚂
Browse files

graphics

parent b87e2adf
Loading
Loading
Loading
Loading
+36 −6
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

import time
import curses
import math


class Plant:
@@ -11,7 +12,7 @@ class Plant:
        self.food = 100
        self.pot = 10
        self.timelastgrown = time.time()
        self.colour = 50
        self.health = 50
        return

    def grow(self):
@@ -20,20 +21,25 @@ class Plant:
            if self.water > 0:
                self.water -= 10
            else:
                self.colour -= 10
                self.health -= 10
                if self.health < 50 and self.height > 1:
                    self.height -= 1
                return
            if self.food > 0:
                self.food -= 1
            else:
                self.colour -= 10
                self.health -= 10
                if self.health < 50 and self.height > 1:
                    self.height -= 1
                return
            self.colour += 10
            if self.health < 100:
                self.health += 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}
        attrs = {"Height": self.height, "Water": self.water, "Food": self.food, "Health": self.health}
        return attrs


@@ -46,10 +52,17 @@ class Screen:
        curses.noecho()
        curses.cbreak()
        self.stdscr.keypad(True)
        curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
        self.potcolour = curses.color_pair(1)
        curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
        self.plantokcolour = curses.color_pair(2)
        curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
        self.plantbadcolour = curses.color_pair(3)
        self.stdscr.clear()
        return

    def update(self):
        self.drawplant()
        self.writeinfo()
        self.stdscr.refresh()

@@ -65,12 +78,29 @@ class Screen:
            line += 1
        return

    def drawplant(self):
        line = curses.LINES - 2
        self.stdscr.addstr(line, 0, "{0}{1}{0}".format(" " * math.floor((curses.COLS - self.plant.pot) / 2),
                                                       "#" * self.plant.pot), self.potcolour)
        plantloc = math.floor(curses.COLS / 2)
        plantcolour = self.plantokcolour
        if self.plant.health < 50:
            plantcolour = self.plantbadcolour
        for i in range(self.plant.height):
            line -= 1
            self.stdscr.addstr(line, plantloc, "|", plantcolour)
        for i in range(line):
            line -= 1
            if line >= 0:
                self.stdscr.addstr(line, plantloc, " ")
        return


def main(stdscr):
    plant = Plant()
    screen = Screen(stdscr, plant)
    screen.update()
    while plant.colour > 0:
    while plant.health > 0:
        time.sleep(1)
        screen.update()
        plant.grow()