Esempio n. 1
0
    def load(self):
        import manipulate_stats as ms

        self.player_dic = jm.load_file(filename='player_dic',
                                       player_name=self.player_dic['name'])
        self.spell_dic = jm.load_file(filename='spell_dic',
                                      player_name=self.player_dic['name'])
        self.attribut_dic = jm.load_file(filename='attribut_dic',
                                         player_name=self.player_dic['name'])
        self.inventory_dic = jm.load_file(filename='inventory_dic',
                                          player_name=self.player_dic['name'])
Esempio n. 2
0
    def __init__(self,player_name):


        self.main_window = Tk()


        self.main_window.title("Bloks")
        self.main_window.resizable(False, False)
        self.main_window.iconbitmap("img/icone.ico")

        self.main_window.option_add('*Font','Constantia 12')
        self.main_window.option_add('*Button.relief','flat')
        self.main_window.option_add('*Button.overRelief','ridge')
        self.main_window.option_add('*justify','left')
        self.backgroundcolor='#292825'
        self.foregroundcolor='#F9D342'
        self.main_window.option_add('*background',self.backgroundcolor)
        self.main_window.option_add('*foreground',self.foregroundcolor)
        self.main_window.option_add('*compound','left')

        #self.main_window.configure(bg='gray')
        self.main_window.attributes("-fullscreen", True)



        # Actuellement : 1280 * 720
        #self.main_canvas = Canvas(self.main_window,width=16*80,height=9*80)
        #self.main_canvas.pack(expand=True,fill="both")

        # Actuellement : 1280 * 560
        self.game_canvas = Canvas(self.main_window,width=16*80,height=7*80)
        self.game_canvas.pack(expand=True,fill="both")
        self.game_canvas.update()

        height = self.game_canvas.winfo_height()
        width = self.game_canvas.winfo_width()

        import outputbox
        self.outputbox = outputbox.OutputBox(canvas=self.game_canvas,x=width-300,y=height-300-200,height=300,width=300)
        self.outputbox.show()

        self.myMap = None
        self.combat = False

        import manipulate_json as jm
        self.player_dic = jm.load_file(filename='player_dic',player_name=player_name)
        self.spell_dic = jm.load_file(filename='spell_dic',player_name=player_name)
        self.attribut_dic = jm.load_file(filename='attribut_dic',player_name=player_name)
        self.inventory_dic = jm.load_file(filename='inventory_dic',player_name=player_name)

        self.draw_menu()
Esempio n. 3
0
def test():

    _map_ = "img/stock/_tiles/Tiled software/my_first_map.tmx"
    _tileset_ = "img/stock/_tiles/Tiled software/bloks.tsx"

    _jsonmap_ = "img/stock/_tiles/Tiled software/map.json"
    _jsontileset_ = "img/stock/_tiles/Tiled software/bloks.json"

    x.xml_to_json(opendir=_map_,savedir=_jsonmap_)
    x.xml_to_json(opendir=_tileset_,savedir=_jsontileset_)

    _mapdic_ = j.load_file(fulldir=_jsonmap_)
    _tilesetdic_ =j.load_file(fulldir=_jsontileset_)


    return(_mapdic_,_tilesetdic_)
Esempio n. 4
0
    def reload_everything(self, *args):
        import manipulate_stats as ms

        self.player_dic = ms.calculate_playerstats(
            attribut_dic=self.attribut_dic, player_dic=self.player_dic)

        self.player_dic = jm.load_file(
            filename='player_dic', player_name=self.player_dic['name'])
        self.spell_dic = jm.load_file(
            filename='spell_dic', player_name=self.player_dic['name'])
        self.attribut_dic = jm.load_file(
            filename='attribut_dic', player_name=self.player_dic['name'])
        self.inventory_dic = jm.load_file(
            filename='inventory_dic', player_name=self.player_dic['name'])
        self.used_objects = jm.load_file(filename="used_objects",player_name=self.player_dic['name'])

        self.outputbox.add_text('Everything has been loaded')
Esempio n. 5
0
def add_used_item(layer, li, go, player_name, myMap):
    """
    Ajoute un item utilisé au json "used_objects" ; ne fait rien s'il est déjà présent
    """
    used_objects = jm.load_file(filename="used_objects",
                                player_name=player_name)
    if [li, go] not in used_objects[layer]:
        used_objects[layer].append([li, go])
        jm.save_file(data=used_objects,
                     filename="used_objects",
                     player_name=player_name)
        myMap.used_objects = used_objects
        myMap.map_by_layer[layer][li][go] = myMap.map_by_layer[0][li][go]
Esempio n. 6
0
def load_map(mapdir,mapname,tilename,imgdir,used_objects):
    import manipulate_xml as x
    import manipulate_json as j

    o_fullmapdir = f"{mapdir}/{mapname}.tmx"
    o_fulltiledir = f"{mapdir}/{tilename}.tsx"

    s_fullmapdir = f"{mapdir}/{mapname}.json"
    s_fulltiledir = f"{mapdir}/{tilename}.json"
    if s_fullmapdir == s_fulltiledir:
        raise Exception("Impossible de mettre le même nom !")


    x.xml_to_json(opendir=o_fullmapdir,savedir=s_fullmapdir)
    x.xml_to_json(opendir=o_fulltiledir,savedir=s_fulltiledir)

    mapdic = j.load_file(fulldir=s_fullmapdir)
    tiledic = j.load_file(fulldir=s_fulltiledir)

    myMap = Map(mapdic=mapdic,tiledic=tiledic,imgdir=imgdir,used_objects=used_objects)


    return(myMap)
Esempio n. 7
0
def add_item_to_inventory(item, player_name):
    import manipulate_json as jm
    inventory_dic = jm.load_file(filename="inventory_dic",
                                 player_name=player_name)
    inventory_dic['itemlist'].append(item)

    # On trie l'inventaire par id
    inventory_dic['itemlist'] = sorted(inventory_dic['itemlist'],
                                       key=lambda x: x['id'])

    # Si on veut pouvoir préciser un dossier de save spécial
    #if savedir != "":
    #    jm.save_file(inventory_dic,fulldir=savedir)

    jm.save_file(inventory_dic,
                 filename="inventory_dic",
                 player_name=player_name)
Esempio n. 8
0
def template_itemlist():
    import manipulate_json as jm
    mypath = "ressources/template/items"

    from os import listdir
    from os.path import isfile, join
    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

    print(onlyfiles)
    itemlist = []

    for filename in onlyfiles:
        print(filename, filename[-5:])
        if filename[-5:] == '.json':
            mydir = f"{mypath}/{filename}"
            item = jm.load_file(fulldir=mydir)
            itemlist.append(item)

    return (itemlist)
Esempio n. 9
0
    def enter(event):
        toolTip.show(player_dic=player_dic, attribut_dic=attribut_dic)

    def leave(event):
        toolTip.hidetip()

    widget.bind('<Enter>', enter)
    widget.bind('<Leave>', leave)


if __name__ == '__main__':
    #player_dic,attribut_dic,spelldic,inventory_dic = dictionnaires.dictionnaires_vierge()
    global w

    import manipulate_json as jm
    player_dic = jm.load_file('player_dic', 'Blue Dragon')
    attribut_dic = jm.load_file('attribut_dic', 'Blue Dragon')
    spell_dic = jm.load_file('spell_dic', 'Blue Dragon')
    inventory_dic = jm.load_file('inventory_dic', 'Blue Dragon')

    a = 0

    if a == 0:

        w = AttributWindow(toplevel=False)
        w.show(player_dic, attribut_dic)

    else:
        w = Tk()

        w.title("Un petit test")
Esempio n. 10
0
def load_inventory_dic():
    import manipulate_json as jm

    return (jm.load_file(fulldir='ressources/template/inventory_dic.json'))
Esempio n. 11
0
def load_player_dic():
    import manipulate_json as jm

    return (jm.load_file(fulldir='ressources/template/player_dic.json'))
