Exemplo n.º 1
0
    def keyPressEvent(self, event):
        """
        Метод обработки ввода с клав.
        :param event: Параметр сигнала с квал.
        :return: None
        """
        if event.key() == Qt.Key_Left:
            self.player.move('left')
            self.player.anim_left = True
        elif event.key() == Qt.Key_Right:
            self.player.move('right')
            self.player.anim_right = True
        elif event.key() == Qt.Key_Up:
            self.player.move('up')
            self.player.anim_up = True
        elif event.key() == Qt.Key_Down:
            self.player.move('down')
            self.player.anim_down = True

        elif event.key() == Qt.Key_Shift:
            self.player.roll_bomb()
        elif event.key() == Qt.Key_Space:
            self.player.drop_bomb()

        elif event.key() == Qt.Key_S:
            map.save_map()

        elif event.key() == Qt.Key_L:
            map.load_map()
        elif event.key() == Qt.Key_I:
            get_info_game(self)
        elif event.key() == Qt.Key_N:
            map.scroll_map()

        self.update()
Exemplo n.º 2
0
 def save_game(self, nom):
     # Map
     self.out("Saving "+nom+"...")
     for i in self.maps:
        map.save_map("save_srv/"+nom+"/map"+str(i.id), i.map) 
     # Perso
     for i in self.clients:
         self.clients_saved.append(i)
         
     file = open("data/save_srv/"+nom+"/char", "w")
     buffer  = ""
     for i in self.clients_saved:
         buffer += i.nom+";"+i.inv.save()+"\n"
     file.write(buffer)
     file.close()
Exemplo n.º 3
0
    def submit(self, action):
        if action == "save.png":
            self.next = SaveMap(self.screen, self.mapdata)
        elif action == "load.png":
            self.next = LoadMap(self.screen)
        elif action == "test.png":
            #save map to tmp
            self.next_was = "game"
            self.mapcopy = self.mapdata.copy()
            save_map(self.mapdata, "TMP", MAP_folder)
            self.next = EditorGame(self.mapdata)
        else:
            return

        self.pause()
        self.quit()
Exemplo n.º 4
0
    def submit_entry(self):
        #save map

        filename = self.entry.text + ".map"
        if save_map(self.mapdata, filename, MAP_folder):
            self.show_msg("Map saved.")
        else:
            self.show_msg("ERROR: Saving map failed.")

        self.quit()
Exemplo n.º 5
0
def main():
    doctest.testmod()
    moved_list = ['north', 'east', 'south', 'west']
    # load or create a character and map
    character.get_user()
    map.get_user_map()

    # prints initial map, character, and message
    print(
        'You are in an abandoned village in your search for a hidden treasure.'
    )
    print('Type north, east, south, or west to move')
    print('Type help to see a list of other keywords you can use')
    map.display_map()
    character.print_character()
    player_input = user_input()

    # game loop continues until user inputs quit
    while player_input != 'quit':
        print_message(player_input)
        map.display_map()

        # If player moves checks for monster encounter
        if player_input in moved_list:
            # Checks for a monster encounter
            if not monster.check_monster_encounter():
                # If not encounter is found increase health
                if character.get_hitpoints() < 10:
                    character.set_hitpoints(character.get_hitpoints() + 1)

        # exits game loop if user dies
        if character.get_hitpoints() <= 0:
            print('You died :(')
            break

        # prints character and asks for next input
        character.print_character()
        player_input = user_input()

    # saves user and map in .json files if user did not die
    if character.get_hitpoints() > 0:
        character.save_user()
        map.save_map()
Exemplo n.º 6
0
    def new_game(self, nom):
        self.out("Generating "+nom+"...")
        # Copie map std
        i = 0

        if not os.path.isdir("data/save_srv/"):
            os.mkdir("data/save_srv/")
        if not os.path.isdir("data/save_srv/"+nom+"/"):
            os.mkdir("data/save_srv/"+nom+"/")

        while map.open_map("map/std/map"+str(i)) != []:
            map.save_map("save_srv/"+nom+"/map"+str(i),map.open_map("map/std/map"+str(i)))
            i = i+1

        # Génération sous-sol
        map.save_map("save_srv/"+nom+"/map-1", self.gen_map(-1))
       
        # Fichier global
        file = open("data/save_srv/"+nom+"/char", "w")
        file.write("")
        file.close()
