Beispiel #1
0
 def score_genotype(self, p1: flower.Flower, p2: flower.Flower,
                    child: flower.Flower, target: flower.Flower) -> int:
     dist = child.distance_from(target)
     same_as_parent = child == p1 or child == p2
     dist_parent = min(p1.distance_from(target), p2.distance_from(target))
     if dist_parent < dist and not self.have_visited(child):
         score = 1
     elif dist_parent == dist and same_as_parent:
         score = 2
     elif dist_parent < dist and self.have_visited(child):
         score = 3
     elif dist_parent == dist and not same_as_parent:
         score = 4
     elif dist_parent > dist:
         score = 5
     return score
Beispiel #2
0
    def handle_plant_flower(self, leader):
        if not(self.game.level.minimum_plant_level < leader.location.y < self.game.level.maximum_plant_level):
            return

        leader.flock.level.flowers.append(
            Flower(self.game, leader.location, age=-Settings.flower_seed_period)
        )
Beispiel #3
0
 def init_level(self):
     for location in [(235, 892), (570, 775), (970, 810)]:
         self.flowers.append(
             Flower(self.game,
                    location,
                    age=Settings.flower_adult_age *
                    random.randint(50, 100) / 100))
     self.game.active_forces.add('Hunger')
Beispiel #4
0
    def test_flower__init__(self):
        """Tests the constructor."""
        test_name = 'rose'
        test_petals = 8
        test_price = 3.50

        test_flower = Flower(test_name, test_petals, test_price)

        assert test_flower is not None
        assert isinstance(test_flower, Flower)
Beispiel #5
0
 def __init__(self, robot: cozmo.robot.Robot):
     self.cozmo = robot
     self.lift_up = 0
     self.lift_down = 0
     self.head_up = 0
     self.head_down = 0
     self.go_fast = 0
     self.go_slow = 1
     self.animations = [
         Cube(self.cozmo),
         Circle(self.cozmo),
         Flower(self.cozmo)
     ]
Beispiel #6
0
 def setUp(self):
     '''Create test objects'''
     self.alyssum = Flower(
         'yellow', -4, 20.5
     )  #All negative integers will be change into positive and all floats will be convert into ints
     self.tulip = Tulip('pink', 5, 120)
     self.rose = Rose('black', 10, 150)
     self.rose2 = Rose('yellow', 5, 200, 'hulthemia')
     self.rose3 = Rose.create_rose(175)
     self.chamomile = Chamomile('white', 20, 30, True)
     self.flowerset1 = FlowerSet([self.alyssum, self.tulip, self.rose2])
     self.flowerset2 = FlowerSet()
     self.bucket1 = Bucket([self.flowerset1, self.flowerset2])
     self.bucket2 = Bucket()
Beispiel #7
0
 def feed(self):
     retval = []
     for i in range(len(self.pitypool)):
         if (baserepro[self.pitypool[i]] +
                 bonusrepro[self.visit]) > np.random.random():
             # success!
             self.pitypool[i] = 0
             retval.append(
                 Flower(
                     self.genepool[np.random.choice(self.genemap, None,
                                                    True, self.probpool)],
                     self.visit))
         else:
             self.pitypool[i] += 1
     return retval
Beispiel #8
0
    def setup(self):
        # Set up game here. Call this fn to restart game
        self.setup_ground()

        if self.state == State.MAIN_MENU:
            self.start_screen_sprite_list = arcade.SpriteList()
            self.bee_sprite = Bee.setup_bee()
            self.start_screen_sprite_list.append(self.bee_sprite)

            # initiate & place starting screen
            self.start_screen = arcade.Sprite("sprites/start_screen.png", 1)
            self.start_screen.center_x = SCREEN_WIDTH / 2
            self.start_screen.center_y = SCREEN_HEIGHT / 2
            self.start_screen_sprite_list.append(self.start_screen)

        elif self.state == State.PLAYING:
            #initiate sprite lists
            self.bottom_obstacles_list = arcade.SpriteList()
            self.top_obstacles_list = arcade.SpriteList()
            self.flowers_list = arcade.SpriteList()
            self.player_sprite_list = arcade.SpriteList()

            #set up bee
            self.bee_sprite = Bee.setup_bee()
            self.player_sprite_list.append(self.bee_sprite)

            #set up bottom and top obstacles
            self.bottom_obstacles_list, self.top_obstacles_list = Obstacle.setup_obstacles(
                self.bottom_obstacles_list, self.top_obstacles_list)

            #place flowers for points
            self.flowers_list = Flower.setup(self.flowers_list,
                                             self.bottom_obstacles_list,
                                             self.top_obstacles_list)

            #set up score
            self.score = 0

            self.physics_engine = arcade.PhysicsEnginePlatformer(
                self.bee_sprite, self.ground_list, gravity_constant=GRAVITY)

        elif self.state == State.GAME_OVER:
            self.end_screen_sprite_list = arcade.SpriteList()
            self.end_screen = arcade.Sprite("sprites/game_over_screen.png", 1)
            self.end_screen.center_x = SCREEN_WIDTH / 2
            self.end_screen.center_y = SCREEN_HEIGHT / 2
            self.end_screen_sprite_list.append(self.end_screen)
Beispiel #9
0
def map_sprites():

    global decorations
    decorations = pygame.sprite.Group()
    decorations.add(Pond(400, 325))
    decorations.add(Road_2(150, 0))
    decorations.add(Road_2(350, 0))
    decorations.add(Road_2(550, 0))
    decorations.add(Road_2(750, 0))
    decorations.add(Road(0, 75))
    decorations.add(Road(0, 375))
    decorations.add(Road(0, 675))
    decorations.add(Box(5, 5))
    decorations.add(Box(495, 20))
    decorations.add(Box(295, 320))
    decorations.add(Box(95, 130))
    decorations.add(Box(605, 320))
    decorations.add(Box(205, 620))
    decorations.add(Box(695, 430))
    decorations.add(Box(945, 620))
    decorations.add(Box(405, 730))
    decorations.add(Box(805, 745))
    decorations.add(Tower(0, 275))
    decorations.add(Tower(200, 125))
    decorations.add(Tower(950, 275))
    decorations.add(Tower(300, 575))
    decorations.add(Fan(700, 125))
    decorations.add(Fan(950, 125))
    decorations.add(Fan(0, 625))
    decorations.add(Fan(600, 625))
    decorations.add(Fan(300, 0))
    decorations.add(Fan(200, 750))
    decorations.add(Tree(400, 125))
    decorations.add(Tree(500, 625))
    decorations.add(Flower(405, 325))
    decorations.add(Flower(530, 325))
    decorations.add(Flower(465, 300))
    decorations.add(Flower(405, 460))
    decorations.add(Flower(530, 460))
    decorations.add(Flower(465, 480))
    decorations.add(Arrow(875, 25))
Beispiel #10
0
    def test_flower_attributes(self):
        """
        Tests Flower class attributes
        """
        # Test attribute types
        flower = Flower('yellow', '23', '250')
        self.assertEqual(flower.quantity, 23)
        self.assertIsInstance(flower.color, str)
        self.assertIsInstance(flower.price, int)

        # Price can not be set for 0 quantity
        flower = Flower('yellow', 0, 120)
        self.assertEqual(flower.price, 0)

        # Price and Quantity should not be negative
        flower = Flower('yellow', -10, -120)
        self.assertEqual(flower, Flower('yellow', 10, 120))

        # Price and Quantity should be only digits
        flower = Flower('yellow', 'ten', 'one twenty')
        self.assertEqual(flower, Flower('yellow', None, None))
Beispiel #11
0
import pygame, random
from pygame.locals import *
from util import loadImage
from bee import Bee
from flower import Flower
from score import Score

pygame.init()
TITLE = 'Bee, Get the Nectar!'
screen = pygame.display.set_mode((1280, 720), 0)
screenRect = screen.get_rect()
Bee.loadImages()
Flower.loadImages()
background = loadImage('clover-large.jpg')

font = pygame.font.Font(None, 48)
text = font.render(TITLE, 1, Color('white'))
textpos = text.get_rect(centerx=screenRect.width/2, centery=25)
background.blit(text, textpos)

screen.blit(background, (0, 0))
pygame.display.flip()

bee = Bee(screenRect)
flowers = pygame.sprite.Group()
score = Score()

