Пример #1
0
 def __init__(self, length_of_wing_in_centimeters: int, can_speak: bool,
              weight_in_grams, price, origin_country, is_predator,
              eats_in_grams):
     self.length_of_wing_in_centimeters = length_of_wing_in_centimeters
     self.can_speak = can_speak
     Animal.__init__(self, weight_in_grams, price, origin_country,
                     is_predator, eats_in_grams)
Пример #2
0
    def __init__(self, name, sound):
        """
		Creates a fish instance
		"""
        Animal.__init__(self, name)
        self.sound = sound
        Fish.number_of_fish = Fish.number_of_fish + 1
Пример #3
0
 def die(self, other):
     if self.superpower:
         self.escape()
         return False
     else:
         Animal.die(self, other)
         return True
Пример #4
0
 def __init__(self, slots=4):
     self.animals = []
     self.animals.append(Animal(20, 30))
     self.animals.append(Animal(50, 50))
     self.animals.append(Animal(80, 60))
     self.animals.append(Animal(45, 70))
     self.slots = slots
Пример #5
0
    def __init__(self, a=0, w=None):
        if w == None:
            Animal.__init__(self, 11, 4, 0, None, 'C')
        else:
            Animal.__init__(self, 11, 4, a, w, 'C')

        self.__target = None
Пример #6
0
	def __init__(self, name, eyecolor):
		"""
		Creates a cat instance
		"""
		Animal.__init__(self,name)
		self.eyecolor = eyecolor
		Cat.number_of_cats = Cat.number_of_cats + 1
Пример #7
0
    def __init__(self,
                 grid,
                 coefs=None,
                 brain=None,
                 confusion=True,
                 mask=np.ones(13)):

        Animal.__init__(self, grid)
        self.agility = 6
        self.speed = 3
        self.sight = 200

        self.confusion = confusion

        if brain: self.brain = brain
        else:
            self.brain = Perceptron(max_iter=1)
            self.initialize_brain(coefs)
        # view is the input vector for the predator's perceptron
        # (12 sections + bias)
        self.view = np.zeros(13)
        # mask is used to impair the predator's vision
        # if it's a vector of ones, all information goes through
        # we can set some values to 0 to blind certain angles
        self.mask = mask
        # wait is for the digesting period
        # (the predator has to wait 10 iterations between 2 attacks)
        self.wait = 0
Пример #8
0
 def setup(self):
     self.cat = Animal(species='cat',
                       weight=10,
                       age=15,
                       name='puss in boots')
     self.dog = Animal(species='dog', weight=8, age=20, name='Baxter')
     self.dog2 = Animal(species='dog', weight=14, age=3, name='Marley')
     self.dogpound = AnimalShelter()
Пример #9
0
 def collision(self, other):
     if other.power >= self.armour or other.species == self.species:
         Animal.collision(self, other)
     else:
         temp = Point(2 * other.position.x - self.position.x,
                      2 * other.position.y - self.position.y)
         self.wrapPosition(temp)
         if self.world.getOrganism(temp) is None:
             other.position = temp
Пример #10
0
 def __init__(self, breed, name, dogAge):
     '''
     Constructor
     '''
     Animal.__init__(
         self
     )  # this line calls the Constructor from the inherited class Animal
     self.breed = breed
     self.name = name
     self.dogAge = dogAge
Пример #11
0
class TestAnimal():
    def setup(self):
        self.cat = Animal(species='dog', weight=8, age=20, name='Baxter')
        self.dupl_cat = Animal(species='cat',
                               weight=10,
                               age=15,
                               name='puss in boots')

    def test_species(self):
        assert self.cat.species == 'DOG'

    def test_setSpecies(self):
        self.cat.setSpecies('cat')
        assert self.cat.species == 'CAT'

    def test_setWeight(self):
        self.cat.setWeight(10)
        assert self.cat.weight == 10

    def test_setAge(self):
        self.cat.setAge(15)
        assert self.cat.age == 15

    def test_setName(self):
        self.cat.setName('Puss in Boots')
        assert self.cat.name == 'PUSS IN BOOTS'

    def test_toString(self):
        assert self.cat.toString() == f"Species: {self.cat.species}, Name: {self.cat.name}, Age: {self.cat.age}," \
                                      f" Weight: {self.cat.weight:.1f}"
