Example #1
0
def main():
    global screen
    for i in range(10):
        fishes.append(Fish((width/2, height/2)))
    while True:
        clock.tick(60)
        for event in py.event.get():
            if event.type == py.QUIT:
                quit()
            if event.type == py.MOUSEBUTTONDOWN:
                fishes.append(Fish(event.pos))
            if event.type == py.KEYDOWN:
                if event.key == py.K_d:
                    sprites = fishes.sprites()
                    for i in range(len(fishes) // 2):
                        sprites[i].kill()
                elif event.key == py.K_f:
                    screen = py.display.set_mode(size, py.FULLSCREEN)
                elif event.key == py.K_ESCAPE:
                    screen = py.display.set_mode(size)
        screen.fill(color)
        for fish in fishes:
            fish.update()
            fish.draw(screen)
        py.display.flip()
Example #2
0
def catch_fish():
    from fish import Fish
    import random

    catch = Fish(random.randint(0, 20))
    result = catch.toString()
    return result
    def __init__(self, scene):
        self._fishes = []
        self._obstacles = []
        self.timer = QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(TICK)

        self._scene = scene

        for i in range(1, 101):
            color = QColor(randint(0, 255), randint(0, 255), randint(0, 255))
            max_speed = 10
            fish = Fish(randint(0, scene.width()),
                        randint(0, scene.height()),
                        color,
                        max_speed,
                        name=random_name())
            self.add_fish(fish)
            fish.set_theta(randint(0, 360))
            # fish.set_speed(10)

        for i in range(11):
            color = QColor(255, 255, 255)
            obstacle = Obstacle(randint(0, scene.width()),
                                randint(0, scene.height()), color)
            self.add_obstacle(obstacle)
Example #4
0
 def _create_fish(self, fish_number, row_number):
     fish = Fish(self)
     fish_width, fish_height = fish.rect.size
     fish.x = fish_width + 2 * fish_width * fish_number
     fish.rect.x = fish.x
     fish.rect.y = fish.rect.height + 2 * fish.rect.height * row_number
     self.fishes.add(fish)
Example #5
0
def get_all_fishes():
    conn = get_db_connection()
    rows = conn.execute(
        'SELECT fishes.id, fishes.name,lifespan, mass, fishes.length, fishes.height, red, green, blue,'
        'diets.name as diet,'
        'fins.height as height_fin, fins.length as length_fin'
        ' FROM ((fishes JOIN colors ON color_id = colors.id)'
        'JOIN diets ON diet_id = diets.id)'
        'JOIN fins ON fin_id = fins.id').fetchall()
    fishes = []
    for row in rows:
        fish = Fish()
        fish.id = row['id']
        fish.name = row['name']
        fish.mass = row['mass']
        fish.diet = str2diet(row['diet'])
        fish.height = row['height']
        fish.length = row['length']
        fish.lifespan = row['lifespan']
        fish.color = (row['red'], row['green'], row['blue'])
        fish.height_fin = row['height_fin']
        fish.length_fin = row['length_fin']
        fishes.append(fish)
    conn.close()
    return fishes
Example #6
0
 def prep_fish(self):
     self.fish = Group()
     for fish_number in range(self.stats.fish_left):
         fish = Fish(self.ai_settings, self.screen)
         fish.rect.x = 10 + fish_number * fish.rect.width
         fish.rect.y = 10
         self.fish.add(fish)
Example #7
0
class types_of_fish:

    First_type = Fish('Clownfish', '3', 'stripes')
    print("The name is " + First_type.name)
    print("The weight is " + First_type.weight + "kg")
    print("The color is " + First_type.color)

    Second_type = Fish('Tang', '2', 'yellow')
    print("The name is " + Second_type.name)
    print("The weight is " + Second_type.weight + "kg")
    print("The color is " + Second_type.color)

    Third_type = Fish('Kong', '1', 'red')
    print("The name is " + Third_type.name)
    print("The weight is " + Third_type.weight + "kg")
    print("The color is " + Third_type.color)
Example #8
0
    def __init__(self):
        # pygame.init is used to deploy the background
        pygame.init()
        # self.screen will display a window with 1200 by 700 screen size
        self.settings = Settings(self)
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        self.screen_rect = self.screen.get_rect()
        # bg_colour will give a background colour
        self.bg_colour = self.settings.bg_colour
        # self.captions will create a title at the top of the window
        pygame.display.set_caption('Blue Sky')

        self.fish = Fish(self)
        self.seaweeds = pygame.sprite.Group()
        self.worms = pygame.sprite.Group()
        self.hook = Hook(self)
        self.line = Line(self)

        self.stats = GameStats(self)

        self._create_fleet()
        self._create_worms()

        self.clock = pygame.time.Clock()
        self.counter = 0
        pygame.time.set_timer(pygame.USEREVENT, 1000)

        self.play = Button(self, 'Play')
        self.sb = Score(self)
Example #9
0
    def refresh(self, timestamp):
        """
        刷新鱼
        """
        #self.checkFishOut(timestamp)
        #暂清鱼(鱼阵出现)
        self.reloadLevel2appearCount()

        if self.removeFishes:
            if timestamp >= self.removeFishTimestamp:
                for _fish in self.removeFishes:
                    if _fish.id in self.fishIdx:
                        self.remove(_fish)
                self.removeFishes = []
                self.removeFishTimestamp = 0

        #鱼阵激活
        if not self.fishArray.isStarted:
            if timestamp - self.lastFishArrayTimestamp >= self.fishArrayAppearTick:
                self.game.randomBgIdx()

                #清鱼缓存
                self.removeFishes = []
                self.removeFishes.extend(self.fishs)
                self.removeFishTimestamp = timestamp + FISH_REMOVE_AFTER_ARRAY

                fishArrayProto = S_C_FishArray()
                fishArrayProto.timestamp = timestamp
                fishArrayProto.bgIdx = self.game.bgIdx
                fishArrayData = self.game.server.fishArrayGenerator.getFishData(
                )
                log(u'Fish Array gen fishs count[%d] duration[%s] fish idx[%d]'% \
                    (len(fishArrayData.fishDatas), fishArrayData.duration, self.idx))
                for fishData in fishArrayData.fishDatas:
                    #                    log(u'fish level[%d] initRot[%d] initPos[%s, %s] duration[%s] multi[%d] rate[%d] route[%s]'% \
                    #                        (fishData.level, fishData.initRot, fishData.x, fishData.y, fishData.duration, fishData.multi, fishData.rate, fishData.route))
                    fish = Fish(self.genId(), fishData.idx, fishData.level, fishData.order, timestamp + fishData.timestampOffset, fishData.initRot, \
                        fishData.x, fishData.y, fishData.duration, fishData.multi, fishData.rate, fishData.dice, fishData.route)
                    self.add(fish)
                    pbAppendFishList(fishArrayProto.fishs, fish,
                                     self.game.server.showFishHitCoiunt)
                self.game.sendAll(fishArrayProto)
                self.fishArray.duration = fishArrayData.duration
                self.fishArray.start(timestamp)
            else:
                self.genFishs(timestamp)
                #log(u'current fishs count[%s]'%(len(self.fishs)))
        else:
            #没鱼了或鱼阵结束
            if self.fishArray.isOver(timestamp):
                log(u'fish array over duration[%s]' %
                    (self.fishArray.duration))
                self.destroy()
                self.fishArray.stop()
                self.nextFishGenTimestamp = 0
                self.lastFishArrayTimestamp = timestamp
                self.fishArrayAppearTick = random.randint(
                    FISH_ARRAY_APPEAR_SEC[0], FISH_ARRAY_APPEAR_SEC[1]) * 1000
                self.genFishs(timestamp)
Example #10
0
def create_pool(screen, settings, fishes, cat):
	"""Create a full pool of fishes"""
	fish = Fish(screen, settings)
	number_fishes_x = get_number_fishes_x(settings, fish.rect.width)
	number_rows = get_number_rows(settings, cat.rect.height, fish.rect.height)
	for row_number in range(number_rows):
		for fish_number in range(number_fishes_x):
			create_fish(screen, settings, fishes, fish_number, row_number, cat)
Example #11
0
 def __init__(self):
     self.fish_image = pygame.image.load(
         os.path.join("flappy_fish", "images", "fish.png"))
     self.alive = [
         Fish(image=self.fish_image) for _ in range(config.FISH_NR)
     ]
     self.dead = []
     self.max_score = 0
def create_fish(ai_settings, screen, fishes, fish_number, row_number):
    """Create fish and place it in row"""
    #Create fish and place it in row
    fish = Fish(ai_settings, screen)
    fish_width = fish.rect.width
    fish.x = fish_width + 2 * fish_width * fish_number
    fish.rect.x = fish.x
    fish.rect.y = fish.rect.height + 2 * fish.rect.height * row_number
    fishes.add(fish)
Example #13
0
def new_fish_pop(minds,colors,size_w = (600,900,3),s1=100,s2=100):
    n_pop = minds.shape[0]
    size_w1,size_w2 = size_w[:2][::-1]
    pos_orient_color = [ (  rand.randint(s1,size_w2-s1),rand.randint(s2,size_w1-s2),2*pi*rand.random(),np.random.choice(range(256), size=3, replace=False)) for i in range(n_pop)]
    fishes = [Fish(orient=o,pos=(p1,p2),color=c) for p1,p2,o,c in pos_orient_color]
    for f,c,m in zip(fishes,colors,minds):
        f.color =  [np.asscalar(e) for e in c]
        f.mind = f.init_mind(variables = m)
    return fishes
Example #14
0
    def __generate_random_river__(self, qty):
        for i in range(0, qty):
            random_num = random.randint(0, 2)

            if random_num == 0:
                self.__river__.append(None)
            elif random_num == 1:
                self.__river__.append(Fish(0, random.randint(1, 2)))
            elif random_num == 2:
                self.__river__.append(Bear(0, random.randint(1, 2), 0))
Example #15
0
    def __init__(self):

        pygame.init()
        self.window = pygame.display.set_mode((50 * 3, 300))

        self.czcionka = pygame.font.SysFont("comicsans", 20)
        self.player = player("./res/man.png")
        self.fishes.append(Fish("./res/blackfish.png"))
        self.fishes.append(Fish("./res/blackfish.png"))
        self.fishes.append(Fish("./res/blackfish.png"))

        self.fishes[0].rect.y = -350
        self.fishes[1].rect.y = -440
        self.fishes[2].rect.y = -525

        while True:
            self.window.fill(self.color)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit(0)
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    sys.exit(0)

            if (pygame.key.get_pressed()[pygame.K_SPACE]):
                a = Game()

            if (self.catched == True):
                self.text = "score" + str(self.score)
            self.text_render = self.czcionka.render(self.text, 1,
                                                    (250, 250, 250))
            self.window.blit(self.text_render, (10, self.texty))

            self.window.blit(player.getImage(self.player),
                             (self.player.rect.x, self.player.rect.y))
            self.window.blit(Fish.getImage(self.fishes[0]),
                             (self.fishes[0].rect.x, self.fishes[0].rect.y))
            self.window.blit(Fish.getImage(self.fishes[1]),
                             (self.fishes[1].rect.x, self.fishes[1].rect.y))
            self.window.blit(Fish.getImage(self.fishes[2]),
                             (self.fishes[2].rect.x, self.fishes[2].rect.y))

            self.Ticking()
            pygame.display.flip()
Example #16
0
def create_fish(screen, settings, fishes, fish_number, row_number, cat):
	"""Create a fish and put it in a row"""
	fish = Fish(screen, settings)
	fish_width = fish.rect.width
	fish_height = fish.rect.height
	fish.x = fish_width + 2 * fish_width * fish_number
	fish.y = fish_height + 2 * fish_height * row_number + cat.rect.height
	fish.rect.x = fish.x
	fish.rect.y = fish.y
	fishes.add(fish)
Example #17
0
def main():
    #backgrounds, screen, clock, song, font = setup()
    backgrounds, background_size = setup_backgrounds("far", "sand",
                                                     "foreground")
    font = setup_displays("main_theme", "Pixeled.ttf")
    clock = setup_clock()
    screen = setup_screen(background_size)

    menu(backgrounds, screen, clock)

    #a list of all sprites
    all_sprites_list = pygame.sprite.Group()
    sharks = pygame.sprite.Group()
    sushis = pygame.sprite.Group()

    #objects
    fish = Fish()
    shark = Shark()
    sushi = Sushi()

    #add sprites to lists
    all_sprites_list.add(fish)
    all_sprites_list.add(shark)
    all_sprites_list.add(sushi)
    sharks.add(shark)
    sushis.add(sushi)

    timer = 1
    #run until sys.exit() is detected
    while True:
        #print(len(sharks))
        if (timer % 150 == 0):
            #print(len(sharks))
            #make a new shark and add to the lists
            shark = Shark()
            sharks.add(shark)
            all_sprites_list.add(shark)
        elif (timer % 225 == 0):
            sushi = Sushi()
            sushis.add(sushi)
            all_sprites_list.add(sushi)
        timer += 1

        pressed_key = pygame.key.get_pressed()

        check_for_quit(pressed_key)
        draw_background(screen, backgrounds)
        animate(fish, sharks, sushis, all_sprites_list, font, pressed_key,
                backgrounds, screen)
        check_off_screen(sharks, sushis)

        #afterwards, display the new screen after updates are finalized
        pygame.display.flip()
        clock.tick(FPS)
Example #18
0
 def prepare_values(item):
     if item == '---':
         return None
     elif item[0] == 'B':
         gender = 1 if item[1] == 'F' else 2
         age = int(item[2])
         return Bear(age, gender, 0)
     elif item[0] == 'F':
         gender = 1 if item[1] == 'F' else 2
         age = int(item[2])
         return Fish(age, gender)
Example #19
0
    def add_fish(self):
        """
        add 20 fish

        """
        for i in range(0, 20):
            fish = Fish()
            fish.init_pos()
            fish.angle = randint(0, 360)
            fish.velocity = Vector(-3, 0).rotate(fish.angle)
            self.add_widget(fish)
            self.flock_list.append(fish)
Example #20
0
    def __init__(self, load=None):
        if load:
            temp = {}
            for filename in os.listdir(load):
                order = int(filename.split(".")[0])
                data = numpy.load(load + "/" + filename)

                temp[order] = data

            brain = []
            for i in temp:
                brain.append(temp[i])

            self.fish = Fish(brain)
        else:
            self.fish = Fish()
        self.food = Food(self.fish.x, self.fish.y, self.fish.z)

        self.numEaten = 0

        self.eatDistance = 0.01
Example #21
0
 def spawn(self, grid, creature_type):
     spawned = False
     while not spawned:
         x = random.randint(0, HEIGHT - 1)
         y = random.randint(0, WIDTH - 1)
         if grid[x][y] == 0:
             spawned = True
     if creature_type == "fish":
         grid[x][y] = 1
         fish = Fish(x, y)
     elif creature_type == "shark":
         grid[x][y] = 2
         shark = Shark(x, y)
Example #22
0
    def get_random_fish(self):
        fish_pool = random.choices(population=ft.all_fish,
                                   weights=fish.rarity_weights,
                                   k=1)[0]
        print(fish_pool)
        next_fish = fish_pool[random.randint(0, len(fish_pool) - 1)]
        return Fish(next_fish)


# x = Game(1,1)
# for _ in range(10):
# x.cast_reel()
# print(x.next_fish)
def create_school(ai_settings, screen, mermaid, fishes):
    """Create school of fish"""
    #Create fish + find number of fish that fit in one row
    #Spacing between fish = 1 fish width
    fish = Fish(ai_settings, screen)
    number_fishes_x = get_number_fishes_x(ai_settings, fish.rect.width)
    number_rows = get_number_rows(ai_settings, mermaid.rect.height,
                                  fish.rect.height)

    #Create school of fish
    for row_number in range(number_rows):
        for fish_number in range(number_fishes_x):
            create_fish(ai_settings, screen, fishes, fish_number, row_number)
Example #24
0
    def __init__(self, *args, **kwargs):
        self.size = (Window.width, Window.height)

        super(FredLifeGame, self).__init__(*args, **kwargs)

        self.victory_screen = FredLifeScore()
        self.manufacture_ships(3)

        self.fish = Fish(
            box=[self.game_area.x, self.game_area.y + 65, self.game_area.width, self.game_area.height - 175])
        self.fish.bind(pos=lambda instance, value: self.check_for_smthing_to_eat(value))
        self.fish.bind(calories=self.update_calories_bar)
        self.fish.bind(on_death=self.the_end)
Example #25
0
 def spawn_creature(self, grid, creature_type):
     """Randomly choose beginning location of creatures."""
     spawned = False
     while not spawned:
         x = random.randint(0, HEIGHT - 1)
         y = random.randint(0, WIDTH - 1)
         if grid[x][y] == 0:
             spawned = True
     if creature_type == "fish":
         grid[x][y] = 1
         fish = Fish(x, y)
     elif creature_type == "shark":
         grid[x][y] = 2
         shark = Shark(x, y)
Example #26
0
    def _create_fleet(self):
        fish = Fish(self)
        fish_width, fish_height = fish.rect.size
        available_space_x = self.settings.screen_width - (2 * fish_width)
        number_fishes_x = available_space_x // (2 * fish_width)

        octopus_height = self.octopus.rect.height
        available_space_y = (self.settings.screen_height - (3 * fish_height) -
                             octopus_height)
        number_rows = available_space_y // (2 * fish_height)

        for row_number in range(number_rows):
            for fish_number in range(number_fishes_x):
                self._create_fish(fish_number, row_number)
Example #27
0
    def add_replica(self, replica_id, position):
        x = self.get_replica_x(replica_id)
        y = self.get_replica_y(x, position)

        final_y = self.get_replica_y(0, position)
        self.replicas_coordinates.append((x, y, final_y))

        replica = Fish(x,
                       y,
                       self.width,
                       self.height,
                       self.shaded_area_x,
                       replica=True,
                       replica_final_y=final_y)
        self.shoal.append(replica)
Example #28
0
 def __init__(self):
     self.world_time = time.time()
     # self.fish.set_parent(self)
     # for f in self.fish:
     # f.set_parent(self)
     # create initial fish
     for i in range(10):
         f = Fish(random.randint(0, 600), random.randint(0, 600), 10)
         f.set_parent(self)
         self.fish.append(f)
     # create initial food
     for i in range(20):
         fx = random.randint(0, screen_width)
         fy = random.randint(0, screen_height)
         self.food.append(Food(fx, fy))
     return
Example #29
0
    def __init__(self, step, visual, trynumber, fatorLotacao, fishQtd,
                 iteracoes):
        self.fishs = []

        for _ in range(fishQtd):
            self.fishs.append(Fish())

        self.step = step
        self.visual = visual
        self.trynumber = trynumber
        self.fatorLotacao = fatorLotacao
        self.fishQtd = fishQtd
        self.iteracoes = iteracoes

        print("valores iniciais")
        for fish in self.fishs:
            print(fish.getRepresentation())
Example #30
0
    def castLine(self):

        #retrieve a fish object and get its species/wikipedia page
        num = random.randint(0, 20)
        fish = Fish(num)
        catch = fish.castLine()
        species = catch.species
        wikiURL = catch.wiki_url
        fishID = catch.number

        #format the string for the screen's label
        if (species != "You fail to catch a fish"):
            species = "You caught a " + species
        self.ids._catch_label.text = species

        #dictionary of the image URL's
        #TODO find a better way to implement these
        fishImages = {
            1: "Trout.png",
            2: "Salmon.png",
            3: "Crayfish.png",
            4: "Shark.png",
            5: "Boots.png",
            6: "Lobster.png",
            7: "Sardine.png",
            8: "Mackerel.png",
            9: "Crab.png",
            0: "Seaweed.png"
        }

        #get the url for the image
        image = fishImages.get(fishID)

        #update the fish tally
        if (catch.number < 10):
            self.fish_tally[catch.number] += 1

        self.wiki_button.bind(on_press=partial(webbrowser.open, wikiURL))

        #if the fishID doesn't have an image, just default to seaweed for now
        if image == None:
            image = "sadFace.png"

        # TODO add a link to the wikipedia page when you click on the image
        self.ids._fish_image.source = "images/" + image