drawingGroup = pygame.sprite.RenderUpdates()
drawingGroup.add(bee)
drawingGroup.add(score)
Beispiel #12
0
class TestFlower(unittest.TestCase):

    def setUp(self):
        self.f = Flower("rose", 6, 100)

    def test_name(self):
        self.assertEqual(self.f.get_name(), "rose")
        self.f.set_name("cherry")
        self.assertEqual(self.f.get_name(), "cherry")

    def test_petals(self):
        self.assertEqual(self.f.get_petals(), 6)
        self.f.set_petals(10)
        self.assertEqual(self.f.get_petals(), 10)

    def test_price(self):
        self.assertEqual(self.f.get_price(), 100)
        self.f.set_price(200)
        self.assertEqual(self.f.get_price(), 200)
 def plant_seed(self, location):
     self.flowers.append(Flower(self, location))
Beispiel #14
0
    def update(self, delta_time):
        if self.state == State.MAIN_MENU:
            if self.space_pressed:
                self.state = State.PLAYING
                self.setup()

        elif self.state == State.PLAYING:
            #game movement
            self.bee_sprite.change_x = 0
            self.bee_sprite.change_y = 0

            if self.space_pressed:
                self.bee_sprite.change_x = PLAYER_JUMP_SPEED
                self.bee_sprite.change_y = PLAYER_JUMP_DISTANCE
            else:
                self.bee_sprite.change_x = PLAYER_MOVEMENT_SPEED

            #check if bee has a flower
            flower_hit_list = arcade.check_for_collision_with_list(
                self.bee_sprite, self.flowers_list)

            for flower in flower_hit_list:
                flower.remove_from_sprite_lists()
                self.score = self.score + 1

            #check if bee hit an obstacle
            bottom_obstacle_hit_list = arcade.check_for_collision_with_list(
                self.bee_sprite, self.bottom_obstacles_list)
            top_obstacle_hit_list = arcade.check_for_collision_with_list(
                self.bee_sprite, self.top_obstacles_list)

            if len(bottom_obstacle_hit_list) != 0 or len(
                    top_obstacle_hit_list) != 0:
                self.bee_sprite.angle = -90
                self.bee_sprite.change_y = 0
                self.state = State.GAME_OVER
                self.setup()

            #kill obstacles & flowers and then make new ones so that it gives "scrolling" effect
            if self.bee_sprite.center_x >= SCREEN_WIDTH:
                self.bee_sprite.center_x = bee.SPRITE_STARTING_X
                Obstacle.kill_obstacles(self.bottom_obstacles_list)
                Obstacle.kill_obstacles(self.top_obstacles_list)
                Obstacle.kill_obstacles(self.flowers_list)

            if len(self.bottom_obstacles_list) == 0 and len(
                    self.top_obstacles_list) == 0:
                self.bottom_obstacles_list, self.top_obstacles_list = Obstacle.setup_obstacles(
                    self.bottom_obstacles_list, self.top_obstacles_list)
                self.flower = Flower.setup(self.flowers_list,
                                           self.bottom_obstacles_list,
                                           self.top_obstacles_list)

            self.physics_engine.update()

        elif self.state == State.GAME_OVER:
            if self.n_pressed:
                arcade.close_window()

            if self.y_pressed:
                self.state = State.MAIN_MENU
                self.setup()
Beispiel #15
0
import random
import sys
import os
from plant import Plants
from garden import Garden
from flower import Flower
from tree import Tree

myGarden = Garden()

yellowFlower = Flower('yellow')
blueFlower = Flower('blue')
purpleTree = Tree('purple')
orangeTree = Tree('orange')

myGarden.addToGarden(yellowFlower)
myGarden.addToGarden(blueFlower)
myGarden.addToGarden(purpleTree)
myGarden.addToGarden(orangeTree)

print('\n')
myGarden.printGarden()
print('\n')
myGarden.watering(20)
myGarden.printGarden()
print('\n')
myGarden.watering(30)
myGarden.printGarden()
print('\n')
myGarden.watering(40)
myGarden.printGarden()
Beispiel #16
0
    def test_price_setter(self):
        """Tests the self._price setter."""
        test_flower = Flower('rose', 8, 3.50)
        test_flower.price = 5.55

        assert test_flower.price == 5.55
Beispiel #17
0
    def test_price_getter(self):
        """Tests the self._price getter."""
        test_flower = Flower('rose', 8, 3.50)

        assert test_flower.price == 3.50
Beispiel #18
0
    def test_number_of_petals_setter(self):
        """Tests the self._number_of_petals setter."""
        test_flower = Flower('rose', 8, 3.50)
        test_flower.number_of_petals = 13

        assert test_flower.number_of_petals == 13
Beispiel #19
0
    def test_flower_name_setter(self):
        """Tests the self._name setter."""
        test_flower = Flower('rose', 8, 3.50)
        test_flower.name = 'changed'

        assert test_flower.name == 'changed'
Beispiel #20
0
    def test_flower_name_getter(self):
        """Tests the self._name getter."""
        test_flower = Flower('rose', 8, 3.50)

        assert test_flower.name == 'rose'
Beispiel #21
0
from flower import Flower
from orchid import Orchid
from tree import Tree
from bush import Bush

screen = t.Screen()
t.ht()
t.speed("fastest")

objects = []
o_index = 0

is_drawing = False
draw_q = []

objects.append(Flower(0, 0, "pink", "orange", 20, 6, 50))
objects.append(Flower(0, 0, "lightblue", "yellow", 15, 8, 30))
objects.append(Orchid(0, 0, "purple", "pink", "yellow", 17.5))
objects.append(Orchid(0, 0, "orange", "magenta", "white", 25))
objects.append(Tree(0, 0, "brown", "green", 75, 150, 4, 75))
objects.append(Bush(0, 0, "green", "red", 50, 15, 5))

def next_object():
    global o_index
    o_index = o_index + 1 if o_index < len(objects) - 1 else 0

def last_object():
    global o_index
    o_index = o_index - 1 if o_index > 0 else len(objects) - 1

def draw_object(x, y):
Beispiel #22
0
def main():
    pygame.init()
    title = 'Bee, Get the Nectar!'
    screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
    screenRect = screen.get_rect()
    Bee.loadImages()
    Flower.loadImages()
    background = loadImage('clover-large.jpg')
    drawTitle = True
    if drawTitle:
        font = pygame.font.Font(None, 48)
        text = font.render(title, 1, Color('white'))
        textpos = text.get_rect(centerx=screenRect.width/2, centery=25)
        background.blit(text, textpos)
    screen.blit(background, (0, 0))
    pygame.display.flip()

    bee = Bee(screenRect)
    flowers = pygame.sprite.Group()
    score = Score()

    drawingGroup = pygame.sprite.RenderUpdates()
    drawingGroup.add(bee)
    drawingGroup.add(score)

    pygame.display.set_caption(title)
    pygame.mouse.set_visible(0)

    clock = pygame.time.Clock()
    angles = ((45, 90, 135), (0, 0, 180), (315, 270, 225))

    # game loop
    loop = True
    while loop:
        # get input
        for event in pygame.event.get():
            if event.type == QUIT \
                or (event.type == KEYDOWN and event.key == K_ESCAPE):
                loop = False
            
        keystate = pygame.key.get_pressed()
        xdir = keystate[K_RIGHT] - keystate[K_LEFT]   # -1, 0, or 1
        ydir = keystate[K_DOWN]  - keystate[K_UP]
        
        bee.setAngle(angles[xdir+1][ydir+1])
        bee.rect = bee.rect.move((xdir * 8, ydir * 8)).clamp(screenRect)

        # Detect collisions
        for flower in pygame.sprite.spritecollide(bee, flowers, True):
            score.score += 1
            flower.kill()
            
        if random.randint(0, 50) == 0:
            flower = Flower(screenRect)
            drawingGroup.add(flower)
            flowers.add(flower)
            
        drawingGroup.clear(screen, background)
        drawingGroup.update()
        changedRects = drawingGroup.draw(screen)
        pygame.display.update(changedRects)

        # maintain frame rate
        clock.tick(40)
        
    pygame.quit()
Beispiel #23
0
import pygame, random
from pygame.locals import *
from util import loadImage
from bee import Bee
from flower import Flower
from score import Score

pygame.init()
TITLE = 'Bee, Get the Nectar!'
screen = pygame.display.set_mode((1280, 720), 0)
screenRect = screen.get_rect()
Bee.loadImages()
Flower.loadImages()
background = loadImage('clover-large.jpg')

font = pygame.font.Font(None, 48)
text = font.render(TITLE, 1, Color('white'))
textpos = text.get_rect(centerx=screenRect.width/2, centery=25)
background.blit(text, textpos)

screen.blit(background, (0, 0))
pygame.display.flip()

bee = Bee(screenRect)
flowers = pygame.sprite.Group()
score = Score()

drawingGroup = pygame.sprite.RenderUpdates()
drawingGroup.add(bee)
drawingGroup.add(score)
def get_random_flower():
    flower_genes_len = 3 + 2 * flower_pos_bits
    random_genes = [random.randint(0, 1) for _ in range(flower_genes_len)]
    return Flower(random_genes)
Beispiel #25
0
def runGame():
    #initialize pygame, settings, and screen object
    global game_settings
    global screen
    game_settings = Settings()
    #sets screen to the width and height of the window, so assets can be blited in the window
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    #initialize
    pygame.init()
    #sets the window caption to "Bob-omb Squad"
    pygame.display.set_caption("Bob-omb Squad")
    # global variables used later on and also defines variable using the classes
    Pclick = False
    Sclick = False
    timer = 0
    cannon = Cannon_ball(screen, game_settings)
    flower = Flower(game_settings, screen)
    bomb = bobOmb(game_settings, screen)
    cloud = Cloud(game_settings, screen)
    all_sprites = pygame.sprite.Group()
    bombs = pygame.sprite.Group()

    # creates while true loop to have a continuing loop for the game
    while True:
        cloud.update()
        cloud.blitme()
        # if the event is that the user tries to exit the window, it closes the python window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            #Ben McCardy wrote this code (line 156-169)
            #checks if the user clicks down the left mouse button
            if event.type == pygame.MOUSEBUTTONDOWN:
                # sets the mouse variable to the coordinate position of the mouse cursor
                mouse = pygame.mouse.get_pos()
                mouseX, mouseY = mouse[0], mouse[1]
                cannon.pos = mouse
                # checks if the click was made in a certain area of the screen
                if (220 <= mouseX and 260 >= mouseX) and (360 <= mouseY
                                                          and 400 >= mouseY):
                    Pclick = True
                    print("pclick set to true")
            # when the user release the mouse button it resets everything and moves the cannonball back
            if event.type == pygame.MOUSEBUTTONUP:
                Pclick = False
                print("pclick set to false")
                timer = 0
                cannon.center = (240, 380)
                screen.blit(background, (0, 0))
        # checks if the spacebar button is clicked down
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    Sclick = True
            # checks if the space bar button is released
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_SPACE:
                    Sclick = True
            if Sclick == False:
                pass
            # if Slick is true, then it calls on the function to fire the cannon
            if Sclick == True:
                print('should be firing')
                print(cannon.new_pos)
                #cannon.fire()
                screen.blit(background, (0, 0))
        # if the mouse button is being clicked
        if Pclick == True:
            timer += 1
            # after a ceetain amount of time, "mouse" gathers the current mouse position
            if timer >= 100:
                mouse = pygame.mouse.get_pos()
                newpos = mouse
                # blits the background and then the cannonball over the background at the current mouse position
                screen.blit(background, (0, 0))
                screen.blit(cannon.image, newpos)

        # blits all the assets at the beginning at specific coordinates
        screen.blit(flower.image, (170, 565))
        screen.blit(flower.image, (92, 565))
        screen.blit(flower.image, (262, 565))
        screen.blit(flower.image, (340, 565))
        screen.blit(cannon.image, (220, 360))

        # updates the pygame window to display the new blits
        pygame.display.update()

    # flips the screen for the user
    pygame.display.flip()
Beispiel #26
0
from flower import Flower

#Creating 10 flowers
flower1 = Flower()
flower2 = Flower()
flower3 = Flower()
flower4 = Flower()
flower5 = Flower()
flower6 = Flower()
flower7 = Flower()
flower8 = Flower()
flower9 = Flower()
flower10 = Flower()

# How many flower1 have been picked
flower1.get_status()

#Pick flower 5
flower5.pick()

#Have many flowers have been picked
flower8.get_status()
Beispiel #27
0
    def initialize_forest(self):
        """Adds initial organisms to the map."""

        directions = list(Direction)
        # Water map
        for pool_size in WATER_POOLS:
            rand_x = random.randint(0, self.width - 1)
            rand_y = random.randint(0, self.height - 1)
            while self.water_map[rand_x][rand_y]:
                rand_x = random.randint(0, self.width - 1)
                rand_y = random.randint(0, self.height - 1)
            water_pools_added = 0
            positions = [(rand_x, rand_y)]
            WATER_POOLS_POSITIONS.append((rand_x, rand_y))
            while water_pools_added < pool_size and positions:
                # Breadth first add water pools around
                x, y = positions.pop(0)
                if not self.water_map[x][y]:
                    water = Water(self, x, y)
                    self.water_map[x][y] = water
                    water_pools_added += 1
                    # Insert all neighbors
                    random.shuffle(
                        directions)  # shuffle for a bit random shapes
                    for dir in directions:
                        new_x = x + dir.value[0]
                        new_y = y + dir.value[1]
                        # Check if out of bounds
                        if new_x < 0 or new_x >= self.width or new_y < 0 or new_y >= self.height:
                            continue
                        if self.water_map[new_x][new_y]:
                            continue
                        positions.append((new_x, new_y))

        # Plant map
        for x in range(self.width):
            for y in range(self.height):
                # check if water
                if self.water_map[x][y]:
                    continue
                if random.random() <= TREE_PERCENTAGE:
                    tree = Tree(self, x, y)
                    self.plant_map[x][y] = tree
                    if random.random() <= HIVES_PER_TREE:
                        hive = Hive(self, x, y)
                        self.animal_map[x][y].append(hive)
                        bee_amount = random.randint(HIVE_BEE_MIN_AMOUNT,
                                                    HIVE_BEE_MAX_AMOUNT)
                        bee = Bee(self,
                                  x,
                                  y,
                                  hive=hive,
                                  scout=True,
                                  age=random.randint(0, 24 * 150))
                        hive.bees.append(bee)
                        self.animal_map[x][y].append(bee)
                        for _ in range(bee_amount):
                            bee = Bee(self,
                                      x,
                                      y,
                                      hive=hive,
                                      scout=False,
                                      age=random.randint(0, 24 * 150))
                            self.animal_map[x][y].append(bee)
                            hive.bees.append(bee)
                elif random.random() <= GRASS_INIT_PERCENTAGE:
                    grass = Grass(self, x, y, random.randint(-80, 100), None,
                                  self.get_initial_water_level(x, y))
                    self.plant_map[x][y] = grass
                else:
                    earth = Earth(self, x, y,
                                  self.get_initial_water_level(x, y))
                    self.plant_map[x][y] = earth

        # Flower map
        from organisms import Type
        for x in range(self.width):
            for y in range(self.height):
                if self.water_map[x][y]:
                    continue
                if random.random() <= FLOWER_PERCENTAGE:
                    if self.plant_map[x][y] and self.plant_map[x][
                            y].type == Type.TREE:
                        continue
                    for _ in range(random.randint(1, 4)):
                        flower = Flower(self,
                                        x,
                                        y,
                                        random.randint(-50, 100),
                                        nectar=random.randint(0, 100),
                                        has_seed=random.choice([True, False]))
                        self.flower_map[x][y].append(flower)

        # Animal map
        import numpy as np
        # Rabbits
        for _ in range(BURROW_AMOUNT):
            x = random.randint(0, self.width - 1)
            y = random.randint(0, self.height - 1)
            while self.water_map[x][y]:
                x = random.randint(0, self.width - 1)
                y = random.randint(0, self.height - 1)
            burrow = Burrow(self, x, y)
            self.animal_map[x][y].append(burrow)
            rabbit_amount = random.randint(BURROW_RABBIT_MIN_AMOUNT,
                                           BURROW_RABBIT_MAX_AMOUNT)
            for _ in range(rabbit_amount):
                dx = random.randint(-3, 3)
                dy = random.randint(-3, 3)

                if x + dx < 0 or x + dx >= self.width or y + dy < 0 or y + dy >= self.height:
                    continue

                if self.water_map[x + dx][y + dy]:
                    continue

                rabbit = Rabbit(self,
                                x + dx,
                                y + dy,
                                random.choice([True, False]),
                                adult=True,
                                burrow=burrow,
                                age=random.randint(24 * 30, 24 * 30 * 3),
                                reproduction_timer=random.randint(0, 24 * 6),
                                genetics_factor=np.random.normal(1, 0.1))
                self.animal_map[x + dx][y + dy].append(rabbit)

        # Foxes
        for _ in range(FOX_AMOUNT):
            x = random.randint(0, self.width - 1)
            y = random.randint(0, self.height - 1)
            while self.water_map[x][y]:
                x = random.randint(0, self.width - 1)
                y = random.randint(0, self.height - 1)
            fox = Fox(self,
                      x,
                      y,
                      random.choice([True, False]),
                      adult=True,
                      age=random.randint(24 * 30 * 2, 24 * 30 * 6),
                      genetics_factor=np.random.normal(1, 0.1))
            self.animal_map[x][y].append(fox)