Пример #12
0
    def __init__(self, a = 0, w = None):

        if w == None:
            Animal.__init__(self, 5, 4, 0, None, 'P')
        else:
            Animal.__init__(self, 5, 4, a, w, 'P')
        
        self.__cooldown = 0
        self.__active = 0

        self.__control = WorldDirections.DIR_NULL
Пример #13
0
    def attack(self, numberofAttacks):
        animal = Animal()
        for run in range(numberofAttacks):
            #1. get a random tiger: getRandomTiger()
            randomTiger = self.getRandomTiger()

            #2. get a random lion: getRandomLion()
            randomLion = self.getRandomLion()

            # 3. fight(tiger, lion)
            self.fight(randomTiger, randomLion)

            # 4. remove if anyone is dead after fight
            isTigerDead = animal.isDead()
            if isTigerDead:
                self.removeTiger(randomTiger)

            isLionDead = animal.isDead()
            if isLionDead:
                self.removeLion(randomLion)


#   method: resultOfWar
#   input: army of aftermath of war
#   return: string representation of updated animals
#   method:
#       for tiger list:
#           conditionOfTigers = get tiger health and print like tiger index: health = ...
#           conditionOfTigers+= '\n'
#       print(conditionOfTigers)
#       for lion list:
#           conditionOfLions = get

# vul:
# 1. animals file er naam ta vul. animal hobe.
# 2. isdead method ta animal er method hobe, war er hobe.
# 3. removedeadanimal-> confusion toiri kore, animal er ektai collection ase. duita collection ase, so confusion hocche.
# 4. better hocche-> duita different method hobe, removetiger and remove lion

# evaluation
# war = War()
# war.attack(5) where numberOfAttacks = 5
#   1. self.lionArmy = []
#   2. self.tigerArmy = []
#   3. self.randomTigerNumber = randint(5,10)
#   4. self.randomTigerNumber = 6
#   5. self.randomLionNumber = randint(self.randomTigerNumber+2, self.randomTigerNumber + 6)
#   6. self.randomLionNumber = randint(6+2, self.randomTigerNumber + 6)
#   7. self.randomLionNumber = randint(8, self.randomTigerNumber + 6)
#   8. self.randomLionNumber = randint(8, 6+6)
#   9. self.randomLionNumber = randint(8,12)
#   10. self.randomLionNumber = 10
 def enter_clicked():  #when the enter button is clicked
     a_name = entry_animalName.get()
     if self.check_Animal(
             a_name, self.animal_list
     ) == False:  #if the animal name entered isn't already in the Database
         error.config(
             text="This animal already exists, enter another animal again"
         )  #change error message
         cont_b.place_forget()
     else:
         self.animal = Animal(
             a_name.upper())  #create a new Animal object
         error.config(text="This is a new animal, click continue"
                      )  #change error message
         cont_b.place(x=350, y=350, width=100, height=40)
def test____init___1():
    a = Animal("Cheetah", 879.0, 12, "Chilly")
    b = AnimalShelter()
    assert (a.species) == ("CHEETAH")
    assert (a.weight) == (879.0)
    assert (a.age) == (12)
    assert (a.name) == ("CHILLY")
def test____init___2():
    a = Animal("Cat", 9.0, 2, "Catherine")
    b = AnimalShelter()
    assert (a.species) == ("CAT")
    assert (a.weight) == (9.0)
    assert (a.age) == (2)
    assert (a.name) == ("CATHERINE")
def test____init___3():
    a = Animal("Chicken", 39.0, 5, "Chicky")
    b = AnimalShelter()
    assert (a.species) == ("CHICKEN")
    assert (a.weight) == (39.0)
    assert (a.age) == (5)
    assert (a.name) == ("CHICKY")
Пример #18
0
Файл: main.py Проект: skpai/oop
def main():
    a = Animal("cat", 1, 1)
    a.se_deplacer()
    s = Serpent("ss", 1, 1)
    s.se_deplacer()
    o = Oiseau("ss", 1, 1, 100)
    print(o.altmax)
    o.altmax = 150
    print(o.altmax)
    o.se_deplacer()
    o.dosomething()
    z = Zoo([s, o])
    z.dosomething()
    print(z)
    z.add_animal(a)
    print(z)
    print(z + z)
Пример #19
0
    def draw(this):
        this.screen.fill((0, 0, 0))

        for y in range(len(this.entities)):
            for x in range(len(this.entities[y])):
                if this.entities[y][x] is not None:
                    pygame.draw.rect(
                        this.screen, this.entities[y][x].getColor(),
                        pygame.Rect(x * CellDist, y * CellDist, CellSize,
                                    CellSize))
                    text = World.font.render(this.entities[y][x].DisplayChar,
                                             True, (0, 0, 0))
                    this.screen.blit(
                        text,
                        (x * CellDist + CellDist / 2 - text.get_width(),
                         y * CellDist + CellDist / 2 - text.get_height() / 2))
                else:
                    pygame.draw.rect(
                        this.screen, (40, 40, 40),
                        pygame.Rect(x * CellDist, y * CellDist, CellSize,
                                    CellSize))

        animalClasses = Animal.__subclasses__()
        plantClasses = Plant.__subclasses__()

        for i in range(len(animalClasses)):
            aClass = animalClasses[i]
            pygame.draw.rect(
                this.screen,
                aClass(this).getColor(),
                pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist,
                            CellSize, CellSize))
            text = World.font.render(aClass(this).DisplayChar, True, (0, 0, 0))
            this.screen.blit(text,
                             (i * CellDist + CellDist / 2 - text.get_width(),
                              (this.size.y + 1) * CellDist + CellDist / 2 -
                              text.get_height() / 2))

        plStIdx = len(animalClasses)
        for i in range(plStIdx, plStIdx + len(plantClasses)):
            aClass = plantClasses[i - plStIdx]
            pygame.draw.rect(
                this.screen,
                aClass(this).getColor(),
                pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist,
                            CellSize, CellSize))
            text = World.font.render(aClass(this).DisplayChar, True, (0, 0, 0))
            this.screen.blit(text,
                             (i * CellDist + CellDist / 2 - text.get_width(),
                              (this.size.y + 1) * CellDist + CellDist / 2 -
                              text.get_height() / 2))

        for i in range(len(this.comments)):
            text = World.font.render(this.comments[i] + ".", True,
                                     (255, 255, 255))
            this.screen.blit(text, ((this.size.x + 1) * CellDist, i * 10))

        pygame.display.flip()
Пример #20
0
class test_Animal(unittest.TestCase):
    def setUp(self):
        self.animal1 = Animal()

    def test_animal_hunger(self):
        self.assertEqual(self.animal1.hunger, 50)

    def test_animal_eat(self):
        self.assertEqual(self.animal1.eat(), 49)

    def test_animal_drink(self):
        self.assertEqual(self.animal1.drink(), 49)

    def test_animal_play(self):
        self.assertEqual(self.animal1.play(), "49 49")

    def test_animal_play2(self):
        self.assertEqual(self.animal1.play(), "51 51")
Пример #21
0
 def test_animal_in_range(self):
     animal = Animal()
     self.assertTrue(
         animal.get_Coordinates()['x'] < 100
         and animal.get_Coordinates()['x'] > -100, "Animal not in range X")
     self.assertTrue(
         animal.get_Coordinates()['y'] < 100
         and animal.get_Coordinates()['y'] > -100, "Animal not in range Y")
     self.assertTrue(
         animal.get_Coordinates()['z'] < 100
         and animal.get_Coordinates()['z'] > -100, "Animal not in range Z")
Пример #22
0
    def Collision(self, o):
        if self.__probability < Utilities.randomFloat(0, 1):
            newP = Navigation.Translate(self.location,
                                        WorldDirections.DIR_NULL)

            self.Move(newP)

            return False

        return Animal.Collision(self, o)
Пример #23
0
class TestAnimal(unittest.TestCase):

    def setUp(self):
        self.animal = Animal("name", 18, "male", 87, "species", 20, "carnivore", 9, 20, 100, 200, 20)

    def test_animal_init(self):
        self.assertEqual(self.animal.name, "name")
        self.assertEqual(self.animal.age, 18)
        self.assertEqual(self.animal.gender, "male")
        self.assertEqual(self.animal.weight, 87)
        self.assertEqual(self.animal.species, "species")
        self.assertEqual(self.animal.life_expectancy, 20)
        self.assertEqual(self.animal.food_type, "carnivore")
        self.assertEqual(self.animal.gestation_period, 9)
        self.assertEqual(self.animal.newborn_weight, 20)
        self.assertEqual(self.animal.average_weight, 100)
        self.assertEqual(self.animal.weight_age_ratio, 200)
        self.assertEqual(self.animal.food_weight_ratio, 20)
        self.assertTrue(self.animal.is_alive)

    def test_animal_grow(self):
        self.animal.grow()
        self.assertEqual(self.animal.age, 18.033)
        self.assertEqual(self.animal.weight, 88)

    def test_animal_eat(self):
        self.animal.eat(10)
        self.assertEqual(self.animal.weight, 97)

    def test_animal_die(self):
        results = set()
        for i in range(1000):
            self.animal.grow()
            results.add(self.animal.is_alive)
        self.assertTrue(True in results)
Пример #24
0
 def __init__(self):
     #Create a list of Animal objects
     self.animalList = []
     #Add new Animal objects to the list
     self.animalList.append(Animal("aardvark", 3, "San Diego Zoo"))
     self.animalList.append(Animal("zebra", 5, "Chyenne Mountain Zoo"))
     self.animalList.append(Animal("elephant", 17, "San Diego Zoo"))
     self.animalList.append(Animal("bird", 120, "Chyenne Mountain Zoo"))
     self.animalList.append(Animal("lion", 7, "Brooklyn Zoo"))
     self.animalList.append(Animal("tiger", 9, "Brooklyn Zoo"))
     self.animalList.append(Animal("giraffe", 4, "Chyenne Mountain Zoo"))
 def create_Animal(self):
     #allows the user to add in a new animal
     #creates a new Animal object
     print("------------------------ Add -------------------------")
     print("------------------------------------------------------")
     animal_name = self.ask_Animal_name()
     animal = Animal(animal_name)  #new Animal object is created
     animal.add_Habitat_info(self.add_continent(), self.add_country())
     animal.add_Diet_info(self.add_dietType())
     animal.add_Conservation_info(self.add_conservationStatus())
     self.animal_list.append(animal)  #adds the animal's name to the list
     print("New animal entry is successful")
     print("------------------------------------------------------")
     print("------------------------------------------------------")
     print()
Пример #26
0
 def load_Database(self, list):
     #loads the database's list from a text file and returns the list
     #input: database's list
     nameHandle = open(r"Animal Database (Non-Visual) (Animal as objects)\Animal_database", "r")
     s_dict = nameHandle.read()
     d_dict = ast.literal_eval(s_dict) #converts the string containing the list into a list
     animal_list = []
     for animal in d_dict:
         animal_info = d_dict[animal]
         obj = Animal(animal)
         habitat_info = animal_info[0]
         obj.add_Habitat_info(habitat_info[0], habitat_info[1])
         obj.add_Diet_info(animal_info[1])
         obj.add_Conservation_info(animal_info[2])
         animal_list.append(obj) #adds the Animal object to the list
     return animal_list
Пример #27
0
    def input(this):
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                this.comments.clear()

            for eArr in this.entities:
                for ent in eArr:
                    if isinstance(ent, Human):
                        ent.onEvent(event)

            if event.type == pygame.QUIT:
                return True
            if event.type == pygame.KEYDOWN:
                if (event.key == pygame.K_z):
                    this.save()
                elif (event.key == pygame.K_w):
                    this.load()
                else:
                    this.tick()
            if event.type == pygame.MOUSEBUTTONDOWN:
                mPos = Vec2(event.pos[0], event.pos[1])

                animalClasses = Animal.__subclasses__()
                plantClasses = Plant.__subclasses__()

                for i in range(len(animalClasses)):
                    if pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist,
                                   CellSize,
                                   CellSize).collidepoint(mPos.x, mPos.y):
                        this.chosenClass = animalClasses[i]
                        return False

                plStIdx = len(animalClasses)
                for i in range(plStIdx, plStIdx + len(plantClasses)):
                    if pygame.Rect(i * CellDist, (this.size.y + 1) * CellDist,
                                   CellSize,
                                   CellSize).collidepoint(mPos.x, mPos.y):
                        this.chosenClass = plantClasses[i - plStIdx]
                        return False

                for i in range(this.size.y):
                    for j in range(this.size.x):
                        idx = Vec2(j, i)
                        if pygame.Rect(j * CellDist, i * CellDist, CellSize,
                                       CellSize).collidepoint(mPos.x, mPos.y):
                            this.killEntity(idx)
                            this.spawnEntity(idx, this.chosenClass)

            return False
