Skip to content
Snippets Groups Projects
Commit 639e427c authored by Thomas Röck's avatar Thomas Röck
Browse files

v_1_2

parent 2945f0c9
No related branches found
No related tags found
No related merge requests found
from plant import Plant
class Bed:
def __init__(self, location: str) -> None:
self.location = location
self.plants = []
self.water_level = 0
def __repr__(self) -> str:
return f"Bed {self.location}"
def __str__(self) -> str:
return (f"{self!r}\n"
f"Water level: {self.water_level}\n"
f"{len(self.plants)} plants: {[p.species for p in self.plants]}")
def plant_plant(self, plant: Plant) -> None:
self.plants.append(plant)
def water(self, added_water: int = 1) -> None:
self.water_level += added_water
def update(self) -> None:
for plant in self.plants:
if self.water_level <= 0:
print(f"Bed {self.location} is out of water, plants can't grow")
return
self.water_level -= 1
plant.grow()
class Fruit:
def __init__(self, name: str, calories: int):
self.name = name
self.calories = calories
import random
from copy import copy
from fruit import Fruit
class Plant:
def __init__(self, species: str, growth_factor: int, fruit_template: Fruit):
self.species = species
self.growth_factor = growth_factor
self.fruit_template = fruit_template
self.size = 1
self.fruits = []
def __repr__(self):
return f"{self.species}"
def __str__(self):
return f"{self.species} of size {self.size:.1f} with {len(self.fruits)} fruits"
def grow(self):
self.size *= self.growth_factor
if random.randrange(100) < self.size:
self.fruits.append(copy(self.fruit_template))
def pick(self):
return self.fruits.pop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment