コード例 #1
0
ファイル: __main__.py プロジェクト: qDes/legacy_test
 def test_animal_constructor(self):
     animal_test = Animal("test")
     self.assertEqual("test", animal_test.name,
                      "simple constructor naming test")
     self.assertEqual(100, animal_test.get_energy(),
                      "simple constructor energy test")
     animal_test = Animal("test",
                          init_parameters={
                              "name": "changed",
                              "energy": 500
                          })
     self.assertEqual("changed", animal_test.name,
                      "init parameters naming test")
     self.assertEqual(500, animal_test.get_energy(),
                      "init parameters energy test")
     self.assertEqual(self.name, self.animal.name, "setup class test")
コード例 #2
0
    def __init__(self):
        pygame.init()
        self.window = pygame.display.set_mode(
            (config.screen['width'], config.screen['height']))
        self.window_rect = pygame.Rect(
            (0, 0), (config.screen['width'], config.screen['height']))
        pygame.display.set_caption("Evolution of life")

        self.background = pygame.image.load('images/background.jpg').convert()

        self.fooda = Food()
        self.animala = Animal()

        for peacock in range(config.animalsBeggining['startingPeacocksCount']):
            peacock = Peacock()
            peacock.create()
            self.animala.animalsList.add(peacock)
            self.animala.peacocksList.add(peacock)
        for tiger in range(config.animalsBeggining['startingTigersCount']):
            tiger = Tiger()
            tiger.create()
            self.animala.animalsList.add(tiger)
            self.animala.tigersList.add(tiger)

        self.tour = 0
        self.food_collision_list = pygame.sprite.Group()
        self.peacocks_collision_list = pygame.sprite.Group()
        self.tigers_collision_list = pygame.sprite.Group()
コード例 #3
0
    def test_animal_walk(self):
        self.animal = Animal()
        with self.assertRaises(ValueError):
            self.animal.walk()

        self.animal.set_legs(2)
        self.animal.walk()
        self.assertEqual(self.animal.speed, .2)
コード例 #4
0
 def breed(self):
     if len(self.list_of_animal) == self.place_number:
         print("You have enough animal.")
     elif len(self.list_of_animal) >= self.place_number:
         print("You have too much animals!")
     else:
         for i in range((self.place_number - len(self.list_of_animal))):
             self.list_of_animal.append(Animal(i * 5, i * 10))
     print(len(self.list_of_animal))
コード例 #5
0
 def test_random_move(self):
     a_test = Animal([1, 1])
     invalid_moves = [[0, 1], [1, 0], [-1, 0], [0, -1]]
     inv2 = [[1, 0], [-1, 0], [0, -1]]
     inv3 = [[-1, 0], [0, -1]]
     inv4 = [[0, -1]]
     inv5 = []
     self.assertEqual(a_test._random_move(invalid_moves), None)
     self.assertEqual(a_test._random_move(inv2), [0, 1])
     self.assertIn(a_test._random_move(inv3), [[1, 0], [0, 1]])
     self.assertIn(a_test._random_move(inv4), [
         [1, 0],
         [0, 1],
         [-1, 0],
     ])
     self.assertIn(a_test._random_move(inv5),
                   [[0, 1], [1, 0], [-1, 0], [0, -1]])
コード例 #6
0
ファイル: main.py プロジェクト: green-fox-academy/tszabad
from animals import Animal
from farm import Farm

gekko = Animal()
python = Animal()
dog = Animal()
cat = Animal()
frog = Animal()

frog.play()
frog.play()
frog.play()
frog.play()

new_farm = Farm()

new_farm.add(gekko)
new_farm.add(python)
new_farm.add(cat)
new_farm.add(frog)
new_farm.add(dog)
new_farm.breed()

new_farm.slaughter()
コード例 #7
0
 def createAnimal(self, species, name, nr_of_legs):
     """
     Create an Animal.
     """
     self._db.create(Animal(species, name, nr_of_legs))
コード例 #8
0
 def setUpClass():
     critter = Animal()
     scooby = Dog(Animal)
     print(scooby)
コード例 #9
0
from mathdojo import MathDojo
from hospital import Patient
from hospital import Hospital
from car import Car
from callcenter import Call
from callcenter import CallCenter
from bike import Bike
from animals import Animal
from animals import Dog
from animals import Dragon

md = MathDojo(0)
print md
hosp = Hospital("Great Hospital", 6)
print hosp
patient = Patient(1, "Bob")
print patient
car = Car(5000, "75mph", "Full", "25mpg")
print car
call = Call(1, "Stephen", "770-789-7038", 8.30, "For Fun")
print call
call_center = CallCenter()
print call_center
bike = Bike(150, "15mph")
print bike
fox = Animal("Fox")
print fox
pitbull = Dog("Pitbull")
print pitbull
trogdor = Dragon("Trogdor the Burninator")
print trogdor
コード例 #10
0
 def test_can_only_create_cats_and_dogs(self):
     regex = r'^Cannot create .*: `fish`$'
     with self.assertRaisesRegexp(ValueError, regex):
         Animal('Nemo', 'fish')
コード例 #11
0
 def setUp(self):
     self.animal = Animal(name="Jerry")
コード例 #12
0
from animals import Animal, Person, Cat

if __name__ == '__main__':
    animal1 = Animal(10)
    animal1.set_name('Spot')
    # animal1.speak()

    # cat1 = Cat(5)
    # print(cat1)
    # cat1.speak()

    # person1 = Person("Kim", 25)
    # person1.add_friend('Jane')
    # person1.add_friend('Raj')
    # print(f'{str(person1)} has {len(person1.friends)} friends')

    cat1 = Cat(5)
    cat2 = Cat(5)
    cat3 = Cat(6)
    print(cat1 == cat2)
    print(cat2 == cat3)

    person1 = Person("Kim", 25)
    person2 = Person("Jane", 22)
    person1.age_diff(person2)
コード例 #13
0
    def test_can_create_dog(self):
        dog = Animal('Pluto', Animal.DOG)

        self.assertEquals(dog.name, 'Pluto')
        self.assertTrue(dog.is_dog())
        self.assertFalse(dog.is_cat())
コード例 #14
0
def find_index(x, y):
    row = y // gc.image_size
    col = x // gc.image_size
    index = row * gc.num_tiles_side + col
    return index


pygame.init()

display.set_caption('My Game')

screen = display.set_mode((512, 512))

running = True
tiles = [Animal(i) for i in range(0, gc.num_tiles_total)]
current_images = []

while running:
    current_events = event.get()
    for e in current_events:
        if e.type == pygame.QUIT:
            running = False
        if e.type == pygame.KEYDOWN:
            if e.key == pygame.K_ESCAPE:
                running = False
        if e.type == pygame.MOUSEBUTTONDOWN:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            index = find_index(mouse_x, mouse_y)
            if index not in current_images:
                current_images.append(index)
コード例 #15
0
 def create_animal():
     animal_list = []
     for i in range(6):
         animal_list.append(Animal(i * 10, i * 15))
     return animal_list
コード例 #16
0
ファイル: get_type.py プロジェクト: MiracleWong/PythonBasic
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'MiracleWong'

# OOP 之 获取对象信息
# 地址:https://www.liaoxuefeng.com/wiki/1016959663602400/1017499532944768

import types
from animals import Animal, Dog

print(type(123))
print(type('123'))
print(type(None))
print(type(abs))
a = Animal()
print(type(a))


def fn():
    pass


print(type(fn) == types.FunctionType)
print(type(abs) == types.BuiltinFunctionType)
print(type(lambda x: x) == types.LambdaType)
print(type((x for x in range(10))) == types.GeneratorType)


# 使用isinstance()
class Husky(Dog):
    def run():
コード例 #17
0
 def generate_animal(self, animal=None):
     if animal is None:
         a_pos = random.randint(0, self.size * self.size)
         a_x, a_y = int(a_pos / self.size), a_pos % self.size
         animal = Animal(a_x, a_y)
     self.animals.add(animal)
コード例 #18
0
from animals import Animal


gidget = Animal("Gidget", "dog")

fifi = Animal("Fifi", "salamander")

Animal.print_animals([gidget, fifi])


コード例 #19
0
 def setUpClass(self):
     self.bob = Dog("Bob")
     self.jacob = Animal("Jacob")