Пример #28
0
def main():

    a1 = Animal("Susy", 4, "matas")

    c1 = Cachorro("preto", "Dog", 4, "doméstico")
    c1.mover()
    c1.farejar()

    g1 = Galinha("Zefa", 2, "granja")
    g1.mover()
    g1.ciscar()

    print("Animal:\n " + str(a1) + "Cachorro:\n " + str(c1) + "Galinha:\n " + str(g1))

    r1 = c1+g1
    print("Soma do número de membros: ", r1)
Пример #29
0
def main():

    print("Welcome to the Animal Generator!")
    print("This program creates Animal Objects\n")

    zoo = []
    loop = 'y'

    while (loop == 'y'):
        while (True):
            try:
                animalType = input(
                    'What type of animal would you like to create? ')
                if (animalType.isdigit()):
                    print('The type cannot be a number.')
                    continue
            except:
                print('Please enter a string.')
                continue
            else:
                break

        while (True):
            try:
                name = input("What is the animal's name? ")
                if (name.isdigit()):
                    print('The name cannot be a number.')
                    continue
            except:
                print('Please enter a string')
                continue
            else:
                break

        zoo.append(Animal(animalType, name))

        loop = input("\nWould you like to evaluate another file? (y/n) ")

    print("\nAnimal List:")
    for animal in zoo:
        print(animal.get_name() + " the " + animal.get_animal_type() + " is " +
              animal.check_mood())
Пример #30
0
    def __init__(self, limit=0):

        self.level = 1
        self.limit = limit + self.level * 10
        self.animals = []
        self.price_to_upgrade = self.level * 1000.0
        self.name = "Barn"

        chicken = Animal("Chicken", "Egg", 100, 1.0, 0.8, 0.5)
        sheep = Animal("Sheep", "Wool", 200, 10.0, 8.0, 5)
        cow = Animal("Cow", "Milk", 400, 20.0, 16.0, 10.0)
        pig = Animal("Pig", "Bacon", 800, 50.0, 40.0, 25.0)
        turkey = Animal("Turkey", "Turkey's Egg", 1600, 100.0, 80.0, 50.0)
        goat = Animal("Goat", "Goat's Milk", 3200, 200.0, 160.0, 100.0)

        self.animals.append(chicken)
        self.animals.append(sheep)
        self.animals.append(cow)
        self.animals.append(pig)
        self.animals.append(turkey)
        self.animals.append(goat)

        self.button = None
Пример #31
0
 def __init__(self, a=0, w=None):
     if w == None:
         Animal.__init__(self, 4, 4, 0, None, 'S')
     else:
         Animal.__init__(self, 4, 4, a, w, 'S')
Пример #32
0
from Animal import Animal

kitty = Animal("Meowser", 18, 5, "Gray" , "Meow")

kitty.eat()
kitty.sleep()

Пример #33
0
    def __init__(self, ID, fertility, childRatio, env, age=0):
        Animal.__init__(self, ID, fertility, childRatio, env, age)

        self.gender = 'f'
        self.hasaPartner = False;
Пример #34
0
	def __init__(self, name, breed):
		Animal.__init__(self, name, "dog")
		self.name = name
		self.breed = breed
Пример #35
0
    def __init__(self, ID, fertility, childRatio, env, age=0):
        Animal.__init__(self, ID, fertility, childRatio, env, age)

        self.gender = 'm'
        self.partner=None
Пример #36
0
 def setUp(self):
     self.animal = Animal("name", 18, "male", 87, "species", 20, "carnivore", 9, 20, 100, 200, 20)
Пример #37
0
from Animal import Animal
from Puma import Puma

#Creamos un animal
animalito = Animal()

#Creamos un PUMA
pumita = Puma()

#Que coman los animalitos
animalito.comer()
pumita.comer()