Exemplo n.º 7
0
    def read(self):
        clients_to_read = []
        try:
            clients_to_read, wlist, xlist = select.select(self.get_clients(), [], [], 0.05)
        except select.error:
            pass
        else:
            for client in clients_to_read:
                try:
                    pbuffer = client.recv(1024)
                    
                    buffer_ret = " "
                    if pbuffer == "exit":
                        self.runned = False
                    buffer = pbuffer.split(";")
                    if buffer[0] == "co_perso":
                        founded = False
                        for i in self.clients:
                            if i.nom == buffer[1]:
                                founded = True
                                break
                        if not founded:
                            founded = False
                            for i in self.clients_saved:
                                if i.nom == buffer[1]:
                                    self.get_client(client).inv.empty()
                                    self.get_client(client).inv.load(i.inv.save())
                                    self.clients_saved.remove(i)
                                    break
                            self.get_client(client).nom = buffer[1]
                            self.get_client(client).color = []
                            self.get_client(client).color.append(buffer[2])
                            self.get_client(client).color.append(buffer[3])
                            self.get_client(client).color.append(buffer[4])
                            self.get_client(client).color.append(buffer[5])
                            self.get_client(client).color.append(buffer[6])
                            self.event.append("connect;"+self.get_client(client).nom)
                            self.event.append("say;"+self.get_client(client).nom+" connected")
                            buffer_ret = "Connected"
                            self.out(str(self.get_client(client).adr)+self.get_client(client).nom+" connected !\a")
                        else:
                            buffer_ret = "Pseudo already used"
                    elif buffer[0] == "get_welcome":
                        buffer_ret="say;"+self.msg_welcome
                    elif buffer[0] == "get_persos":
                        buffer_ret = ""
                        for i in self.clients:
                            if i != self.get_client(client):
                                buffer_ret += i.get_char()+"\n"
                        buffer_ret+= " "
                    elif buffer[0] == "get_perso":
                        if buffer[1] != self.get_client(client).nom and self.get_client_nom(buffer[1]) != None:
                            buffer_ret = self.get_client_nom(buffer[1]).get_char()
                    elif buffer[0] == "get_mobs":
                        buffer_ret=str(int(self.mobs))


                    # Inventory
                    elif buffer[0] == "set_inv":
                        self.get_client(client).inv.empty()
                        self.get_client(client).inv.load(buffer[1])
                    elif buffer[0] == "get_inv":
                        buffer_ret=self.get_client(client).inv.save()

                    # Map
                    elif buffer[0] == "get_map":
                        buffer_ret=map.map2char(self.get_map(int(buffer[1])).map)
                    elif buffer[0] == "set_map":
                        id_map = int(buffer[1])
                        self.get_client(client).map = id_map
                        found = False
                        for i in self.maps:
                            if i.id == id_map:
                                found = True
                        if not found:
                            map.save_map("save_srv/"+self.world+"/map"+str(id_map), self.gen_map(id_map))
                            self.maps.append(map.Map(map.open_map("save_srv/"+self.world+"/map"+str(id_map)),id_map))
                            
                    elif buffer[0] == "set_map_perso":
                        self.get_client(client).map = int(buffer[1])
                        self.get_client(client).id_porte = int(buffer[2])


                    elif buffer[0] == "set_vie":
                        self.get_client(client).vie = int(buffer[1])
                    elif buffer[0] == "nbr_player":
                        buffer_ret = str(len(self.clients))
                    elif buffer[0] == "get_last_event":
                        buffer_ret=str(len(self.event))
                    elif buffer[0] == "get_last_event_map":
                        buffer_ret=str(len(self.get_map(int(buffer[1])).event))
                    elif buffer[0] == "get_event_map":
                        buffer_ret=self.get_map(self.get_client(client).map).send_event(int(buffer[1]), self.get_client(client).nom)
                    elif buffer[0] == "get_event":
                        buffer_ret=self.send_event(int(buffer[1]))
                    elif buffer[0] == "jump":
                        self.get_client(client).isingrav = True
                    elif buffer[0] == "stop_jump":
                        self.get_client(client).isingrav = False
                    elif buffer[0] == "destroy_block":
                        self.get_map(self.get_client(client).map).event.append(self.get_client(client).nom+";"+pbuffer)
                        x = int(buffer[1])
                        y = int(buffer[2])
                        for i in self.get_map(self.get_client(client).map).map:
                            if i.x == x and i.y == y:
                                if isinstance(i, Coal):
                                    self.get_client(client).inv.add(item.Item(34, 4))
                                else:
                                    self.get_client(client).inv.add(i)
                                self.get_map(self.get_client(client).map).map.remove(i)
                                
                    # hit block
                    elif buffer[0] == "hit_block":
                        self.get_map(self.get_client(client).map).event.append(self.get_client(client).nom+";"+pbuffer)
                        x = int(buffer[1])
                        y = int(buffer[2])
                        damage = float(buffer[3])
                        for i in self.get_map(self.get_client(client).map).map:
                            if i.x == x and i.y == y:
                                if i.hit(damage):
                                    if isinstance(i, Coal):
                                        self.get_client(client).inv.add(item.Item(34, 4))
                                    else:
                                        self.get_client(client).inv.add(i)
                                    self.get_map(self.get_client(client).map).map.remove(i)

                    # Set Block
                    elif buffer[0] == "set_block":
                        self.get_map(self.get_client(client).map).event.append(self.get_client(client).nom+";"+pbuffer)
                        x = int(buffer[1])
                        y = int(buffer[2])
                        for i in self.get_map(self.get_client(client).map).map:
                            if i.x == x and i.y == y:
                                self.get_map(self.get_client(client).map).map.remove(i)
                        self.get_map(self.get_client(client).map).map.append(map.char2bloc(buffer[3]))

                    # Add block
                    elif buffer[0] == "add_block":
                        self.get_map(self.get_client(client).map).event.append(self.get_client(client).nom+";"+pbuffer)
                        bloc = map.char2bloc(buffer[1])
                        self.get_client(client).inv.changer_select(self.get_client(client).inv.search(item.Item_Bloc(bloc)))
                        self.get_client(client).inv.delete()
                        self.get_map(self.get_client(client).map).map.append(bloc)
                    elif buffer[0] == "lock_chest":
                        self.get_map(self.get_client(client).map).event.append(self.get_client(client).nom+";"+pbuffer)
                    elif buffer[0] == "say":
                        self.out(self.get_client(client).nom+"> "+buffer[1])
                        buffer_unspaced = buffer[1].split()
                        if buffer_unspaced[0] == "/me" and len(buffer_unspaced)>1:
                            del buffer_unspaced[0]
                            buffer[1] = " ".join(buffer_unspaced)
                            self.event.append("say;"+self.get_client(client).nom+" "+buffer[1])
                        elif buffer_unspaced[0] == "/help":
                            buffer_ret = "say;"+\
                                "Commands help : "+\
                                "\n/help : Shows a list of server commands"+\
                                "\n/welcome :  Shows welcome message"+\
                                "\n/list or /ls : list all connected players"+\
                                "\n/me action : Sends a message as an action"
                        elif buffer_unspaced[0] == "/list" or buffer_unspaced[0] == "/ls":
                            buffer_ret = "say;"+str(len(self.clients))+" player(s) connected :"
                            for i in self.clients:
                                buffer_ret += "\n-"+i.nom
                        elif buffer_unspaced[0] == "/welcome":
                            buffer_ret="say;"+self.msg_welcome
                        elif buffer_unspaced[0] == "/sign":
                            map_temp = self.get_map(self.get_client(client).map).map[:]
                            map_temp.reverse()
                            for i in map_temp:
                                if isinstance(i, Sign):
                                    del buffer_unspaced[0]
                                    buffer[1] = " ".join(buffer_unspaced)
                                    i.txt = buffer[1]
                                    self.get_map(self.get_client(client).map).event.append("server;set_block;"+str(i.x)+";"+str(i.y)+";"+map.bloc2char(i))
                                    break
                            map_temp = None
                        else:
                            self.event.append("say;"+self.get_client(client).nom+"> "+buffer[1])
                     
                    client.send(buffer_ret)
                except socket.error:
                    self.break_connection(client)
Exemplo n.º 8
0
    parser.add_option("-s", "--mintps", type="choice", choices=[str(tps) for tps in mapmod.TPS], dest="mintps", default='0',     help="minimum tps to smooth (optional, default 0)")
    parser.add_option("-t", "--maxtps", type="choice", choices=[str(tps) for tps in mapmod.TPS], dest="maxtps", default='100',   help="maximum tps to smooth (optional, default 100)")

    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("missing map filename")
    filename = args[0]

    original_map = mapmod.read_map_file(filename)

    new_map = smooth_map(original_map, options.weight, options.iterations,
                         mapmod.rpm_to_pos(int(options.minrpm)), 
                         mapmod.rpm_to_pos(int(options.maxrpm)), 
                         mapmod.tps_to_pos(int(options.mintps)), 
                         mapmod.tps_to_pos(int(options.maxtps)))
        
    if options.dump:
        mapmod.dump_map(original_map, "original")
        mapmod.dump_map(new_map, "new")
            
    head,tail = os.path.split(filename)
    newfilename = os.path.join(head, "smooth_"+tail)
    
    mapmod.save_map(filename, newfilename, new_map)
    
    print "New map file saved as %s" % newfilename