Example #1
0
 def die(self, base=False):
     '''If enemy runs out of health add them to explosions list, remove from enemy list, and add money to player's account'''
     if self.isAlive:
         if self.isair == True:
             Localdefs.flyinglist.remove(self)
         if self.anim:
             self.anim.cancel_all(self)
         if self.pushAnimation:
             self.pushAnimation.cancel_all(self)
         if self.backToRoad:
             self.backToRoad.cancel_all(self)
         self.clear_widgets()
         Map.mapvar.enemycontainer.remove_widget(self)
         if not base:
             if self.type == 'Splinter' and self.isAlive:
                 self.splinter()
             if self.isBoss:
                 x = random.randint(0, 100)
                 if x < 3:
                     self.gemImage = True
             self.startDeathAnim()
             Player.player.money += int(self.reward)
             Player.player.analytics.moneyEarned += self.reward
             Player.player.score += self.points
             Player.player.myDispatcher.Money = str(Player.player.money)
             Player.player.myDispatcher.Score = str(Player.player.score)
             MainFunctions.updateGUI()
         self.isAlive = False
def create_trajectory_and_inputs(show_=False):
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    app.exec()

    window.getMatrix()
    frame_img = window.img

    window.default_save()
    # Green
    Sresult = ConvertingFunctions.reduce_matrix(frame_img[:, :, 0], 10)

    plt.imshow(frame_img[:, :, 0])
    plt.title("Trajectory in the pyramidal cells")
    plt.xlabel("meters")
    plt.ylabel("meters")
    plt.show()

    if show_:
        plt.imshow(Sresult)
        plt.title("S legend")

    np.save('S_inputs.npy', Sresult)

    result_S = MainFunctions.create_trajectory_matrix('S_inputs.npy')

    if np.count_nonzero(frame_img[:, :, 1] != 255) == 0:
        raise Warning("With this method, must add external inputs!")
    else:
        # Red
        Gresult = ConvertingFunctions.reduce_matrix(frame_img[:, :, 1], 10)
        np.save('G_inputs.npy', Gresult)
        result_G = MainFunctions.create_trajectory_matrix('G_inputs.npy')

        plt.imshow(frame_img[:, :, 1])
        plt.title("Special input in the pyramidal cells")
        plt.xlabel("meters")
        plt.ylabel("meters")
        plt.show()

        if show_:
            plt.imshow(Gresult)
            plt.title("G legend")

        result_S = result_S + result_G

        return result_S, result_G
Example #3
0
 def checkHit(self, *args):
     if Map.mapvar.baseimg.collide_widget(self) and self.isAlive:
         self.die(base=True)
         Player.player.sound.playSound(Player.player.sound.hitBase,
                                       start=.5)
         if self.isBoss:
             if self.specialSend:
                 Player.player.health -= 2
             else:
                 Player.player.health -= 5
         else:
             Player.player.health -= 1
         Player.player.myDispatcher.Health = str(Player.player.health)
         MainFunctions.flashScreen('red', 2)
         if Player.player.health <= 0:
             Player.player.die()
         return
Example #4
0
def placeTower(event, selected):
    if not selected.tower.outyet and (not any([
            ttower.rect.collidepoint(event.dict['pos'])
            for ttower in localdefs.towerlist if ttower.outyet
    ]) and not any([
            p.inflate(25, 25).collidepoint(event.dict['pos'])
            for pathrectlist in localdefs.mapvar.pathrectlists
            for p in pathrectlist
    ])):
        selected.tower.place(MainFunctions.roundPoint(event.dict['pos']))
        return None, True, 0
    return selected, False, 0
Example #5
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.setFixedSize(900,600)
        self.loginBtn.clicked.connect(self.loginBtn_clicked)
        self.dbBtn.clicked.connect(self.dbBtn_clicked)
        self.excelBtn.clicked.connect(self.excelBtn_clicked)
        self.getAllCodeBtn.clicked.connect(self.getAllCodeBtn_Clicked)
        self.getCodeBtn.clicked.connect(self.getCodeBtn_Clicked)
        self.getCodeDBBtn.clicked.connect(self.getCodeDBBtn_Clicked)
        self.getAllCodeDBBtn.clicked.connect(self.getAllCodeDBBtn_Clicked)
        self.codeListBtn.clicked.connect(self.codeListBtn_Clicked)

        self.mainFucntions = mf.MainFunctions()
Example #6
0
def are_you_sure(listbox):
    popup = Toplevel()
    popup.title('AYS?')
    popup.geometry("200x80+1050+350")
    popup.resizable(False, False)
    label1 = Label(popup, text="Are you sure you want to reset?")
    cancel_button = Button(popup,
                           text="Cancel",
                           command=lambda: popup.destroy(),
                           width=5)
    reset_ok = Button(
        popup,
        text="Reset",
        command=lambda: [MF.reset(listbox), popup.destroy()],
        width=5)
    label1.grid(row=0, column=0, columnspan=5, padx=(12, 0), pady=(7, 5))
    cancel_button.grid(row=2, column=1, padx=(12, 6), pady=(5, 5))
    reset_ok.grid(row=2, column=3, padx=(12, 0), pady=(5, 5))
    popup.grab_set()
    popup.mainloop()
Example #7
0
def placeTowerFromList(*args):
    list = Map.mapvar.background.dragger.towerposlist
    instance = args[0]
    createdTowers = []
    for tower in list:
        createdTowers.append(placeTower(instance, tower))

    x = 0
    while MainFunctions.updatePath() == False:
        if x == 0:
            checkBlockedPath(createdTowers)
            x += 1
        else:
            for tower in createdTowers:
                tower.remove()
                Messenger.messenger.createMessage("Path Blocked")
                Player.player.money += tower.cost
                Player.player.analytics.moneySpent -= tower.cost
                Player.player.myDispatcher.Money = str(Player.player.money)
    if createdTowers:
        resetEnemyPaths()
        towerset = set()
        towergroupset = set()
        towerset.add(createdTowers[0])
        TowerNeighbors.initNeighbors(createdTowers[0], towerset, towergroupset)
        tower = next(iter(towerset))
        if len(towergroupset) == 0:
            tower.towerGroup = TowerGroup.TowerGroup(tower)
            tg = tower.towerGroup
        else:
            tg = next(iter(towergroupset))
            tower.towerGroup = tg
        tg.needsUpdate = True
        for tower in towerset:
            TowerNeighbors.getImage(tower)
            tower.towerGroup = tg
            if tower.leader:
                tg.leader = tower
        for menu in towerset:
            menu.setTowerData()
def placeTower(event,selected):
    if not selected.tower.outyet and (not any([ttower.rect.collidepoint(event.dict['pos']) for ttower in localdefs.towerlist if ttower.outyet])
        and not any([p.inflate(25,25).collidepoint(event.dict['pos']) for pathrectlist in localdefs.mapvar.pathrectlists for p in pathrectlist])):
        selected.tower.place(MainFunctions.roundPoint(event.dict['pos']))
        return None,True,0
    return selected,False,0
