Exemple #1
0
 def __init__(self, username, mysocket, x, y, window, clock, globaltickcounter,animation,playerPokemonName,playerPokemonLvl,playerPokemonHp,playerPokemonExp,playerPokemonRest):
     self.x = x
     self.y = y
     self.window = window
     self.clock = clock
     self.moving = ""
     self.movepress = ""
     self.images = [pygame.image.load("sprites/hero-Up1.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Up2.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Up3.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Up4.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Down1.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Down2.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Down3.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Down4.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Left1.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Left2.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Left3.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Left4.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Right1.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Right2.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Right3.png").convert_alpha(),
                    pygame.image.load("sprites/hero-Right4.png").convert_alpha()]
     self.map = pygame.image.load("maps/pathing/pathing.png")
     self.CurrentGUI = 0
     self.pokemons = [pokelib.getPokemon(playerPokemonName,playerPokemonLvl,playerPokemonHp,playerPokemonExp)]
     if len(playerPokemonRest)>3:
         for num in xrange(0,len(playerPokemonRest),4):
             self.pokemons.append(pokelib.getPokemon(playerPokemonRest[num].strip(),int(playerPokemonRest[num+1].strip()),int(playerPokemonRest[num+2].strip()),int(playerPokemonRest[num+3].strip())))
     self.GUIs = gui.GenGUIs(self)
     self.WAITING = False
     self.Username = username
     self.HashCheck = str(hash(self.Username)) + ";"
     self.peers = {}
     self.mysocket = mysocket
     self.send(self.Username+",posi,"+str(self.x)+","+str(self.y)+",")
     self.GlobalTickCounter = globaltickcounter
     self.ChallengeOffer = ""
     self.SentChallenge = ""
     self.BattlingPlayer = ""
     self.WildBattle = False
     self.AnimationPlayer = animation
     self.inWildBattle = False
     self.EnemyTurn = False
     self.font = pygame.font.Font('gui/PKMNRSEU.FON', 5)
     self.playingBG = False
     self.MapList = mapload.GenMapList()
     self.mapname = ""
     self.ChatSendBox = gui.TextElement(580, 580, pygame.font.Font('gui/PKMNRSEU.FON', 20), "", (0,0,100),"l")
     self.ChatRecieveBoxes = []
     self.TrainerWildBattle = False
     self.ChallengeAccepted = False
     for a in xrange(0,20):
         self.ChatRecieveBoxes.append(gui.TextElement(580, 270, pygame.font.Font('gui/PKMNRSEU.FON', 20), "", (0,0,50),"l"))
         self.ChatRecieveBoxes[a].y += a * 15
     self.ChatRecieveText = [""] * 20
     thread.start_new_thread(acceptdata, (self,))
Exemple #2
0
 def wildbattle(self, enemyname, lvl, trainer = False, trainername = ""):
     if self.SentChallenge != "":
         self.send(self.Username+',sendchal,,'+self.pokemons[0].name+","+str(self.pokemons[0].lvl)+","+str(self.pokemons[0].hp)+",")
         self.addtochat("Your challenge has been cancelled.")
         self.SentChallenge = ""
         
     self.TrainerWildBattle = trainer
     pygame.mixer.music.stop()
     if self.TrainerWildBattle:
         self.addtochat("Foe %s sent out %s!" % (trainername,enemyname), True)
     else:
         self.addtochat("A wild %s has appeared!" % (enemyname,), True)
     
     MM.play_music(MM.battle_file)
     
     self.flashscreen()
     
     self.enemypokemon = pokelib.getPokemon(enemyname, lvl)
     for a in xrange(0,4):
         self.GUIs[1].text["a"+str(a+1)].text = self.pokemons[0].moves[a].name
     gui.UpdateLabels(self)
     self.GUIs[1].pics["ppb"].image = GIFImage("sprites/back/"+str(self.pokemons[0].number).zfill(3)+".gif")
     self.GUIs[1].pics["epb"].image = GIFImage("sprites/front/"+str(self.enemypokemon.number).zfill(3)+".gif")
     self.GUIs[1].buttons["a2"].visible = False
     self.GUIs[1].text["a2"].visible = False
     self.GUIs[1].buttons["a3"].visible = False
     self.GUIs[1].text["a3"].visible = False
     self.GUIs[1].buttons["a4"].visible = False
     self.GUIs[1].text["a4"].visible = False
     if self.pokemons[0].lvl >= 10:
         self.GUIs[1].buttons["a2"].visible = True
         self.GUIs[1].text["a2"].visible = True
     if self.pokemons[0].lvl >= 20:
         self.GUIs[1].buttons["a3"].visible = True
         self.GUIs[1].text["a3"].visible = True
     if self.pokemons[0].lvl >= 30:
         self.GUIs[1].buttons["a4"].visible = True
         self.GUIs[1].text["a4"].visible = True
     self.CurrentGUI = 1
     self.WildBattle = True
