Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import random
- import trick
- class flower:
- population = 0
- def __init__(self, health = 100, dying = False, sunlightstorage = 0, waterstorage = 0, co2storage = 0, sugar = 600, age = 0, rootsize = 0, leafsize = 0, plantsize = 0, seeds = 0, phase = "sapling"):
- self.health = health
- self.dying = dying
- self.sunlightstorage = sunlightstorage
- self.waterstorage = waterstorage
- self.co2storage = co2storage
- self.sugar = sugar
- self.age = age
- self.rootsize = rootsize
- self.leafsize = leafsize
- self.plantsize = plantsize
- self.seeds = seeds
- self.phase = phase
- flower.population = flower.population + 1
- def sunlightabsorb(self, sunlight): #Takes in X units of sunlight, and stores them. X aught to be leafsize.
- self.sunlightstorage = self.sunlightstorage + sunlight
- if self.sunlightstorage > (self.plantsize * 10):
- self.sunlightstorage = (self.plantsize * 10)
- print "sunlight absorbed", self.sunlightstorage
- def waterabsorption(self, water): #Takes in X units of water, and stores them. X aught to be rootsize.
- self.waterstorage = self.waterstorage + water
- if self.waterstorage > (self.plantsize * 10):
- self.waterstorage = (self.plantsize * 10)
- print "water absorbed", self.waterstorage
- def co2absorption(self, co2): #Takes in X untis of Co2 and stores them, X aught to be leafsize.
- self.co2storage = self.co2storage + co2
- if self.co2storage > (self.plantsize * 10):
- self.co2storage = (self.plantsize * 10)
- print "co2 absorbed", self.co2storage
- def photosynthesis(self):
- if self.co2storage > 10 and self.waterstorage > 10 and self.sunlightstorage > 10:
- self.co2storage = self.co2storage - 10
- self.waterstorage = self.waterstorage - 10
- self.sunlightstorage = self.sunlightstorage - 10
- self.sugar = self.sugar + 10
- print "sugar get"
- def regeneration(self):
- if self.sugar > 4:
- self.sugar = self.sugar - (self.plantsize + self.rootsize + self.leafsize)
- else:
- grower = trick.pullrandom(("Roots", "leaves", "size"))
- if grower == "Roots":
- self.rootsize = self.rootsize - 1
- if self.rootsize < 0:
- self.rootsize = 0
- elif grower == "leaves":
- self.leafsize = self.leafsize - 1
- if self.leafsize < 0:
- self.leafsize = 0
- elif grower == "size":
- self.plantsize = self.plantsize - 1
- if self.plantsize < 0:
- self.plantsize = 0
- if self.sugar > 4:
- grower = trick.pullrandom(("Roots", "leaves", "size"))
- if grower == "Roots":
- self.rootsize = self.rootsize + 1
- elif grower == "leaves":
- self.leafsize = self.leafsize + 1
- elif grower == "size":
- self.plantsize = self.plantsize + 1
- print "roots -", self.rootsize, "leaves -", self.leafsize, "plant -", self.plantsize
- def aging(self):
- self.age = self.age + 1
- if self.age == 1640:
- self.phase = "plant"
- if self.age == 13940:
- self.phase = "flower"
- def pollination(self, wind):
- if self.seeds > 0 and self.phase == "flower":
- self.seeds = self.seeds - wind
- for i in range(1, wind):
- randomnumber = randit(1, 30)
- if randomnumber == 1:
- pass #initialize new flower
- def death(self):
- if self.plantsize == 0 and self.rootsize == 0 and self.leafsize == 0:
- pass #death
- if age == 24600:
- pass #death
- def __del__(self):
- flower.population = flower.population - 1
- co2 = 500
- water = 500
- sunlight = 500
- wind = 1
- f = flower()
- while True:
- time.sleep(1)
- f.aging()
- f.regeneration()
- if co2 >= f.leafsize and (f.leafsize + f.co2storage) < (f.plantsize * 10):
- f.co2absorption(f.leafsize)
- co2 = co2 - f.leafsize
- if sunlight >= f.leafsize and (f.leafsize + f.sunlightstorage) < (f.plantsize *10):
- f.sunlightabsorb(f.leafsize)
- if water >= f.rootsize and (f.rootsize + f.waterstorage) < (f.plantsize * 10):
- f.waterabsorption(f.rootsize)
- water = water - f.rootsize
- f.photosynthesis()
- f.pollination(wind)
- print f.age
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement