Exemplo n.º 1
0
    def chooseDeck(self,name=None,n_p=0) :
        #from deck_creation import utilisation_list

        all_decks = [file2name(fname,'.dek') for fname in glob.glob("Decks/*.dek")]
        #print "possible decks are :",all_decks
        deck = []
        if not(name in all_decks):
            print ("all decks", all_decks)
            while not deck:
                print (name," is not accessible")
                name = raw_input("choose a deck in list :")
                if name in all_decks :
                    break
        
        if name!=None and name in all_decks:
            all_cards={}
            for f in glob.glob("CardFiles/all*.sav") :
                #print "load cards in ",f
                d = readMonsters(f)
                all_cards.update(d)
            name=name2file("Decks",name,".dek")
            deck_names=eval(open(name).read())
            #print deck_names
            for d,c in deck_names.items():
                if d != "AvatarImage":
                    try :
                        k=all_cards[d]
                    except Exception as inst :
                        print( "error with card ",d)
                        print( "in",all_cards.keys())
                        print( "error=",inst)
                        raise "fatal error"
                    for v in range(c):
                        deck.append(k)
                    #print d
                else:
                    if n_p == 1:
                        self.player1_avatar = pygame.image.load(localpath(c))
                    elif n_p == 2:
                        self.player2_avatar = pygame.image.load(localpath(c))
        else :
            deck=None

        from CardPowers import Camouflage, Provocation,DonneArmureAuHero
        for d in reversed(deck):
            if (any([b.__class__==Camouflage for b in d.bonus]) or any([b.__class__==Camouflage for b in d.bonus])) and (any([(b.__class__==Provocation) for b in d.bonus]) or any([(b.__class__==DonneArmureAuHero) for b in d.bonus])):
                for i in range(60):
                    print( "Cheater !!!!!!")
                deck = []
                from Card import mouton
                for i in range(30):
                    deck.append(mouton)
                break

        return deck
    def __init__(self,x_center,y_center,image,fonction,game,argus,deck_name):
        Button.__init__(self,x_center,y_center,image,fonction,game,argus)
        #print " deck name is",deck_name
        size = (1500,2000)
        font_size = 36
        if deck_name != "NET BATTLE" :
          with open(name2file("Decks",deck_name,".dek"),"r") as fil:
            deck = eval(fil.read())
            del deck["AvatarImage"]
            print (deck_name)
            for k in deck.keys() :
                try :
                    all_cards[k].getCost()
                except Exception as e:
                    print ("error getCost with",k," in deck ",deck_name)
                    print(sorted(all_cards.keys()))
                    raise e
            try :
                stars = sum([all_cards[k[0]].getStars()*k[1] for k in deck.items()] )
            except :
                print (" in ",all_cards.keys(), " looking for ",deck.keys())
                raise
            pastrop=0
            pouvoirslimites=["CoutReduit[(]","GainMana","CoutDesSortsReduit","CoutDesMonstresReduit"]
            for p in pouvoirslimites :
                rp=re.compile(p)
                pastrop=max(pastrop,sum([len(rp.findall(all_cards[k[0]].constructor()))*k[1] for k in deck.items()] ))
                if pastrop>=6 :
                    print(deck_name," interdit de campagne par trop de ",p)
                    break
            if (stars>15 or pastrop>=6) and len(argus)!=2:
                self.accessible = False
                color = RED
                def updat(self):
                    pass
                self.update = MethodType(updat,self)
            elif stars>15  or pastrop>=6 :
                self.accessible = True
                color = RED
            else:
                self.accessible = True
                color = GREEN
        else :
            color=BLUE
            self.accessible=True
            stars=0

        while size[0]>self.size[0]-30:
            self.image = copy(image)
            font = pygame.font.SysFont("Heraldic",font_size,italic=True,bold=True)
            text = font.render(deck_name+"- "+(str(stars)+"*")*(stars!=0),False,color)
            size = font.size(deck_name+"- "+(str(stars)+"*")*(stars!=0))
            self.image.blit(text,(self.size[0]/2-size[0]/2,self.size[1]/2-size[1]/2))
            font_size-=1
Exemplo n.º 3
0
 def sendDeck(self) :
     print "send Deck"
     self.game.soc.send(self.name+"\n"+"["+",".join([c.constructor() for c in self.deck])+"]")
     while 1 :
         demand=self.game.soc.recv(1024)
         if demand=="Thanks" :
             print "deck sent with success"
             break
         print "net is asking for ",demand
         from outils import name2file
         cheminImage = name2file("Cards",demand,".png")
         fichierImage = open(cheminImage, "rb")
         #On convertit la taille en string
         import os
         tailleImage = str(os.path.getsize(cheminImage))
         #On rajoute des 0 devant la taille pour avoir 8 char
         tailleImage = "0"*(8-len(tailleImage)) + tailleImage               
         #On a la taille de l'image, on l'envoie au client
         self.game.soc.send(tailleImage.encode())
         #On envoit le contenu du fichier
         self.game.soc.send(fichierImage.read()) 
Exemplo n.º 4
0
    def __init__(self,x_center,y_center,image,fonction,game,argus,deck_name):
        Button.__init__(self,x_center,y_center,image,fonction,game,argus)
        #print " deck name is",deck_name
        size = (1500,2000)
        font_size = 36
        if deck_name != "NET BATTLE" :
          with open(name2file("Decks",deck_name,".dek"),"r") as fil:
            deck = eval(fil.read())
            del deck["AvatarImage"]
            [all_cards[k[0]].getCost() for k in deck.items()] # a cause de RaleDAgonie qui a besoin d un appel a getcost avant
            try :
                stars = sum([all_cards[k[0]].getStars()*k[1] for k in deck.items()] )
            except :
                print " in ",all_cards.keys(), " looking for ",deck.keys()
                raise
            if stars>15 and len(argus)!=2:
                self.accessible = False
                color = RED
                def updat(self):
                    pass
                self.update = MethodType(updat,self)
            elif stars>15:
                self.accessible = True
                color = RED
            else:
                self.accessible = True
                color = GREEN
        else :
            color=BLUE
            self.accessible=True
            stars=0

        while size[0]>self.size[0]-30:
            self.image = copy(image)
            font = pygame.font.SysFont("Heraldic",font_size,italic=True,bold=True)
            text = font.render(deck_name+"- "+(str(stars)+"*")*(stars!=0),False,color)
            size = font.size(deck_name+"- "+(str(stars)+"*")*(stars!=0))
            self.image.blit(text,(self.size[0]/2-size[0]/2,self.size[1]/2-size[1]/2))
            font_size-=1
Exemplo n.º 5
0
#playable_decks.remove("default")
playable_decks.remove("Fried Frenchs")
all_decks = copy(playable_decks)
for d in reversed(playable_decks):
    if d in blocked_decks:
        playable_decks.remove(d)
print "all_decks: ",all_decks

scores = {}
for d in all_decks:
    scores[d] = 0
    


for deck in all_decks:
    with open(name2file("Decks",deck,".dek","rb") as f:
        print "\n*** ",deck
        dec = pickle.load(f)
        print dec
        deck_cards = []
        for m in dec:
            if m != "AvatarImage":
                for i in range(dec[m]):
                    if m in cards:
                        deck_cards.append(cards[m])
        print "Cost average, ",sum(int(unit.getCost()) for unit in deck_cards)/float(len(deck_cards))
        deck_powers = []
        for unit in deck_cards:
            for power in unit.bonus:
                deck_powers.append(power.__class__)
        #print "Powers of deck ",deck_powers
Exemplo n.º 6
0
for e,p in enumerate(nums):
    print e,": ",ordered[p],", statistic = ",(100.*p)/len(cards),"(",p,")"

playable_decks = [file2name(d,".dek") for d in glob.glob("Decks/*.dek")]
#playable_decks.remove("default")
all_decks = copy(playable_decks)

scores = {}
for d in all_decks:
    scores[d] = 0
    


for deck in all_decks:
    with open(name2file("Decks",deck,".dek"),"r") as f:
        print "\n*** ",deck
        dec = eval(f.read())
        print dec
        deck_cards = []
        for m in dec:
            if m != "AvatarImage":
                for i in range(dec[m]):
                    if m in cards:
                        deck_cards.append(cards[m])
        print "Cost average, ",sum(int(unit.getCost()) for unit in deck_cards)/float(len(deck_cards))
        deck_powers = []
        for unit in deck_cards:
            for power in unit.bonus:
                deck_powers.append(power.__class__)
        #print "Powers of deck ",deck_powers
Exemplo n.º 7
0
 def receiveDeck(self) :
     print "try to receive deck"
     import time
     time.sleep(0.5) # pour que le send en face soit fini
     mess=self.game.soc.recv(1024*16)
     try :
         name,cards=mess.split("\n")
         self.name=name
     except :
         print "got message ",mess
         print "should have name\ndeck"
         raise
     from Card import evalCard,all_monsters
     try :
         self.deck=evalCard(cards) # le jeu est deja melange
     except :
       print "error with",cards
       for c in cards.strip().strip("[]").split("Card(").strip(",") :
         try :
             evalCard("Card("+c) # all_monsters contient des instances
         except :
             print "problem with ",c
     print "opponent name ",name
     #print "deck",deck
     asking=set()
     for c in self.deck :
         c.costint=int(floor(c.getCost()))
         c.starcost=c.getStars()
         print "c.constructor()",c.constructor()
         for name in c.constructor().split('Card("')[1:] :
             #print "nam brut",name
             name=name.split('"')[0]
             #print "name modif",name
             if name not in all_monsters or c.getInlineDescription()!=all_monsters[c.name].getInlineDescription() :
                 asking.add(name)
     for name in asking :
         self.game.soc.send(name)
         print "asking for image ",name
         tailleImage = self.game.soc.recv(8)
         #On convertit la taille de l'image en entier (en octets)
         tailleImage = int(tailleImage.decode())
         #Contenu loaded
         contenuTelecharge = 0
         #Le fichier qui va contenir l'image
         from outils import name2file
         filename=name2file("",name,".png")
         fichierImage = open(filename,"wb")               
         #On continue la lecture up to th end
         while contenuTelecharge < tailleImage:
             #On lit les 1024 octets suivant
             contenuRecu = self.game.soc.recv(1024)
             #On enregistre dans le fichier
             fichierImage.write(contenuRecu)
             contenuTelecharge += len(contenuRecu)
         fichierImage.close()
         c.image = pygame.image.load(filename)
         print "ok for one"
     for c in self.deck :  # si l image est nouvelle on l affecte a la carte 
         if c.name in asking :
             filename=name2file("",c.name,".png")
             c.image=pygame.image.load(filename)
     print "net player cards are received"
     self.game.soc.send('Thanks')  # echo
Exemplo n.º 8
0
    def chooseDeck(self, name=None, n_p=0):
        #from deck_creation import utilisation_list

        all_decks = [
            file2name(fname, '.dek') for fname in glob.glob("Decks/*.dek")
        ]
        #print "possible decks are :",all_decks
        deck = []

        if not (name in all_decks):
            while not deck:
                print name, " is not accessible"
                name = raw_input("choose a deck in list :")
                if name in all_decks:
                    break

        if name != None and name in all_decks:
            all_cards = {}
            for f in glob.glob("CardFiles/all*.sav"):
                #print "load cards in ",f
                d = readMonsters(f)
                all_cards.update(d)
            name = name2file("Decks", name, ".dek")
            deck_names = eval(open(name).read())
            #print deck_names
            for d, c in deck_names.items():
                if d != "AvatarImage":
                    try:
                        k = all_cards[d]
                    except Exception as inst:
                        print "error with card ", d
                        print "in", all_cards.keys()
                        print "error=", inst
                        raise "fatal error"
                    for v in range(c):
                        deck.append(k)
                    #print d
                else:
                    if n_p == 1:
                        self.player1_avatar = pygame.image.load(localpath(c))
                    elif n_p == 2:
                        self.player2_avatar = pygame.image.load(localpath(c))
        else:
            deck = None

        from cardPowers import Camouflage, Provocation
        for d in reversed(deck):
            if (any([b.__class__ == Camouflage for b in d.bonus])
                    or any([b.__class__ == Camouflage
                            for b in d.bonus])) and (any([
                                (b.__class__ == Provocation) for b in d.bonus
                            ]) or any([(b.__class__ == DonneArmureAuHero)
                                       for b in d.bonus])):
                for i in range(60):
                    print "Cheater !!!!!!"
                deck = []
                from Card import mouton
                for i in range(30):
                    deck.append(mouton)
                break

        return deck