コード例 #1
0
def get_player_servants(servant_database):
    player_servants = servant_database
    servant_list = []
    GlobalLibrary.debug(str(player_servants["ActiveServants"]))
    for i in range(0, 3):
        servant = player_servants["Servants"][int(
            player_servants["ActiveServants"][i])]
        file_path = str("Servants/" + servant + ".json")
        with open(file_path, 'r', encoding="utf8") as file_ref:
            json_ref = json.load(file_ref)  # Load file into JSON module
            servant_level = int(player_servants["Levels"][int(
                player_servants["ActiveServants"][i])])
            json_ref["HP"] = int(
                int(json_ref["HP"]) * (1 + (servant_level / 30)))
            json_ref["ATK"] = int(
                int(json_ref["ATK"]) * (1 + (servant_level / 30)))
            json_ref.update({"Level": servant_level})
            json_ref.update({"Allied": True})
            json_ref.update({
                "CurrentHP":
                int(int(json_ref["HP"]) * (1 + (servant_level / 30)))
            })
            json_ref.update({"CurrentNP": 0})
            servant_list.append(json_ref)
    servant1 = servant_list[0]
    servant2 = servant_list[1]
    servant3 = servant_list[2]
    return servant1, servant2, servant3
コード例 #2
0
    def __init__(self, GUI, grid_size):
        GlobalLibrary.initalise(Battle.__name__)

        # INTERFACE ASSETS
        GUI.logo_image = self.image_resize("Pictures/Logo.png",
                                           int(GUI.monitor_resolution_x / 10),
                                           int(GUI.monitor_resolution_y / 10))
        GUI.ui_servant_select_stats_bg = self.image(
            "Pictures/UI/ServantSelectStats.png")
        GUI.ui_turn_order_bg = self.image("Pictures/UI/TurnOrder.png")
        GUI.ui_move_icon = self.image_resize("Pictures/UI/MoveIcon.png",
                                             grid_size, grid_size)
        GUI.ui_attack_icon = self.image_resize("Pictures/UI/AttackIcon.png",
                                               grid_size, grid_size)

        # CLASS LOGOS
        GUI.ui_class_saber = self.image("Pictures/Classes/Saber.png")
        GUI.ui_class_archer = self.image("Pictures/Classes/Archer.png")
        GUI.ui_class_lancer = self.image("Pictures/Classes/Lancer.png")
        GUI.ui_class_caster = self.image("Pictures/Classes/Caster.png")
        GUI.ui_class_rider = self.image("Pictures/Classes/Rider.png")
        GUI.ui_class_assassin = self.image("Pictures/Classes/Assassin.png")
        GUI.ui_class_ruler = self.image("Pictures/Classes/Ruler.png")
        GUI.ui_class_shielder = self.image("Pictures/Classes/Shielder.png")
        GUI.ui_class_berserker = self.image("Pictures/Classes/Berserker.png")

        GlobalLibrary.notice("Battle Graphical Assets Imported")
コード例 #3
0
def get_all_player_servants(servant_database):
    servant_list = []
    servant_list_master = []
    for i in range(len(servant_database["Servants"])):
        try:
            servant = servant_database["Servants"][i]
            file_path = str("Servants/" + servant + ".json")
            with open(file_path, 'r', encoding="utf8") as file_ref:
                json_ref = json.load(file_ref)  # Load file into JSON module
            servant_level = int(servant_database["Levels"][i])
            json_ref["HP"] = int(
                int(json_ref["HP"]) * (1 + (servant_level / 30)))
            json_ref["ATK"] = int(
                int(json_ref["ATK"]) * (1 + (servant_level / 30)))
            json_ref.update({"Level": servant_level})
            json_ref.update({"Allied": True})
            json_ref.update({
                "CurrentHP":
                int(int(json_ref["HP"]) * (1 + (servant_level / 30)))
            })
            json_ref.update({"CurrentNP": 0})
            servant_list.append(json_ref)
            if len(servant_list) == 10:
                servant_list_master.append(servant_list)
                servant_list = []
        except KeyError:
            GlobalLibrary.error("Servant File Error")

    servant_list_master.append(servant_list)
    return servant_list_master
コード例 #4
0
 def __init__(self, player_stats):
     GlobalLibrary.initalise(Main.__name__)
     self.enemy_AI = None
     self.grid_manager = None
     self.player_stats = player_stats
     self.GUI = None
     self.CurrentTurnCounter = 0
     self.OverallTurnCounter = 0
     self.TurnCounterList = []
コード例 #5
0
 def __init__(self, servant_database):
     GlobalLibrary.initalise(Main.__name__)
     self.servant_1 = servant_database['Servants'][int(
         servant_database['ActiveServants'][0])]
     self.servant_2 = servant_database['Servants'][int(
         servant_database['ActiveServants'][1])]
     self.servant_3 = servant_database['Servants'][int(
         servant_database['ActiveServants'][2])]
     self.set_servant_references(servant_database)
コード例 #6
0
 def __init__(self, grid_amount, grid_size, GUI, turn_tracker):
     GlobalLibrary.initalise(Main.__name__)
     self.GUI = GUI
     self.grid_size = int(grid_size)
     self.grid_amount = int(grid_amount)
     self.grid = []
     self.turn_tracker = turn_tracker
     for i in range(0, grid_amount):
         self.grid.append(["#"] * self.grid_amount)
コード例 #7
0
    def start_enemy_turn(self, entity, x, y):
        GlobalLibrary.notice(
            str("Enemy " + entity['Name'] + "'s turn has started!"))
        target_list = []
        for pos_y in range(len(self.grid_manager.grid)):
            for pos_x in range(len(self.grid_manager.grid[pos_y])):
                pos = self.grid_manager.grid[pos_y][pos_x]
                if isinstance(pos, dict):
                    if pos['Allied']:
                        distance = int(abs(x - pos_x) + abs(y - pos_y) / 2)
                        strength = int(((pos['HP'] + pos['ATK']) / 1000) +
                                       (pos['Range']))
                        level_gap = entity['Level'] - pos['Level']
                        danger_value = 10 + int((
                            (-distance + strength) -
                            (int(pos['CurrentHP'] / 5000))) + (level_gap / 2))
                        target = [pos, pos_x, pos_y, danger_value]
                        target_list.append(target)
        if len(target_list) > 0:
            current_target = target_list[0]
            for target in target_list:
                if target[3] > current_target[3]:
                    current_target = target
            if int(abs(x - current_target[1])) <= entity['Range'] and int(
                    abs(y - current_target[2])) <= entity['Range']:
                self.GUI.servant_selected_attack(entity, current_target[0],
                                                 current_target[1],
                                                 current_target[2])
            elif int(abs(x - current_target[1])) <= int(
                    entity['Move'] * 2) and int(
                        abs(y - current_target[2])) <= int(entity['Move'] * 2):
                new_x = (x - current_target[1]) % entity['Move']
                if new_x == 0 and current_target[1] < x:
                    new_x = (x - entity['Move']) + 1
                elif new_x == 0 and current_target[1] > x:
                    new_x = (x + entity['Move']) - 1
                elif new_x != 0 and current_target[1] < x:
                    new_x = x - new_x
                elif new_x != 0 and current_target[1] > x:
                    new_x = x + new_x
                else:
                    new_x = x
                new_y = (y - current_target[2]) % entity['Move']
                if new_y == 0 and current_target[2] < y:
                    new_y = (y - entity['Move']) + 1
                elif new_y == 0 and current_target[2] > y:
                    new_y = (y + entity['Move']) - 1
                elif new_y != 0 and current_target[2] < y:
                    new_y = y - new_y
                elif new_y != 0 and current_target[2] > y:
                    new_y = y + new_y
                else:
                    new_y = y

                self.grid_manager.move_grid_pos(x, y, new_x, new_y, True)