Exemple #3
0
def acceptdata(lp):
    recData = ""
    while 1:
        try:
            try:
                recData += lp.mysocket.recv(4096)
            except Exception as ex:
                print ex
                lp.RUN = False
            lstData = recData.split(";")
            recData = ""
            for a in lstData:
                b = a.split(",")
                b.append("")
                if len(b)>1 and (b[0] != "") and (b[0] != lp.Username) and (str(hash(b[0])) == b[len(b)-2]):
                    if not b[0] in lp.peers and b[1] != "dced":
                        lp.peers[b[0]] = Peer(b[0],10005.0,10006.0)
                        lp.send(lp.Username+",posi,"+str(lp.x)+","+str(lp.y)+",")
                        lp.addtochat(b[0] + " has connected.")
                    if b[1] == "posi":
                        lp.peers[b[0]].x = float(b[2])
                        lp.peers[b[0]].y = float(b[3])
                        lp.peers[b[0]].moving = b[4]
                    elif b[1] == "dced":
                        lp.peers.pop(b[0])
                        if lp.ChallengeOffer == b[0]:
                            lp.GUIs[0].buttons["accchal"].visible = False
                            lp.GUIs[0].text["accchal"].visible = False
                            lp.ChallengeOffer = ""
                        elif lp.BattlingPlayer == b[0]:
                            gui.WinBattle(lp)
                            lp.addtochat("The trainer you were battling has defaulted!")
                        lp.addtochat(b[0] + " has disconnected.")
                    elif b[1] == "sendchal":
                        if b[2] == lp.Username:
                            lp.ChallengeOffer = b[0]
                            lp.ChallengePokemon = pokelib.getPokemon(b[3],int(b[4]),int(b[5]))
                            lp.GUIs[0].buttons["accchal"].visible = True
                            lp.GUIs[0].text["accchal"].visible = True
                            lp.addtochat(b[0] + " has challenged you.")
                        elif lp.ChallengeOffer == b[0] and b[2] != lp.Username:
                            lp.GUIs[0].buttons["accchal"].visible = False
                            lp.GUIs[0].text["accchal"].visible = False
                            lp.ChallengeOffer = ""
                            lp.addtochat(b[0] + " has challenged somebody else.")
                    elif b[1] == "accchal":
                        if b[2] == lp.Username and b[0] == lp.SentChallenge:
                            lp.ChallengePokemon = pokelib.getPokemon(b[3],int(b[4]),int(b[5]))
                            lp.BattlingPlayer = lp.SentChallenge
                            lp.SentChallenge = ""
                            lp.WAITING = True
                            lp.EnemyTurn = True
                            lp.ChallengeAccepted = True
                    elif b[1] == "atk":
                        if b[2] == lp.Username and b[0] == lp.BattlingPlayer and lp.WAITING:
                            if lp.EnemyTurn:
                                lp.EnemyTurn = False
                                if lp.enemypokemon.hp <= 0:
                                    gui.WinBattle(lp)
                                    continue
                                lp.enemypokemon.attack(lp.pokemons[0], lp.enemypokemon.moves[int(b[3])])

                                lp.AnimationPlayer.startAnimation()
                                lp.AnimationPlayer.setAnimation(lp.enemypokemon.moves[int(b[3])].name, "enemyatk")
                                lp.AnimationPlayer.doAnimation()

                                lp.addtochat("Enemy used " + lp.enemypokemon.moves[int(b[3])].name)
                                lp.GUIs[1].pics["apb"].visible = True
                                gui.UpdateLabels(lp)
                    elif b[1] == "chat":
                        lp.addtochat(b[0]+": "+b[2].replace("{",";").replace("}",","))
                elif (b[0] != "") and (b[0] == lp.Username) and (str(hash(lp.Username)) == b[len(b)-2]):
                    if b[1] == "save":
                        lp.save()
                    elif b[1] == "list":
                        playernamelist = b[2:(len(b)-2)]
                        for peername in lp.peers.keys():
                            if not peername in playernamelist:
                                lp.peers.pop(peername)
                else:
                    if a != "": pass
                    elif a == b[-1]: recData = a
                    else: print "Network Error - Dropped Message:", a
        except Exception as ex:
            print ex
            print recData