Algorytm_genetyczny #3

Merged
s481832 merged 18 commits from Algorytm_genetyczny into master 2024-06-10 13:30:20 +02:00
10 changed files with 48 additions and 9 deletions
Showing only changes of commit 693a8617f7 - Show all commits

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,8 +1,10 @@
import random
import pygame import pygame
from abc import abstractmethod from abc import abstractmethod
class Animal: class Animal:
def __init__(self, x, y,name, image, food_image, food, environment, adult=False,): def __init__(self, x, y,name, image, food_image, food, environment, activity, ill=False, adult=False,):
self.x = x - 1 self.x = x - 1
self.y = y - 1 self.y = y - 1
self.name = name self.name = name
@ -12,6 +14,8 @@ class Animal:
self.food_image = food_image self.food_image = food_image
self._feed = 0 self._feed = 0
self.environment = environment # hot/cold/medium self.environment = environment # hot/cold/medium
self.activity = activity # diurnal/nocturnal
self.ill = ill
def draw(self, screen, grid_size): def draw(self, screen, grid_size):
if self.adult: if self.adult:
@ -40,6 +44,24 @@ class Animal:
food_image = pygame.transform.scale(food_image, (int(grid_size * scale), int(grid_size * scale))) food_image = pygame.transform.scale(food_image, (int(grid_size * scale), int(grid_size * scale)))
screen.blit(food_image, (x * grid_size, (y + 1) * grid_size - int(grid_size * scale))) screen.blit(food_image, (x * grid_size, (y + 1) * grid_size - int(grid_size * scale)))
def is_ill(self):
chance = random.randint(1, 100)
if chance >= 90:
return True
def draw_illness(self, screen, grid_size, x, y):
scale = 0.45
illness_image = pygame.image.load('images/ill.png')
y = y
if self.adult:
x = x + 1
y = y
scale = 0.7
x_blit = x * grid_size + (grid_size - int(grid_size * scale))
illness_image = pygame.transform.scale(illness_image, (int(grid_size * scale), int(grid_size * scale)))
screen.blit(illness_image, (x_blit, y * grid_size))
@abstractmethod @abstractmethod
def getting_hungry(self): def getting_hungry(self):

View File

@ -51,3 +51,5 @@ def draw_Animals(Animals, const):
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/half_bowl.png') Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/half_bowl.png')
if Animal.getting_hungry() < 2: if Animal.getting_hungry() < 2:
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/full_bowl.png') Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/full_bowl.png')
if Animal.ill:
Animal.draw_illness(const.screen, const.GRID_SIZE, Animal.x, Animal.y)

View File

@ -7,9 +7,11 @@ class Bear(Animal):
Bear_image = pygame.image.load('images/bear.png') Bear_image = pygame.image.load('images/bear.png')
name = 'bear' name = 'bear'
environment = "cold" environment = "cold"
activity = 'nocturnal'
ill = self.is_ill()
bear_food = 'meat' bear_food = 'meat'
food_image = 'images/meat.png' food_image = 'images/meat.png'
super().__init__(x, y,name, Bear_image, food_image,bear_food,environment, adult) super().__init__(x, y,name, Bear_image, food_image,bear_food,environment, activity, ill, adult)
self._starttime = datetime.now() self._starttime = datetime.now()

View File

@ -9,6 +9,8 @@ class Elephant(Animal):
Elephant_image = pygame.image.load('images/elephant.png') Elephant_image = pygame.image.load('images/elephant.png')
name = 'elephant' name = 'elephant'
environment = "hot" environment = "hot"
activity = 'diurnal'
ill = self.is_ill()
if adult: if adult:
elephant_food = 'leavs' elephant_food = 'leavs'
food_image = 'images/leaves.png' food_image = 'images/leaves.png'
@ -16,7 +18,7 @@ class Elephant(Animal):
elephant_food = 'milk' elephant_food = 'milk'
food_image = 'images/milk.png' food_image = 'images/milk.png'
super().__init__(x, y,name, Elephant_image, food_image,elephant_food, environment, adult) super().__init__(x, y,name, Elephant_image, food_image,elephant_food, environment, activity, ill, adult)
self._starttime = datetime.now() self._starttime = datetime.now()

View File

@ -9,9 +9,11 @@ class Giraffe(Animal):
Giraffe_image = pygame.image.load('images/giraffe.png') Giraffe_image = pygame.image.load('images/giraffe.png')
name = 'giraffe' name = 'giraffe'
environment = "hot" environment = "hot"
activity = 'diurnal'
ill = self.is_ill()
food_image = 'images/leaves.png' food_image = 'images/leaves.png'
giraffe_food = 'leaves' giraffe_food = 'leaves'
super().__init__(x, y,name, Giraffe_image, food_image,giraffe_food, environment, adult) super().__init__(x, y, name, Giraffe_image, food_image,giraffe_food, environment, activity, ill, adult)
self._starttime = datetime.now() self._starttime = datetime.now()

View File

@ -9,9 +9,11 @@ class Parrot(Animal):
Parrot_image = pygame.image.load('images/parrot.png') Parrot_image = pygame.image.load('images/parrot.png')
name = 'parrot' name = 'parrot'
environment = "medium" environment = "medium"
activity = 'diurnal'
ill = self.is_ill()
food_image = 'images/grains.png' food_image = 'images/grains.png'
parrot_food = 'grains' parrot_food = 'grains'
super().__init__(x, y,name, Parrot_image, food_image,parrot_food, environment, adult) super().__init__(x, y, name, Parrot_image, food_image, parrot_food, environment, activity, ill, adult)
self._starttime = datetime.now() self._starttime = datetime.now()

View File

@ -9,9 +9,11 @@ class Penguin(Animal):
Penguin_image = pygame.image.load('images/penguin.png') Penguin_image = pygame.image.load('images/penguin.png')
name = 'penguin' name = 'penguin'
environment = "cold" environment = "cold"
activity = 'diurnal'
ill = self.is_ill()
food_image = 'images/fish.png' food_image = 'images/fish.png'
penguin_food = 'fish' penguin_food = 'fish'
super().__init__(x, y,name, Penguin_image, food_image,penguin_food,environment, adult) super().__init__(x, y, name, Penguin_image, food_image, penguin_food, environment, activity, ill, adult)
self._starttime = datetime.now() self._starttime = datetime.now()

BIN
images/ill.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,7 +1,6 @@
import random import random
import pygame import pygame
import sys import sys
import sys
sys.path.append('./Animals') sys.path.append('./Animals')
from animals import create_animals, draw_Animals from animals import create_animals, draw_Animals