def main():
    pygame.init()
    print "Pygame Initialized"
    pygame.display.set_caption("PyGame Tower Defence Game")
    pygame.mouse.set_visible(1)
    #localdefs: mapvar = Map()
    background = mapvar.loadMap((scrwid,scrhei),pickMap())
    print "Map Object Generated"
    screen = pygame.display.set_mode((scrwid,scrhei))
    print "Display Initialized"
    clock = pygame.time.Clock()
    genEnemyImageArray() #localdefs
    print "Enemy Image Array Generated"
    run=True #Run loop
    wavenum = 0
    selected = None #Nothing is selected

    MainFunctions.makeIcons()
    
    #Openbutton is the white surface on which the Icon sits
    openbutton = pygame.Surface((iconlist[len(iconlist)-1].rect.right+5,25))
    openbuttonrect = pygame.Rect((0,scrhei-25),(iconlist[len(iconlist)-1].rect.right+5,25))
    openbutton.fill((255,255,255))
    print "Begin Play Loop!!!"
    speed = 3
    frametime = speed/30.0
    while run:
        starttime = time.time()

        MainFunctions.tickAndClear(screen, clock, background)

        MainFunctions.workSenders(frametime)

        MainFunctions.workTowers(screen,frametime)

        MainFunctions.dispExplosions(screen)

        MainFunctions.dispText(screen,wavenum)

        MainFunctions.workEnemies(screen,frametime)

        for event in pygame.event.get():
            if event.type == MOUSEBUTTONUP:
                #If the user left-clicks...
                if event.dict['button']==1:
                    if nexttextpos.collidepoint(event.dict['pos']):
                        wavenum+=1
                        player.health += d(8) + 2
                        for tower in towerlist:
                            if tower.hp < tower.maxhp:
                                tower.hp = min(tower.hp+tower.level,tower.maxhp)
                        if ('wave'+str(wavenum)+'a') in mapvar.mapdict:
                            Sender(wavenum,'a')
                        if ('wave'+str(wavenum)+'b') in mapvar.mapdict:
                            Sender(wavenum,'b')
                        if ('wave'+str(wavenum)+'c') in mapvar.mapdict:
                            Sender(wavenum,'c')
                        if ('wave'+str(wavenum)+'d') in mapvar.mapdict:
                            Sender(wavenum,'d')
                        if all([('wave'+str(wavenum)+letter) not in mapvar.mapdict for letter in ['a','b','c','d']]):
                            if len(enemylist) == 0:
                                background=mapvar.loadMap((scrwid,scrhei),pickMap())
                                screen = pygame.display.set_mode((scrwid,scrhei))
                                wavenum=1
                            else:
                                print "There are still enemies on the screen!"
                                wavenum-=1
                    elif selected:
                        if selected.__class__ == Icon:
                            if event.dict['pos'][1]<scrhei-squsize:
                                if player.money>=eval(selected.type+"Tower").basecost:
                                    if (not any([ttower.rect.collidepoint(event.dict['pos']) for ttower in towerlist])
                                        and not any([p.inflate(25,25).collidepoint(event.dict['pos']) for pathrectlist in mapvar.pathrectlists for p in pathrectlist])):
                                        eval(selected.type+selected.base)(event.dict['pos'])
                                        selected = None
                            else:
                                selected = None
                        elif Tower in selected.__class__.__bases__:
                            EventFunctions.leftSelectedTower(event, selected)
                    else:
                        for object in (towerlist+iconlist):
                            if object.rect.collidepoint(event.dict['pos']):
                                selected = object
                else:
                    selected = None
            keyinput = pygame.key.get_pressed()
            if event.type == QUIT:
                sys.exit()
            if keyinput[K_ESCAPE]:
                sys.exit()
            if keyinput[K_f]:
                screen = pygame.display.set_mode((scrwid,scrhei),FULLSCREEN)
            if keyinput[K_w]:
                screen = pygame.display.set_mode((scrwid,scrhei))

        font = pygame.font.Font(None,20)

        MainFunctions.dispStructures(screen)

        nexttextpos = MainFunctions.dispNextWave(screen)

        if selected and selected.__class__ == Icon:
            MainFunctions.selectedIcon(screen, selected)

        if selected and Tower in selected.__class__.__bases__:
            MainFunctions.selectedTower(screen, selected)

        screen.blit(openbutton,openbuttonrect)
        for icon in iconlist:
            screen.blit(icon.img,icon.rect)
            if icon.rect.collidepoint(pygame.mouse.get_pos()):
                text = font.render("%s Tower (%d)" % (icon.type,eval(icon.type+"Tower").basecost),1,(0,0,0))
                textpos = text.get_rect(left=icon.rect.left,bottom=icon.rect.top-2)
                screen.blit(text,textpos)

        screen.blit(mapvar.baseimg,mapvar.baserect)

        pygame.display.flip()

        frametime = (time.time() - starttime) * speed
    f.write((u'------------------------------------------------------' + u'\n').encode('utf-8') )
    # получаем запрос в нужной кодировке unicode
    s = query.decode('cp1251')

    # разбиваем запрос на токены
    tokens_in_query = tokenization.simple_word_tokenize(s)

    # счетчик
    count = 0

    # для каждого токена получаем набор характеристик
    for token in tokens_in_query:
        # увеличивем счетчик
        count = count + 1
        # получаем корректный набор характеристик для токена
        list = MainFunctions.get_all_characteristics(token)

        # выводим данные на консоль
        for line in list:
            # Записываем стороки разбора в нужном формате и кодировке в файл
            f.write((line + u'\n').encode('utf-8') )

        print count , len(tokens_in_query)

        if count != len(tokens_in_query):
            f.write((u'--------------------------------' + u'\n').encode('utf-8') )

# Закрываем файлы
f_read.close()
f.close()
Example #11
0

def remove_frames():
    for frame in frame_list:
        frame.grid_remove()


cost_group = StringVar(root)
cost_group.set(GF.cost_options[0])
cost_menu = ttk.Combobox(fr4, values=GF.cost_options)
cost_menu.set(cost_group.get())
cost_menu.grid(row=0, column=0, pady=(30, 10), padx=(40, 30))

text_area = Listbox(fr2, width=28, height=34, state='normal')
text_area.grid(row=0, column=0, rowspan=20)
MF.refresh(text_area)

x = 0
for champ in DCF.champion_list:

    GF.images.append(
        ImageTk.PhotoImage(
            Image.open(champ.image).resize((59, 59)), Image.ANTIALIAS))

    b = Button(fr,
               image=GF.images[-1],
               command=lambda x=champ: MF.increment(x, text_area),
               highlightthickness=0,
               bd=0)
    b.grid(row=math.floor(x / 5), column=x % 5)
    x += 1