コード例 #20
0
ファイル: app.py プロジェクト: Undefeated-man/DS_tech
def main():
    loop = True
    timi = (0,0)
    
    while loop:
        running = True
        start_time = time()
        current_images = []
        matched = image.load("other_assets/matched.png")
        matched = pygame.transform.scale(matched, (diy.screen_size, diy.screen_size))
        screen.blit(matched, (0, 0))
        display.flip()
        
        tiles = [Animal(i) for i in range(0, gc.NUM_TILES_TOTAL)]
        
        # Start the game loop
        while running:
            current_events = event.get()
            
            # catch the keyboard and mouse event
            for e in current_events:
                # set a method to quit the game
                if e.type == pygame.QUIT:
                    running = False
                    return
                    
                if e.type == pygame.KEYDOWN:
                    if e.type == pygame.K_ESCAPE:
                        running = False
                
                if e.type == pygame.MOUSEBUTTONDOWN:
                    mouse_x, mouse_y = pygame.mouse.get_pos()
                    index = find_index(mouse_x, mouse_y)
                    if not index in current_images:
                        current_images.append(index)
                    if len(current_images) > 2:
                        current_images = current_images[1:]
                    
            screen.fill((255, 255, 255))
            total_skiped = 0
            for _, tile in enumerate(tiles):
                image_i = tile.image if _ in current_images else tile.box
                if not tile.skip:
                    screen.blit(image_i, (tile.col * gc.IMAGE_SIZE + gc.MARGIN,\
                    tile.row * gc.IMAGE_SIZE + gc.MARGIN))
                else:
                    total_skiped += 1
                
            display.flip()
            
            if len(current_images) == 2:
                idx1, idx2 = current_images
                if tiles[idx1].name == tiles[idx2].name:
                    tiles[idx1].skip = True
                    tiles[idx2].skip = True
                    sleep(0.2)
                    screen.blit(matched, (10, 10))
                    display.flip()
                    sleep(0.4)
                    current_images = []
            
            if total_skiped == len(tiles):
                running = False
                end_time = time()
                showResult(start_time, end_time)

            sleep(0.01)
        
        # would you like to replay?
        replay = pygame.transform.scale(image.load("other_assets/replay.png"), (diy.screen_size, diy.screen_size))
        screen.blit(replay, (0, 0))
        display.flip()
        sleep(0.01)
        
        inner_loop = True
        
        # continue to play?
        while inner_loop:
            current_events = event.get()
            for e in current_events:
                # set a method to quit the game
                if e.type == pygame.QUIT:
                    running = False
                    loop = False
                    inner_loop = False
                    return
                
                # set a method to quit the game            
                if e.type == pygame.KEYDOWN:
                    if e.type == pygame.K_ESCAPE:
                        running = False
                        loop = False
                        inner_loop = False
                    else:
                        running = True
                        loop = True
                        inner_loop = False
                        re_play()
                        break
            sleep(0.01)        
コード例 #21
0
 def test_shortcut_for_cat(self):
     self.assertEquals(
         Animal('Kitten', Animal.CAT),
         Animal.create_cat('Kitten')
     )
コード例 #22
0
 def setUp(self):
     print('setUp')
     self.dog_1 = Animal("Dog", "Food", "Barks")
     self.cat_1 = Animal("Cat", "Food", "Meow")
コード例 #23
0
 def test_shortcut_for_dog(self):
     self.assertEquals(
         Animal('Doggy', Animal.DOG),
         Animal.create_dog('Doggy')
     )
コード例 #24
0
ファイル: farm.py プロジェクト: green-fox-academy/tszabad
 def breed(self):
     if len(self.animals) < self.slots:
         animal = Animal()
         self.add(animal)
コード例 #25
0
    def test_can_create_cat(self):
        cat = Animal('Kitten', Animal.CAT)

        self.assertEquals(cat.name, 'Kitten')
        self.assertTrue(cat.is_cat())
        self.assertFalse(cat.is_dog())
コード例 #26
0
ファイル: tests.py プロジェクト: llpk79/OOP_Zoo
 def setUp(self) -> None:
     self.anim = Animal('Anim', 40)
     self.dog = Doggo('Watson', 11)
     self.lizi = Iguana('Lizi', 3)
     self.human = Human('Human', 40, 'Coding')
コード例 #27
0
 def setUpClass(self):
     self.bob = Dog("Bob")
     self.rob = Animal("Rob")
コード例 #28
0
ファイル: __main__.py プロジェクト: qDes/legacy_test
 def setUp(self):
     self.name = "test_animal"
     self.animal = Animal(self.name)