コード例 #8
0
    def __init__(self, GUI):
        GlobalLibrary.initalise(Cover.__name__)

        image_reference = Image.open(
            str("Pictures/Wallpapers/" +
                random.choice(os.listdir("Pictures/Wallpapers"))))
        image_reference = image_reference.resize(
            (GUI.monitor_resolution_x, GUI.monitor_resolution_y),
            Image.ANTIALIAS)
        GUI.wallpaper = ImageTk.PhotoImage(image_reference)
        GUI.logo_image = self.image_resize("Pictures/Logo.png",
                                           int(GUI.monitor_resolution_x / 4),
                                           int(GUI.monitor_resolution_y / 4))
        GUI.ui_click_to_start = self.image_scale(
            "Pictures/UI/ClickToStart.png", 0.5)
        GlobalLibrary.notice("Menu Graphical Assets Imported")
コード例 #9
0
 def update_servant_list(self):
     list_pos_y = 252
     for i in range(len(self.canvas_servant_list_bg)):
         self.canvas_servant_list.delete(self.canvas_servant_list_bg[i])
         self.canvas_servant_list.delete(
             self.canvas_servant_list_text_name[i])
         self.canvas_servant_list.delete(self.canvas_servant_list_image[i])
         self.canvas_servant_list.delete(
             self.canvas_servant_list_image_ref[i])
     for servant in self.servant_list[self.servant_list_page]:
         self.canvas_servant_list_bg.append(
             self.canvas_servant_list.create_rectangle(
                 123,
                 list_pos_y - 27,
                 580,
                 list_pos_y + 27,
                 fill="#2c2303",
                 tags=(servant['Name'], "servant_list")))
         self.canvas_servant_list_text_name.append(
             self.canvas_servant_list.create_text(180,
                                                  list_pos_y,
                                                  text=servant['Name'],
                                                  fill="#cccccc",
                                                  font=("Coolvetica Rg",
                                                        25),
                                                  anchor="w",
                                                  tags=(servant['Name'],
                                                        "servant_list")))
         try:
             servant_image = UIAssetImport.get_servant_icon(servant, 50, 50)
         except FileNotFoundError:
             GlobalLibrary.error(
                 str("Servant needs icon: " + servant['Name']))
             servant_image = UIAssetImport.image_resize(
                 "Pictures/Class-Shielder-Gold.png", 50, 50)
         self.canvas_servant_list_image_ref.append(servant_image)
         self.canvas_servant_list_image.append(
             self.canvas_servant_list.create_image(150,
                                                   list_pos_y,
                                                   image=servant_image,
                                                   anchor="c",
                                                   tags=(servant['Name'],
                                                         "servant_list")))
         list_pos_y += 55
     self.canvas_servant_list.tag_bind("servant_list", "<Button-1>",
                                       self.select_servant)
コード例 #10
0
    def __init__(self, GUI):
        GlobalLibrary.initalise(Menu.__name__)

        # INTERFACE ASSETS
        GUI.logo_image = self.image_resize("Pictures/Logo.png",
                                           int(GUI.monitor_resolution_x / 10),
                                           int(GUI.monitor_resolution_y / 10))
        GUI.ui_servant_list = self.image("Pictures/UI/ServantList.png")
        GUI.ui_servant_list_button = self.image(
            "Pictures/UI/ServantListButton.png")
        GUI.ui_servant_list_title = self.image(
            "Pictures/UI/ServantListTitle.png")
        GUI.ui_servant_bio = self.image("Pictures/UI/ServantBio.png")
        GUI.ui_fight_button = self.image("Pictures/UI/FightButton.png")
        GUI.ui_team_list = self.image("Pictures/UI/TeamList.png")

        # GENERIC ICONS
        GUI.ui_right_arrow = self.image_resize("Pictures/UI/RightArrow.png",
                                               20, 20)
        GUI.ui_left_arrow = self.image_resize("Pictures/UI/LeftArrow.png", 20,
                                              20)
        GUI.ui_refresh = self.image_resize("Pictures/UI/Refresh.png", 20, 20)

        # CLASS LOGOS
        GUI.ui_class_saber = self.image_scale("Pictures/Classes/Saber.png",
                                              0.7)
        GUI.ui_class_archer = self.image_scale("Pictures/Classes/Archer.png",
                                               0.7)
        GUI.ui_class_lancer = self.image_scale("Pictures/Classes/Lancer.png",
                                               0.7)
        GUI.ui_class_caster = self.image_scale("Pictures/Classes/Caster.png",
                                               0.7)
        GUI.ui_class_rider = self.image_scale("Pictures/Classes/Rider.png",
                                              0.7)
        GUI.ui_class_assassin = self.image_scale(
            "Pictures/Classes/Assassin.png", 0.7)
        GUI.ui_class_ruler = self.image_scale("Pictures/Classes/Ruler.png",
                                              0.7)
        GUI.ui_class_shielder = self.image_scale(
            "Pictures/Classes/Shielder.png", 0.7)
        GUI.ui_class_berserker = self.image_scale(
            "Pictures/Classes/Berserker.png", 0.7)

        GlobalLibrary.notice("Menu Graphical Assets Imported")
コード例 #11
0
    def next_turn(self):
        allies_remaining = False
        for servant in self.TurnCounterList:
            servant_data, servant_x, servant_y = self.grid_manager.find_servant(
                servant)
            if servant_data['Allied'] == True:
                allies_remaining = True
        if allies_remaining == False:
            self.GUI.open_main_menu("")
        self.CurrentTurnCounter += 1
        if self.CurrentTurnCounter > len(self.TurnCounterList) - 1:
            self.CurrentTurnCounter = 0
            self.OverallTurnCounter += 1

        GlobalLibrary.notice(str("Turn: " + str(self.OverallTurnCounter)))
        self.display_current_turn()
        servant_data, servant_x, servant_y = self.grid_manager.find_servant(
            self.TurnCounterList[self.CurrentTurnCounter])
        if not servant_data["Allied"]:
            self.enemy_AI.start_enemy_turn(servant_data, servant_x, servant_y)
            self.next_turn()
コード例 #12
0
 def __init__(self):
     GlobalLibrary.initalise(ServantDatabase.__name__)
     GlobalLibrary.notice("Connecting to Mongo Server!")
     try:
         self.server_ref = pymongo.MongoClient(
             "mongodb+srv://FateGameClient:[email protected]/test?retryWrites=true&w"
             "=majority")
     except pymongo.errors.AutoReconnect:
         GlobalLibrary.error("Connection Failed, Reconnecting!")
     except pymongo.errors.ConnectionFailure:
         GlobalLibrary.error("Connection Failed!")
     self.collection_ref = self.server_ref[
         'fate']  # Open the Collection "fate"
     self.database_servants = self.collection_ref[
         'servants']  # Open the Database "servants"
コード例 #13
0
 def servant_selected_attack(self, attacking_servant, target_servant, x, y):
     if random.randint(0, 20) == 30:
         damage = int(attacking_servant['ATK'] / 2 *
                      (random.randint(7, 10) / 10))
         target_servant['CurrentHP'] -= damage
         GlobalLibrary.notice(
             str(attacking_servant['Name'] + " critted " +
                 target_servant['Name'] + " for " + str(damage)))
     else:
         damage = int(attacking_servant['ATK'] *
                      (random.randint(7, 10) / 10))
         target_servant['CurrentHP'] -= damage
         GlobalLibrary.notice(
             str(attacking_servant['Name'] + " attacked " +
                 target_servant['Name'] + " for " + str(damage)))
     if target_servant['CurrentHP'] <= 0:
         self.grid_manager.set_grid_pos(x, y, "#", True)
         for image in self.image_ref_array:
             if image['Name'] == target_servant['Name']:
                 image_ref = image['Image']
                 self.canvas.delete(image_ref)
         GlobalLibrary.notice(str(target_servant['Name'] + " has died!"))
         self.turn_tracker.TurnCounterList.remove(target_servant['Name'])
         self.turn_tracker.CurrentTurnCounter -= 1
コード例 #14
0
def load_tileset(tileset, grid_size, GUI):  # TERRAIN TILES
    GUI.ui_tiles = {}
    for tile in tileset:
        GUI.ui_tiles.update(
            {tile[0]: image_resize(tile[1], grid_size, grid_size)})
    GlobalLibrary.notice("Tileset Imported")
コード例 #15
0
import socket

from Scripts import CoverGUI, GlobalLibrary

GlobalLibrary.initalise(__file__)

user_device_name = socket.gethostname()
user_IP = socket.gethostbyname(socket.gethostname())
GlobalLibrary.debug(str(user_device_name + " | " + user_IP))
cover_interface = CoverGUI.Main(user_IP)
cover_interface.start_mainloop()
コード例 #16
0
 def servant_selected_both(self, click_selection):
     GlobalLibrary.notice(click_selection['Name'] + " selected.")
     self.selected_servant = click_selection
     selected_servant_move = (self.selected_servant['Move'] * 2) + 1
     selected_servant_move_start_x = (
         (self.grid_clicked_x * self.grid_size) -
         (self.selected_servant['Move'] * self.grid_size))
     selected_servant_move_start_y = (
         (self.grid_clicked_y * self.grid_size) -
         (self.selected_servant['Move'] * self.grid_size))
     for row in range(selected_servant_move):
         for column in range(selected_servant_move):
             x = int(column +
                     (selected_servant_move_start_x / self.grid_size))
             y = int(row + (selected_servant_move_start_y / self.grid_size))
             if 0 <= x < self.grid_amount and 0 <= y < self.grid_amount:
                 if self.grid_manager.get_grid_pos(x, y) == "#":
                     x_start = selected_servant_move_start_x + (
                         column * self.grid_size) + self.grid_origin_x
                     y_start = selected_servant_move_start_y + (
                         row * self.grid_size) + self.grid_origin_y
                     selection_box = self.canvas.create_image(
                         x_start,
                         y_start,
                         image=self.ui_move_icon,
                         anchor="nw",
                         tags="move_selection_box")
                     self.selection_array.append(selection_box)
     self.canvas.tag_bind("move_selection_box", "<Button-1>",
                          self.servant_selected_move_click)
     selected_servant_attack = (self.selected_servant['Range'] * 2) + 1
     selected_servant_attack_start_x = (
         (self.grid_clicked_x * self.grid_size) -
         (self.selected_servant['Range'] * self.grid_size))
     selected_servant_attack_start_y = (
         (self.grid_clicked_y * self.grid_size) -
         (self.selected_servant['Range'] * self.grid_size))
     for row in range(selected_servant_attack):
         for column in range(selected_servant_attack):
             x = int(column +
                     (selected_servant_attack_start_x / self.grid_size))
             y = int(row +
                     (selected_servant_attack_start_y / self.grid_size))
             if 0 <= x < (self.grid_amount -
                          2) and 0 <= y < (self.grid_amount - 2):
                 grid_pos_ref = self.grid_manager.get_grid_pos(x, y)
                 if not isinstance(grid_pos_ref, str):
                     if grid_pos_ref['Allied'] is False:
                         x_start = (selected_servant_attack_start_x +
                                    (column * self.grid_size) +
                                    self.grid_origin_x)
                         y_start = (selected_servant_attack_start_y +
                                    (row * self.grid_size) +
                                    self.grid_origin_y)
                         selection_box = self.canvas.create_image(
                             x_start,
                             y_start,
                             image=self.ui_attack_icon,
                             anchor="nw",
                             tags="attack_selection_box")
                         self.selection_array.append(selection_box)
     self.canvas.tag_bind("attack_selection_box", "<Button-1>",
                          self.servant_selected_attack_event)
     self.display_servant_stats()
コード例 #17
0
 def __init__(self, grid_manager, GUI):
     GlobalLibrary.initalise(Main.__name__)
     self.grid_manager = grid_manager
     self.GUI = GUI
コード例 #18
0
import json
import os
import sys

import pymongo

from Scripts import GlobalLibrary

GlobalLibrary.initalise(__file__)


class ServantDatabase:
    def __init__(self):
        GlobalLibrary.initalise(ServantDatabase.__name__)
        GlobalLibrary.notice("Connecting to Mongo Server!")
        try:
            self.server_ref = pymongo.MongoClient(
                "mongodb+srv://FateGameClient:[email protected]/test?retryWrites=true&w"
                "=majority")
        except pymongo.errors.AutoReconnect:
            GlobalLibrary.error("Connection Failed, Reconnecting!")
        except pymongo.errors.ConnectionFailure:
            GlobalLibrary.error("Connection Failed!")
        self.collection_ref = self.server_ref[
            'fate']  # Open the Collection "fate"
        self.database_servants = self.collection_ref[
            'servants']  # Open the Database "servants"

    def find_servant(self, servant_name):
        search_query = {"Name": servant_name}
        search_result = self.database_servants.find_one(search_query)
コード例 #19
0
    def show_servant_bio(self):
        for servant in self.servant_list[self.servant_list_page]:
            if servant['Name'] == self.selected_servant:
                self.servant_data = servant
        base_servant_data = Servants.get_servant(self.servant_data['Name'])
        self.canvas_servant_bio.create_image(415,
                                             500,
                                             image=self.ui_servant_bio,
                                             anchor="c",
                                             tags="servant_bio")
        self.canvas_servant_bio.create_text(220,
                                            280,
                                            text=self.servant_data['Name'],
                                            fill="#cccccc",
                                            font=("Coolvetica Rg", 30),
                                            anchor="w",
                                            tags="servant_bio")
        try:
            self.selected_servant_image = UIAssetImport.get_servant_icon(
                self.servant_data, 125, 125)
        except FileNotFoundError:
            GlobalLibrary.error("REMEMBER TO ADD ICON PATHS TO SERVANTS!!!")
            self.selected_servant_image = UIAssetImport.image_resize(
                "Pictures/Class-Shielder-Gold.png", 125, 125)
        self.canvas_servant_bio.create_image(107,
                                             315,
                                             image=self.selected_servant_image,
                                             anchor="c",
                                             tags="servant_bio")
        self.canvas_servant_bio.create_text(
            220,
            320,
            text=str("HP: " + str(self.servant_data['HP']) + " (" +
                     str(base_servant_data['HP']) + ")"),
            fill="#888888",
            font=("Coolvetica Rg", 15),
            anchor="w",
            tags="servant_bio")
        self.canvas_servant_bio.create_text(
            400,
            320,
            text=str("HP: " + str(self.servant_data['ATK']) + " (" +
                     str(base_servant_data['ATK']) + ")"),
            fill="#888888",
            font=("Coolvetica Rg", 15),
            anchor="w",
            tags="servant_bio")
        self.canvas_servant_bio.create_text(
            580,
            320,
            text=str("Move: " + str(self.servant_data['Move'])),
            fill="#888888",
            font=("Coolvetica Rg", 15),
            anchor="w",
            tags="servant_bio")
        self.canvas_servant_bio.create_rectangle(215,
                                                 340,
                                                 780,
                                                 370,
                                                 fill="#2c2303",
                                                 tags="servant_bio")

        self.canvas_servant_bio.create_rectangle(220,
                                                 345,
                                                 (self.servant_data['Level'] *
                                                  ((775 - 215) / 100)) + 215,
                                                 365,
                                                 fill="#433607",
                                                 tags="servant_bio")
        self.canvas_servant_bio.create_text(
            ((self.servant_data['Level'] * ((775 - 215) / 100)) / 2) + 215,
            355,
            text=str(self.servant_data['Level']),
            fill="#888888",
            font=("Coolvetica Rg", 12),
            anchor="c",
            tags="servant_bio")
        try:
            if self.servant_data['Class'] == "Saber":
                servant_class = self.ui_class_saber
            elif self.servant_data['Class'] == "Archer":
                servant_class = self.ui_class_archer
            elif self.servant_data['Class'] == "Lancer":
                servant_class = self.ui_class_lancer
            elif self.servant_data['Class'] == "Caster":
                servant_class = self.ui_class_caster
            elif self.servant_data['Class'] == "Rider":
                servant_class = self.ui_class_rider
            elif self.servant_data['Class'] == "Assassin":
                servant_class = self.ui_class_assassin
            elif self.servant_data['Class'] == "Ruler":
                servant_class = self.ui_class_ruler
            elif self.servant_data['Class'] == "Shielder":
                servant_class = self.ui_class_shielder
            elif self.servant_data['Class'] == "Berserker":
                servant_class = self.ui_class_berserker
            self.canvas_servant_bio.create_image(740,
                                                 290,
                                                 image=servant_class,
                                                 anchor="c",
                                                 tags="servant_bio")
        except KeyError:
            GlobalLibrary.error("REMEMBER TO ADD CLASSES TO SERVANTS")
        except UnboundLocalError:
            GlobalLibrary.error("REMEMBER TO ADD CLASSES TO SERVANTS")

        try:
            self.canvas_servant_bio.create_text(55,
                                                425,
                                                text=str(
                                                    self.servant_data['Desc']),
                                                fill="#888888",
                                                font=("Coolvetica Rg", 15),
                                                anchor="nw",
                                                justify="left",
                                                width=725,
                                                tags="servant_bio")
        except KeyError:
            GlobalLibrary.error("REMEMBER TO ADD DESCRIPTIONS TO SERVANTS")
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 160,
            image=self.ui_servant_list_button,
            anchor="c",
            tags=("servant_bio", "team_slot1"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 160,
            image=self.ui_right_arrow,
            anchor="c",
            tags=("servant_bio", "team_slot1"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 30,
            image=self.ui_servant_list_button,
            anchor="c",
            tags=("servant_bio", "team_slot2"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 30,
            image=self.ui_right_arrow,
            anchor="c",
            tags=("servant_bio", "team_slot2"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) + 100,
            image=self.ui_servant_list_button,
            anchor="c",
            tags=("servant_bio", "team_slot3"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) + 100,
            image=self.ui_right_arrow,
            anchor="c",
            tags=("servant_bio", "team_slot3"))
        self.canvas_team_list.tag_bind("team_slot1", "<Button-1>",
                                       self.set_player_servant)
        self.canvas_team_list.tag_bind("team_slot2", "<Button-1>",
                                       self.set_player_servant)
        self.canvas_team_list.tag_bind("team_slot3", "<Button-1>",
                                       self.set_player_servant)
コード例 #20
0
    def sync_files(self):
        try:
            for database_document in self.database_servants.find(
            ):  # Iterate through every Document in Servant Database
                file_path = str(
                    "Servants/" + database_document['Name'] +
                    ".json")  # Set relative file path for selected Servant

                if os.path.isfile(
                        path=file_path
                ):  # Check is selected Servant has a local file
                    GlobalLibrary.debug("File Found - " + file_path)

                    with open(file_path, 'r', encoding="utf8") as file_ref:
                        file_json = json.load(
                            file_ref)  # Load file into JSON module

                    database_document['_id'] = str(
                        database_document['_id']
                    )  # Converts the ID value to string

                    if database_document == file_json:  # Checks if files match exactly
                        GlobalLibrary.debug("File Matched - " + file_path)
                    else:
                        GlobalLibrary.debug("File Didn't Match - " + file_path)
                        os.remove(file_path)  # Delete the old file
                        with open(file_path,
                                  'w') as file_ref:  # Create a new file
                            json.dump(obj=database_document,
                                      fp=file_ref,
                                      ensure_ascii=False,
                                      indent=2)  # Write to file
                        GlobalLibrary.debug("File Updated - " + file_path)
                else:
                    GlobalLibrary.debug("File Not Found - " + file_path)
                    database_document['_id'] = str(
                        database_document['_id']
                    )  # Converts the ID value to string
                    with open(file_path, 'w') as file_ref:  # Create a new file
                        json.dump(obj=database_document,
                                  fp=file_ref,
                                  ensure_ascii=False,
                                  indent=2)  # Write to file
                    GlobalLibrary.debug("File Created - " + file_path)
            GlobalLibrary.notice("File Sync Complete!")
        except pymongo.errors.ServerSelectionTimeoutError:  # Error if connection times out
            GlobalLibrary.error("Connection Failed")
            sys.exit()
コード例 #21
0
    def __init__(self, window, user_IP, grid_amount, grid_size, turn_tracker,
                 player_stats):
        GlobalLibrary.initalise(Main.__name__)
        self.window = window
        # Set ""Global"" Variables
        self.user_IP = user_IP
        self.grid_amount = grid_amount  # Number of Boxes
        self.grid_size = grid_size  # Box Size
        self.grid_manager = None
        self.grid_clicked_x = int
        self.grid_clicked_y = int
        self.turn_tracker = turn_tracker
        self.player_stats = player_stats
        self.servant_has_moved = False
        self.image_array = []
        self.image_ref_array = []
        self.selection_array = []
        self.monitor_resolution_x = window.winfo_screenwidth()
        self.monitor_resolution_y = window.winfo_screenheight()
        self.grid_origin_x = self.monitor_resolution_x / 2 + (
            -int(self.grid_amount / 2) * self.grid_size)
        self.grid_origin_y = self.monitor_resolution_y / 2 + (
            -int(self.grid_amount / 2) * self.grid_size)
        self.selected_servant = object
        if not hasattr(self, 'canvas'):
            UIAssetImport.Battle(self, grid_size)
        # Create main Canvas
        self.canvas = tkinter.Canvas(window,
                                     width=self.monitor_resolution_x,
                                     height=self.monitor_resolution_y,
                                     bg="#333337",
                                     bd=0,
                                     highlightthickness=0,
                                     relief='ridge')
        self.canvas.pack()
        self.canvas.create_image(10,
                                 0,
                                 image=self.logo_image,
                                 anchor="nw",
                                 tags="logo_image")
        self.canvas.tag_bind("logo_image", "<Button-1>", self.open_main_menu)

        # Set Mouse Binds
        self.canvas.bind("<Button-1>", self.click)

        self.turn_counter_bg = self.canvas.create_image(
            self.monitor_resolution_x,
            self.monitor_resolution_y,
            image=self.ui_turn_order_bg,
            anchor="se")
        self.turn_counter_text = (self.canvas.create_text(
            self.monitor_resolution_x - 65,
            self.monitor_resolution_y - 88,
            text="DEBUG",
            fill="#ffffff",
            font=("Coolvetica Rg", 20),
            anchor="c",
            justify="center"))
        self.turn_counter_image = []
        self.turn_counter_image.append(
            self.canvas.create_image(self.monitor_resolution_x - 275,
                                     self.monitor_resolution_y - 30,
                                     image=self.logo_image,
                                     anchor="c"))
        self.turn_counter_image.append(
            self.canvas.create_image(self.monitor_resolution_x - 175,
                                     self.monitor_resolution_y - 30,
                                     image=self.logo_image,
                                     anchor="c"))
        self.turn_counter_image.append(
            self.canvas.create_image(self.monitor_resolution_x - 75,
                                     self.monitor_resolution_y - 30,
                                     image=self.logo_image,
                                     anchor="c"))