Example #12
0
def change_context(button, listbox):
    DCL.is_champ = not DCL.is_champ
    button.config(text='Traits' if DCL.is_champ else "Champions")
    MF.refresh(listbox)
Example #13
0
def main():
    pygame.init()
    print "Pygame Initialized"
    pygame.display.set_caption("PyGame Tower Defence Game")
    pygame.mouse.set_visible(1)
    #localdefs: mapvar = Map()
    
    print "Map Object Generated"
    screen = pygame.display.set_mode((scrwid,scrhei))
    print "Display Initialized"
    clock = pygame.time.Clock()

    player.start()
    player.addScreen(screen,clock)

    background = mapvar.loadMap((scrwid,scrhei),MainMenu.main(screen,clock))

    genEnemyImageArray()
    run=True #Run loop
    wavenum = 0
    selected = None #Nothing is selected

    MainFunctions.makeIcons()
    
    print "Begin Play Loop!!!"

    font = pygame.font.Font(None,20)
    speed = 3
    frametime = speed/30.0
    while run:
#        timehold = list()
        starttime = time.time()
#        temptime = time.time()

        MainFunctions.tickAndClear(screen, clock, background, frametime)
#        timehold.append(("tAC",time.time()-temptime))
#        temptime = time.time()

        MainFunctions.workSenders(frametime)
#        timehold.append(("wSe",time.time()-temptime))
#        temptime = time.time()

        MainFunctions.workTowers(screen,frametime)
#        timehold.append(("wTo",time.time()-temptime))
#        temptime = time.time()

        MainFunctions.dispExplosions(screen,frametime)
#        timehold.append(("dEx",time.time()-temptime))
#        temptime = time.time()

        MainFunctions.dispText(screen,wavenum)
#        timehold.append(("dTe",time.time()-temptime))
#        temptime = time.time()

        MainFunctions.workEnemies(screen,frametime)
#        timehold.append(("wEn",time.time()-temptime))
#        temptime = time.time()

        screen,selected,wavenum,speed,timedel = MainFunctions.workEvents(screen, frametime, selected, wavenum, Sender, speed,pygame.font.Font(None,30),pygame.font.Font(None,25))
#        timehold.append(("wEv",time.time()-temptime))
#        temptime = time.time()

        starttime += timedel

        MainFunctions.dispStructures(screen,pygame.mouse.get_pos())
#        timehold.append(("dSt",time.time()-temptime))
#        temptime = time.time()

        screen.blit(mapvar.baseimg,mapvar.baserect)

        if selected and selected.__class__ == Icon:
            MainFunctions.selectedIcon(screen, selected)
#            timehold.append(("sIc",time.time()-temptime))
#            temptime = time.time()

        if selected and Tower is selected.__class__:
            MainFunctions.selectedTower(screen,selected,pygame.mouse.get_pos())
#            timehold.append(("sTo",time.time()-temptime))
#            temptime = time.time()

        screen.blit(openbuttoninfo[0],openbuttoninfo[1])

        MainFunctions.dispIcons(screen, pygame.mouse.get_pos(), font, frametime)
#        timehold.append(("dIc",time.time()-temptime))

        pygame.display.flip()

        frametime = (time.time() - starttime) * speed
Example #14
0
            for player in player_list:
                print(player[0])
                time.sleep(0.5)

            total_sessions = int(60 / len(player_list))
            print("Number of sessions in the game:", total_sessions)
            session_nr = 1
            # ----------------------------------Deck initialize------------------------
            while session_nr <= total_sessions:
                deck = DC.DeckClass()
                deck.Shuffle()
                # last session does not look for dominant, all deck is distributed.
                if session_nr < total_sessions:
                    deck.dominant_colour = deck.FindDominant()
                deck.EvaluateDeck()
                MF.session_initialize_print(session_nr, total_sessions,
                                            deck.dominant_card)
                # ----------------------------------Hands-------------------------------
                for player in player_list:
                    if player[0] == human_player:
                        player[4] = PH.Hand(player[0])
                    else:
                        player[4] = CH.ComputerHand(player[0])
                for player in player_list:
                    card_nr = 1
                    while card_nr <= session_nr:
                        player[4].add_card(deck.deck.pop(), card_nr)
                        card_nr += 1
# ------------------------------------------Bidding----------------------------
                bid_list = {}
                for player in player_list:
                    bid_list = player[4].place_bid(bid_list, session_nr,