diff --git a/__pycache__/agent.cpython-311.pyc b/__pycache__/agent.cpython-311.pyc index 1592817..4bfbab3 100644 Binary files a/__pycache__/agent.cpython-311.pyc and b/__pycache__/agent.cpython-311.pyc differ diff --git a/__pycache__/animal.cpython-311.pyc b/__pycache__/animal.cpython-311.pyc index b0aa2ef..48fc46f 100644 Binary files a/__pycache__/animal.cpython-311.pyc and b/__pycache__/animal.cpython-311.pyc differ diff --git a/__pycache__/bear.cpython-311.pyc b/__pycache__/bear.cpython-311.pyc index a4db04f..7967955 100644 Binary files a/__pycache__/bear.cpython-311.pyc and b/__pycache__/bear.cpython-311.pyc differ diff --git a/__pycache__/elephant.cpython-311.pyc b/__pycache__/elephant.cpython-311.pyc index d42e290..92cd0a1 100644 Binary files a/__pycache__/elephant.cpython-311.pyc and b/__pycache__/elephant.cpython-311.pyc differ diff --git a/__pycache__/giraffe.cpython-311.pyc b/__pycache__/giraffe.cpython-311.pyc index 5d2e289..4f975bc 100644 Binary files a/__pycache__/giraffe.cpython-311.pyc and b/__pycache__/giraffe.cpython-311.pyc differ diff --git a/__pycache__/parrot.cpython-311.pyc b/__pycache__/parrot.cpython-311.pyc index 8576489..2142ed6 100644 Binary files a/__pycache__/parrot.cpython-311.pyc and b/__pycache__/parrot.cpython-311.pyc differ diff --git a/__pycache__/penguin.cpython-311.pyc b/__pycache__/penguin.cpython-311.pyc index 67c3c8e..4a2a7bb 100644 Binary files a/__pycache__/penguin.cpython-311.pyc and b/__pycache__/penguin.cpython-311.pyc differ diff --git a/agent.py b/agent.py index 102abec..a39f4e8 100644 --- a/agent.py +++ b/agent.py @@ -1,4 +1,5 @@ import pygame + class Agent: def __init__(self, x, y, image_path, grid_size): self.x = x @@ -29,5 +30,5 @@ class Agent: for animal in animals: if self.x == animal.x and self.y == animal.y: if animal.feed()== 'True': - animal.feed_animal() animal._feed = 0 + print(animal.name,"fed with",animal.food) diff --git a/animal.py b/animal.py index 4d4d181..b8491f6 100644 --- a/animal.py +++ b/animal.py @@ -2,11 +2,14 @@ import pygame from abc import ABC, abstractmethod class Animal: - def __init__(self, x, y, image, adult=False): + def __init__(self, x, y,name, image, food_image, food, adult=False): self.x = x - 1 self.y = y - 1 + self.name = name self.image = image self.adult = adult + self.food = food + self.food_image = food_image self._feed = 0 #nowe zwierze jest głodne def draw(self, screen, grid_size): @@ -21,6 +24,18 @@ class Animal: # If not adult, draw like normal Animal screen.blit(self.image, (self.x * grid_size, self.y * grid_size)) + def draw_exclamation(self, screen, grid_size, x, y): + exclamation_image = pygame.image.load('images/exclamation.png') + exclamation_image = pygame.transform.scale(exclamation_image, (grid_size,grid_size)) + screen.blit(exclamation_image, (x*grid_size, y*grid_size - grid_size)) + + def draw_food(self, screen, grid_size, x, y): + food_image = pygame.image.load(self.food_image) + food_image = pygame.transform.scale(food_image, (grid_size,grid_size)) + screen.blit(food_image, (x*grid_size, y*grid_size + grid_size)) + + + @abstractmethod def feed(self): @@ -29,7 +44,3 @@ class Animal: @abstractmethod def getting_hungry(self): pass - - def feed_animal(self): - if self.feed(): - self._feed = 0 \ No newline at end of file diff --git a/bear.py b/bear.py index dfbeb40..7420f94 100644 --- a/bear.py +++ b/bear.py @@ -7,15 +7,17 @@ from datetime import datetime class Bear(Animal): def __init__(self, x, y, adult=False): Bear_image = pygame.image.load('images/bear.png') - super().__init__(x, y, Bear_image, adult) - self.food_type = "fish" + name = 'bear' + bear_food = 'meat' + food_image = 'images/meat.png' + super().__init__(x, y,name, Bear_image, food_image,bear_food, adult) self._starttime = datetime.now() def feed(self): self.getting_hungry() - if self._feed < 5: + if self._feed < 2: return 'False' else: return 'True' diff --git a/elephant.py b/elephant.py index 372bdce..19698d7 100644 --- a/elephant.py +++ b/elephant.py @@ -7,15 +7,22 @@ from datetime import datetime class Elephant(Animal): def __init__(self, x, y, adult=False): Elephant_image = pygame.image.load('images/elephant.png') - super().__init__(x, y, Elephant_image, adult) - self.food_type = "leaves" + name = 'elphant' + if adult: + elephant_food = 'leavs' + food_image = 'images/leaves.png' + else: + elephant_food = 'milk' + food_image = 'images/milk.png' + + super().__init__(x, y,name, Elephant_image, food_image,elephant_food, adult) self._starttime = datetime.now() def feed(self): self.getting_hungry() - if self._feed < 1: + if self._feed < 0.3: return 'False' else: return 'True' diff --git a/giraffe.py b/giraffe.py index eba9862..bfb64b9 100644 --- a/giraffe.py +++ b/giraffe.py @@ -7,15 +7,17 @@ from datetime import datetime class Giraffe(Animal): def __init__(self, x, y, adult=False): Giraffe_image = pygame.image.load('images/giraffe.png') - super().__init__(x, y, Giraffe_image, adult) - self.food_type = "leaves" + name = 'giraffe' + food_image = 'images/leaves.png' + giraffe_food = 'leaves' + super().__init__(x, y,name, Giraffe_image, food_image,giraffe_food, adult) self._starttime = datetime.now() def feed(self): self.getting_hungry() - if self._feed < 3: + if self._feed < 0.8: return 'False' else: return 'True' diff --git a/images/fish.png b/images/fish.png new file mode 100644 index 0000000..8a5f710 Binary files /dev/null and b/images/fish.png differ diff --git a/images/grains.png b/images/grains.png new file mode 100644 index 0000000..e8fe6ce Binary files /dev/null and b/images/grains.png differ diff --git a/images/leaves.png b/images/leaves.png new file mode 100644 index 0000000..897288a Binary files /dev/null and b/images/leaves.png differ diff --git a/images/meat.png b/images/meat.png new file mode 100644 index 0000000..34a3d23 Binary files /dev/null and b/images/meat.png differ diff --git a/images/milk.png b/images/milk.png new file mode 100644 index 0000000..b51a627 Binary files /dev/null and b/images/milk.png differ diff --git a/main.py b/main.py index 40142de..bf1c208 100644 --- a/main.py +++ b/main.py @@ -24,16 +24,18 @@ pygame.display.set_caption("Mini Zoo") background_image = pygame.image.load('images/tło.jpg') background_image = pygame.transform.scale(background_image, WINDOW_SIZE) -exclamation_image = pygame.image.load('images/exclamation.png') -exclamation_image = pygame.transform.scale(exclamation_image, (GRID_SIZE,GRID_SIZE)) -an1 = Parrot(10, 2) -an2 = Penguin(12, 2) -an3 = Bear(14, 10) + + + +an1 = Parrot(16, 2) +an2 = Penguin(8, 6) +an3 = Bear(14, 9) old_an2 = Giraffe(18,4, adult=True) -old_an1 = Elephant(3, 6, adult=True) +old_an1 = Elephant(4, 7, adult=True) +an4 = Elephant(4,3) -Animals = [an1, an2, an3, old_an1, old_an2] +Animals = [an1, an2, an3, an4, old_an1, old_an2] def draw_grid(): for y in range(0, GRID_HEIGHT * GRID_SIZE, GRID_SIZE): @@ -41,14 +43,15 @@ def draw_grid(): rect = pygame.Rect(x, y, GRID_SIZE, GRID_SIZE) pygame.draw.rect(screen, BLACK, rect, 1) -def draw_exclamation(x, y): - screen.blit(exclamation_image, (x*GRID_SIZE, y*GRID_SIZE - GRID_SIZE)) + def draw_Animals(): for Animal in Animals: Animal.draw(screen, GRID_SIZE) if Animal.feed() == 'True': - draw_exclamation(Animal.x, Animal.y) + Animal.draw_exclamation(screen, GRID_SIZE, Animal.x, Animal.y) + else: + Animal.draw_food(screen,GRID_SIZE,Animal.x,Animal.y) diff --git a/parrot.py b/parrot.py index 66650db..6a7728f 100644 --- a/parrot.py +++ b/parrot.py @@ -7,15 +7,17 @@ from datetime import datetime class Parrot(Animal): def __init__(self, x, y, adult=False): Parrot_image = pygame.image.load('images/parrot.png') - super().__init__(x, y, Parrot_image, adult) - self.food_type = "grain" + name = 'parrot' + food_image = 'images/grains.png' + parrot_food = 'grains' + super().__init__(x, y,name, Parrot_image, food_image,parrot_food, adult) self._starttime = datetime.now() def feed(self): self.getting_hungry() - if self._feed < 3: + if self._feed < 1.5: return 'False' else: return 'True' diff --git a/penguin.py b/penguin.py index 61cc2da..8982e5f 100644 --- a/penguin.py +++ b/penguin.py @@ -7,8 +7,10 @@ from datetime import datetime class Penguin(Animal): def __init__(self, x, y, adult=False): Penguin_image = pygame.image.load('images/penguin.png') - super().__init__(x, y, Penguin_image, adult) - self.food_type = "fish" + name = 'penguin' + food_image = 'images/fish.png' + penguin_food = 'fish' + super().__init__(x, y,name, Penguin_image, food_image,penguin_food, adult) self._starttime = datetime.now()