Beispiel #28
0
window = sg.Window(title_program,
                   layout,
                   auto_size_buttons=False,
                   keep_on_top=True,
                   grab_anywhere=True,
                   return_keyboard_events=True,
                   margins=(1, 1),
                   background_color="#333")

#Declaring classes passing window param
utils_ui = Utils_Ui(window)
drag_rotate = DragRotate(window)
healing = Healing(window)
rune_maker = RuneMaker(window)
flower = Flower(window)

while True:
    event, values = window.Read()

    # START DRAG AND DROP
    if not event == 'NoneType' and 'd_' in event:
        drag_rotate.handle_direction_buttons(event)

    if event == 'btn_Start':
        drag_rotate.start_array_positions(drag_rotate.get_records(),
                                          drag_rotate.get_speed(),
                                          drag_rotate.get_repeats())

    if event == 'btn_Random':
        drag_rotate.get_random_positions()
Beispiel #29
0
class TestFlower(unittest.TestCase):
    def setUp(self):
        self.f = Flower("rose", 6, 100)

    def test_name(self):
        self.assertEqual(self.f.get_name(), "rose")
        self.f.set_name("cherry")
        self.assertEqual(self.f.get_name(), "cherry")

    def test_petals(self):
        self.assertEqual(self.f.get_petals(), 6)
        self.f.set_petals(10)
        self.assertEqual(self.f.get_petals(), 10)

    def test_price(self):
        self.assertEqual(self.f.get_price(), 100)
        self.f.set_price(200)
        self.assertEqual(self.f.get_price(), 200)
Beispiel #30
0
        self.rect = self.new_pos
        self.rect.y += self.vely
        print("it fired (not really yet)")

    def blitme(self):
        screen.blit(self.image, self.new_pos)
        #         # print(self.pos)
        print("draw cannon is calling")


# global variables
game_settings = Settings()
screen = pygame.display.set_mode(
    (game_settings.screen_width, game_settings.screen_height))
cannon = Cannon_ball(screen, game_settings)
flower = Flower(game_settings, screen)
bomb = bobOmb(game_settings, screen)
cloud = Cloud(game_settings, screen)
all_sprites = pygame.sprite.Group()
bombs = pygame.sprite.Group()


#function that takes a new entity from the sprite group
def runGame():
    #initialize pygame, settings, and screen object
    #initialize
    pygame.init()
    #sets the window caption to "Bob-omb Squad"
    pygame.display.set_caption("Bob-omb Squad")
    # global variables used later on and also defines variable using the classes
    Pclick = False
Beispiel #31
0
 def setUp(self):
     self.f = Flower("rose", 6, 100)
Beispiel #32
0
 def setUp(self):
     self.f = Flower("rose", 6, 100)
Beispiel #33
0
    def count_need_water_planet(self):
        for flower in self.flowers:
            if flower.need_water():
                self.need_water_count += 1
        for tree in self.trees:
            if tree.need_water():
                self.need_water_count += 1

    def watering(self, water):
        self.count_need_water_planet()
        water_for_each = water / self.need_water_count
        for flower in self.flowers:
            if flower.need_water():
                flower.absorb_water(water_for_each)
        for tree in self.trees:
            tree.absorb_water(water_for_each)
        print(f"Watering with {water}\n" + self.garden_info())


tree1 = Tree("purple")
tree2 = Tree("orange")
flower1 = Flower("yellow")
flower2 = Flower("blue")
garden1 = Garden()
garden1.add_flower(flower1)
garden1.add_flower(flower2)
garden1.add_tree(tree1)
garden1.add_tree(tree2)
garden1.watering(40)