reprezentacja_wiedzy2 #1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3
agent.py
3
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)
|
||||
|
21
animal.py
21
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
|
8
bear.py
8
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'
|
||||
|
13
elephant.py
13
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'
|
||||
|
@ -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'
|
||||
|
BIN
images/fish.png
Normal file
BIN
images/fish.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 934 KiB |
BIN
images/grains.png
Normal file
BIN
images/grains.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 398 KiB |
BIN
images/leaves.png
Normal file
BIN
images/leaves.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 96 KiB |
BIN
images/meat.png
Normal file
BIN
images/meat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 KiB |
BIN
images/milk.png
Normal file
BIN
images/milk.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 288 KiB |
23
main.py
23
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)
|
||||
|
||||
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user