def gem_refresh(screen, gems, frame_gem):
    if pygame.time.get_ticks() > frame_gem:
        gem = Gem(screen)
        gems.add(gem)
        frame_gem += 30000
    gems.update()
    return frame_gem
Beispiel #2
0
    def __init__(self, redis, features={}):
        Generator.__init__(self, redis, features)
        self.logger = logging.getLogger(__name__)

        if not hasattr(self, 'gem'):
            setattr(self, 'gem', Gem(self.redis))

        if not hasattr(self, 'text'):
            self.text = self.render_template(self.template)
            self.text = self.render_template(self.text)
        self.text = self.text[0].capitalize() + self.text[1:]
Beispiel #3
0
    def fall(self):
        # This function makes the gems fall

        # The function checks every gem if there's a blank space under them
        # if so, then move them down
        # This is also the reason why there's [1]

        for i in range(self.__height):  # [1]
            for row in range(self.__height - 1):
                for col in range(self.__width):
                    gem_from = self.getGem(row, col)
                    gem_to = self.getGem(row + 1, col)
                    if (gem_from.id != self.__blank_id and \
                        gem_to.id == self.__blank_id):
                        # Create new Gem
                        self.setGem(row + 1, col, self.getGem(row, col))
                        # Remove old Gem (create blank gem)
                        self.setGem(row, col, Gem(self.__blank_id))
Beispiel #4
0
    def __init__(self, model, escena, gems, gemspos, gemcount, planes,
                 planespos, nextScene, gemsound, planesound):
        self.mine = viz.addChild(model, scene=escena)

        self.planeList = list()
        contpos = 0

        for x in planes:
            planeitem = Plane(x, planespos[contpos], escena,
                              nextScene[contpos], planesound)
            self.planeList.append(planeitem)
            contpos = contpos + 1

        self.btn_regresa = viz.addButtonLabel("regresar", scene=escena)
        self.btn_regresa.setPosition(0.9, 0.1)

        self.gemList = list()
        contpos = 0

        print escena
        for x in gems:
            gemitem = Gem(x, gemspos[contpos], escena, gemsound)
            self.gemList.append(gemitem)
            contpos = contpos + 1
def run_game():
    #初始化游戏
    pygame.init()
    #创建一个屏幕对象
    ai_setting = Setting()
    screen = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_height))
    # jack=Jack(screen)
    background = Background(screen)
    #设置窗口名称
    pygame.display.set_caption("唤兽世界")

    gf = Game_function(screen)

    jifen = JiFen()

    kai_shi = Kaishi(screen)
    kai_shi.kaishi()

    begingame = False
    pygame.mixer.music.load("music/begin_music.wav")
    pygame.mixer.music.play(-1, 0)

    spirits = Group()

    xl = 6
    for i in range(5):
        x = random.randint(0, 1201)
        y = random.randint(0, 801)
        spirit = Spirit(screen, x, y)
        spirits.add(spirit)

    attack = Attack(screen)
    gems = Group()
    gem = Gem(screen)

    end = True
    win = True

    nests = Group()
    nest = Monster_nest(screen)
    nests.add(nest)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                #系统退出
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    begingame = True
                    background.blitme()

                    jack = Jack(screen, gf)

                    jifen.blit_me(screen)

                    pygame.mixer.music.load("music/music.wav")
                    pygame.mixer.music.play(-1, 0)

                    ai_xin = Ai_xin(screen)

                    jack.blitme()

                    frame_spirit = pygame.time.get_ticks()
                    frame_treehole = pygame.time.get_ticks()
                    frame_treehole_spirit = pygame.time.get_ticks()
                    frame_koxie = pygame.time.get_ticks()
                    frame_gem = pygame.time.get_ticks()
                    frame_hyjq = pygame.time.get_ticks()
                    frame_fq = pygame.time.get_ticks()
        if begingame == True and xl > 0 and jifen.jifen < ai_setting.win:
            jack.jack_move(background, spirits, gems, nests)
            jack.jack_attack(attack)

            jifen.blit_me(screen)

            ai_xin.js_xl(xl)

            frame_spirit = re.spirit_refresh(screen, spirits, frame_spirit)
            frame_gem = re.gem_refresh(screen, gems, frame_gem)
            nests.update()
            frame_treehole_spirit = re.treehole_spirit_refresh(
                screen, spirits, frame_treehole_spirit, nest.spirit_treehole_x,
                nest.spirit_treehole_y)

            for the_spirit in spirits:
                if pygame.sprite.spritecollideany(jack.game_jack,
                                                  the_spirit.spirit_group):
                    if not jack.wd:
                        if pygame.time.get_ticks() > frame_koxie:
                            frame_koxie = pygame.time.get_ticks()
                            xl_2 = xl
                            xl -= 1
                            if xl_2 > xl:
                                jack_ss = pygame.mixer.Sound(
                                    "music/jack_ss.wav")
                                jack_ss.set_volume(1)  #调节音量
                                jack_ss.play(0)
                            ai_xin.js_xl(
                                xl
                            )  #pygame.sprite.groupcollide(jack.jack_group,spirit.spirit_group,True,True) //碰撞消失
                            frame_koxie += 3000

                if pygame.sprite.groupcollide(attack.hyjq_group,
                                              the_spirit.spirit_group, True,
                                              True):
                    jifen.plus()
                if pygame.time.get_ticks() > frame_hyjq:
                    attack.hyjq_group.add(attack.game_hyjq)
                    frame_hyjq += 10000

                if pygame.sprite.groupcollide(attack.fq_group,
                                              the_spirit.spirit_group, False,
                                              True):
                    jifen.plus()
                if pygame.time.get_ticks() > frame_fq:
                    attack.fq_group.add(attack.game_fq)
                    frame_fq += 10000
            for gem in gems:
                f = True if xl <= 5 else False
                if pygame.sprite.groupcollide(jack.jack_group,
                                              gem.gem_group_xlbs1, False,
                                              f) and xl <= 5:
                    xl += 1
                elif pygame.sprite.groupcollide(jack.jack_group,
                                                gem.gem_group_xlbs2, False,
                                                f) and xl <= 5:
                    xl = xl + 1 if xl == 5 else xl + 2
        # gf.check_event()

        # gf.update_screen(screen,jack)

        elif xl == 0:
            if end == True:
                pygame.mixer.music.load("music/end_music.wav")
                pygame.mixer.music.play(-1, 0)
            end = False

            # pygame.mixer.music.stop()
            kai_shi.jieshu()
        elif jifen.jifen >= ai_setting.win:
            if win == True:
                pygame.mixer.music.load("music/win_music.wav")
                pygame.mixer.music.play(-1, 0)
            win = False

            kai_shi.shengli()

        pygame.display.flip()
Beispiel #6
0
    def get_gems(self):
        gems_bbox = self.get_gem_board_bbox()
        gems = gems_bbox.split_grid(6, 5)
        gems = [[Gem(gem) for gem in gem_line] for gem_line in gems]

        return gems
Beispiel #7
0
 def createBoard(self):
     self.board = [[Gem(self.__blank_id) for i in range(self.__width)]
                   for i in range(self.__height)]
Beispiel #8
0
    def analyze(self, driver, Game):
        #  coords = []

        self.gems = []
        examples = []

        el = driver.find_element_by_css_selector(
            '#iframe-game')  # you should use meaningful names

        driver.save_screenshot('temp.bmp')
        screen = cv2.imread("temp.bmp")
        top = el.location['y'] + 49
        left = el.location['x'] + 168
        width = 320
        height = 320

        board = screen[top:top + height, left:left + width]
        hsv = cv2.cvtColor(board, cv2.COLOR_BGR2HSV)
        lower = np.array([0, 0, 118])
        upper = np.array([179, 255, 255])
        mask = cv2.inRange(hsv, lower, upper)
        filtered_board = cv2.bitwise_and(board, board, mask=mask)

        self._clear_data()

        for i in range(8):
            level = []
            for j in range(8):
                level.append('__')
            self.gems.append(level)
        #   coords.append(level)
        # Adding file examples
        for level in Game.EXAMPLES:
            examples_level = []
            for filename in level:
                img = np.load(Game.EXAMPLES_PATH + filename)
                code = filename[:-4]
                examples_level.append(Gem(code, img))
            examples.append(examples_level)

        for i in range(8):
            for j in range(8):
                found = False
                gem = filtered_board[i * 40:(i + 1) * 40, j * 40:(j + 1) * 40]
                full_gem = board[i * 40:(i + 1) * 40, j * 40:(j + 1) * 40]
                #  coords[i][j] = ((j * 40) + 5 + 168, (i * 40) + 5 + 49)
                for k in range(len(examples)):
                    if found:
                        break
                        #  print(self.examples)
                        #  print()
                    level = examples[k]
                    # print(level)

                    for example in level:
                        res = example.compare(gem)
                        if res > Game.ERRORS[k]:
                            self.gems[i][j] = str(example)
                            #                            Game.save_example(str(example), full_gem)  ###########################

                            #                            self.mat_lst.append()
                            found = True
                            break

                if self.gems[i][j] == '__':
                    pass
                    #Game.save_example('errors', full_gem)

            print(' '.join(self.gems[i]))
            # print(self.coords)
            # print(self.gems)
        return self.gems
Beispiel #9
0
def get_gems():
    life_gem = Gem(1, 'Gem of Life', {'flat_hp': 10})
    mana_gem = Gem(1, 'Gem of Mana', {'flat_mana': 10})
    as_gem = Gem(1, 'Gem of Speed', {'increased_attack_speed': 5})