Esempio n. 12
0
    def show(self,
             stat_dic,
             name,
             level,
             image_dir,
             category='',
             x_relative=0,
             y_relative=0):
        if self.stats_window:
            return

        if type(self.widget) == str:
            if self.toplevel:
                self.stats_window = Toplevel()
                self.stats_window.wm_overrideredirect(1)
                self.stats_window.wm_geometry("+%d+%d" %
                                              (x_relative, y_relative))
                self.stats_window.focus_force()
            else:
                self.stats_window = Tk()

            self.bold_font13 = "Constantia 13 bold"
            self.bold_font16 = "Constantia 16 bold"
            self.classic_font12 = "Constantia 12"
            self.classic_font16 = "Constantia 16"

            self.underline_font12 = "Constantia 12 bold underline"
            self.bold_font12 = "Constantia 12 bold"
            self.classic_font12 = "Constantia 12"

        else:
            x, y, cx, cy = self.widget.bbox("insert")
            x = x + self.widget.winfo_rootx() + 12
            y = y + cy + self.widget.winfo_rooty() + 40
            self.stats_window = Toplevel(self.widget)

            self.stats_window.wm_overrideredirect(1)
            self.stats_window.wm_geometry("+%d+%d" %
                                          (x + x_relative, y + y_relative))

            self.bold_font13 = "Constantia 10 bold"
            self.bold_font16 = "Constantia 10 bold"
            self.classic_font16 = "Constantia 10"
            self.classic_font12 = "Constantia 10"

            self.underline_font12 = "Constantia 10 bold underline"
            self.bold_font12 = "Constantia 10 bold"
            self.classic_font12 = "Constantia 10"

        self.stats_window.title("Stats")
        self.stats_window.resizable(False, False)
        self.stats_window.iconbitmap("img/icone.ico")

        self.stats_window.option_add('*Font', 'Constantia 12')
        #self.stats_window.option_add('*Button.activebackground','darkgray')
        #self.stats_window.option_add('*Button.activeforeground','darkgray')
        #self.stats_window.option_add('*Button.relief','groove')
        #self.stats_window.option_add('*Button.overRelief','ridge')
        self.stats_window.option_add('*justify', 'left')
        self.stats_window.option_add('*bg', 'lightgray')
        self.stats_window.option_add('*compound', 'left')

        self.stats_canvas = Canvas(self.stats_window)
        self.stats_canvas.pack(fill=BOTH, expand=True, padx=20, pady=20)

        self.stat_dic = stat_dic
        self.img_dic = dictionnaires.dictionnaires_vierge(loadimg=True)

        itsimage = PhotoImage(file=image_dir)
        name_label = Label(self.stats_canvas,
                           text=str(name),
                           font=self.bold_font13,
                           image=itsimage)
        name_label.grid(row=0, column=0)

        level_label = Label(self.stats_canvas,
                            text=str(level),
                            font=self.bold_font13,
                            image=self.img_dic['starnoir'])
        level_label.grid(row=0, column=1)

        if len(category) > 0:
            category_label = Label(self.stats_canvas,
                                   text=str(category),
                                   font=self.bold_font13,
                                   image=self.img_dic[category])
            category_label.grid(row=0, column=2)

        Frame(self.stats_canvas, height=10).grid(row=1)

        # Ecriture de tous les boutons
        # On ajoute 'name' pour pouvoir les identifier en cliquant dessus
        stat_name_list = list(self.stat_dic.keys())
        stat_value_list = list(self.stat_dic.values())

        import manipulate_json as jm
        attribut_dic = jm.load_file(
            fulldir="ressources/template/attribut_dic.json")

        imglist = []
        ligne, colonne = 1, 0
        k1 = 2
        k2 = 0
        for i in range(len(stat_name_list)):

            attribut_name = str(stat_name_list[i])
            attribut_value = f"{stat_value_list[i]:0.1f}"
            color = str(attribut_dic[attribut_name]['color'])
            imglist.append(
                PhotoImage(file=attribut_dic[attribut_name]['image']))

            l1 = Label(self.stats_canvas,
                       text=f"{attribut_name} : {attribut_value}",
                       fg=color,
                       font=self.bold_font12,
                       image=imglist[i])
            l1.grid(row=ligne + k1, column=colonne + k2, padx=10, sticky=W)

            ctt.CreateToolTip(l1, attribut_dic[attribut_name]['description'])

            ligne += 1

            if i == 5:
                ligne = 2
                colonne = 1
            if i == 10:
                ligne = 2
                colonne = 2

        if type(self.widget) == str:
            # Séparateur suivi du bouton 'Confirmer'
            Frame(self.stats_canvas, height=10).grid(row=i + k1 + 1)
            Button(self.stats_canvas, text="Confirmer",
                   command=self.confirm).grid(row=i + k1 + 2,
                                              column=0,
                                              columnspan=10)

        self.stats_window.mainloop()
Esempio n. 13
0
 def reload_everything(self,*args):
     print("Everything was loaded")
     self.player_dic = jm.load_file(filename='player_dic',player_name=self.player_dic['name'])
     self.spell_dic = jm.load_file(filename='spell_dic',player_name=self.player_dic['name'])
     self.attribut_dic = jm.load_file(filename='attribut_dic',player_name=self.player_dic['name'])
     self.inventory_dic = jm.load_file(filename='inventory_dic',player_name=self.player_dic['name'])
Esempio n. 14
0
        self.playbutton.destroy()

        self.player_stats = None
        self.equipped_list = None
        self.combat = False
        self.playerturn = False
        self.player_stats = None
        self.monster_dic = None


if __name__ == "__main__":
    global w
    import manipulate_json as jm
    import manipulate_map as mm

    player_dic = jm.load_file('player_dic','Blue Dragon')
    attribut_dic =jm.load_file('attribut_dic','Blue Dragon')
    spell_dic = jm.load_file('spell_dic','Blue Dragon')
    inventory_dic = jm.load_file('inventory_dic','Blue Dragon')
    monster_dic = jm.load_file(fulldir="ressources/template/monster/slime_bleu.json")

    mapdir = "img/stock/_tiles/Tiled software"
    mapname = "my_first_map"
    tilename = "bloks"

    imgdir = "img/stock/_tiles/resized"



    w = Main_Window(player_dic['name'])
Esempio n. 15
0
    def test_combat(self, *args):
        if not self.combat:
            monster_dic = jm.load_file(
                fulldir="ressources/template/monster/slime_rouge.json")

            self.show_combat(monster_dic=monster_dic)
Esempio n. 16
0
 def load_map(self, mapdir, mapname, tilename, imgdir):
     used_objects = jm.load_file(filename="used_objects",player_name=self.player_dic['name'])
     self.myMap = mm.load_map(mapdir=mapdir, mapname=mapname, tilename=tilename, imgdir=imgdir, used_objects=used_objects)