コード例 #1
0
    def get_composite_formation(self, formation_name):
        if not self.formations:
            raise ScoutCardMakerException('Formation Library Empty')

        formation_words = formation_name.strip().upper().split()

        #determine if going lt or rt
        direction = None
        if 'LT' in formation_words and 'RT' not in formation_words:
            direction = 'LT'
        elif 'LT' not in formation_words and 'RT' in formation_words:
            direction = 'RT'
        else:
            raise ScoutCardMakerException('Can\'t determine if going Lt or Rt from formation name: ' + formation_name)

        sub_formation_names = [word + ' ' + direction for word in formation_words if word != 'LT' and word != 'RT']

        #check that all sub_formations exist
        for sub_formation_name in sub_formation_names:
            if sub_formation_name not in self.formations:
                raise ScoutCardMakerException(sub_formation_name + ' doesn\'t exist in library. Create it.')

        formation = Formation()

        #copy all formations affects one at a time
        for sub_formation_name in sub_formation_names:
            formation.override_formation(self.formations[sub_formation_name])

        return formation
コード例 #2
0
    def get_formation(self, formation_name):
        if not self.formations:
            raise ScoutCardMakerException('Formation Library Empty')

        formation = Formation()
        formation.copy_formation_from_formation(self.formations[formation_name])
        return formation
コード例 #3
0
 def __init__(self):
     self.current_defense = get_default_defense()
     self.current_formation = Formation()
     self.formation_library = FormationLibrary()
     self.current_defender = self.current_defense.c
     self.defense_library = DefensiveLibrary()
     self.editor = None
コード例 #4
0
 def create_player_shapes_for_visualization(self):
     self.player_shapes = {}
     formation = Formation() #create default formation to place players around in
     for label, player in formation.players.items():
         x, y = player_coordinates_to_canvas(player.x, player.y)
         self.player_shapes[label] = {"Oval" : self.canvas.create_oval(x - PLAYER_WIDTH / 2, y - PLAYER_HEIGHT / 2, x + PLAYER_WIDTH / 2, y + PLAYER_HEIGHT / 2, fill="white"),
                                     "Text" : self.canvas.create_text(x, y, text=player.label, font=LABEL_FONT),
                                     "Label" : player.label}
コード例 #5
0
class FormationLibraryEditorController:
    def __init__(self):
        self.current_formation = Formation()
        self.formation_library = FormationLibrary()
        self.editor = None

    def update_player_in_formation(self, tag, x, y):
        self.current_formation.players[tag].x = x
        self.current_formation.players[tag].y = y

    def load_formation_from_library(self, formation_name):
        formation = self.formation_library.get_formation(formation_name)
        self.current_formation.copy_formation_from_formation(formation)

    def load_composite_formation_from_library(self, formation_name):
        formation = self.formation_library.get_composite_formation(formation_name)
        self.current_formation.copy_formation_from_formation(formation)

    def save_formation_to_library(self, formation_name, affected_player_tags):
        self.current_formation.affected_player_tags = affected_player_tags
        self.formation_library.add_formation_to_library(formation_name, self.current_formation)

    def delete_formation_from_library(self, formation_name):
        self.formation_library.delete_formation_from_library(formation_name)

    def new_library(self):
        self.formation_library = FormationLibrary()
        if self.editor:
            self.editor.refresh_library()

    def load_library(self, library_filename):
        self.formation_library.load_library(library_filename)
        if self.editor:
            self.editor.refresh_library()

    def save_library(self, library_filename):
        self.formation_library.save_library(library_filename)

    def print_player_positions(self):
        for key, player in self.current_formation.players.items():
            print("{} : {} , {}".format(player.label, player.x, player.y))
コード例 #6
0
    def add_formation_to_library(self, formation_name, formation):
        formation_words = formation_name.strip().upper().split()

        #automatically make direction right if they they don't specify it
        if len(formation_words) == 1:
            formation_words.append('RT')

        #Check that formation name has only two words
        if len(formation_words) != 2:
            raise ScoutCardMakerException("Formation names must be made up one word and a direction.")
        #check that the last word is either lt or rt
        if formation_words[1] != 'LT' and formation_words[1] != 'RT':
            raise ScoutCardMakerException('Name must end in LT or RT')

        #check that no other words are LT or RT
        if formation_words[0] == 'LT' or formation_words[0] == 'RT':
                raise ScoutCardMakerException('Name can\'t contain LT or RT except to specify direction')

        #construct formation name from the words
        modified_formation_name = ' '.join(formation_words)

        #construct a flipped formation name as well
        if formation_words[-1] == 'LT':
            formation_words[-1] =  'RT'
        else:
            formation_words[-1] = 'LT'

        flipped_modified_formation_name = ' '.join(formation_words)

        #create two formations and add them to the library
        formation_to_save = Formation()
        formation_to_save.copy_formation_from_formation(formation)
        flipped_formation_to_save = Formation()
        flipped_formation_to_save.copy_formation_from_formation(formation)
        flipped_formation_to_save.flip_formation()

        self.formations[modified_formation_name] = formation_to_save
        self.formations[flipped_modified_formation_name] = flipped_formation_to_save
コード例 #7
0
 def create_player_shapes_for_visualization(self):
     self.player_shapes = {}
     formation = Formation(
     )  #create default formation to place players around in
     for label, player in formation.players.items():
         x, y = player_coordinates_to_canvas(player.x, player.y)
         self.player_shapes[label] = {
             "Oval":
             self.canvas.create_oval(x - PLAYER_WIDTH / 2,
                                     y - PLAYER_HEIGHT / 2,
                                     x + PLAYER_WIDTH / 2,
                                     y + PLAYER_HEIGHT / 2,
                                     fill="white"),
             "Text":
             self.canvas.create_text(x,
                                     y,
                                     text=player.label,
                                     font=LABEL_FONT),
             "Label":
             player.label
         }
     defense = Defense(
     )  #create default formation to place defenders around in
     self.defender_shapes = {}
     for label, defender in defense.defenders.items():
         x, y = defender_coordinates_to_canvas(
             *defender.place_defender(formation))
         self.defender_shapes[label] = {
             'Text':
             self.canvas.create_text(x,
                                     y,
                                     text=defender.label,
                                     font=DEFENDER_FONT),
             'Label':
             player.label
         }
         self.defender_shapes[label]['Text']
コード例 #8
0
    def __init__(self, root, library):
        super(FormationLibraryEditor, self).__init__(root)
        self.current_formation = Formation()
        self.library = library

        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(1, weight=1)

        # Widgets to enter formation info
        formation_entry_frame = tk.Frame(self)
        formation_entry_frame.grid(row=0, column=0)
        tk.Label(formation_entry_frame, text='Formation Name:').pack()
        self.formation_name_entry = tk.Entry(formation_entry_frame)
        self.formation_name_entry.pack()
        self.save_formation_btn = tk.Button(formation_entry_frame, text='Save Formation', command=self.save_formation)
        self.formation_name_entry.bind('<Return>', self.save_formation)
        self.save_formation_btn.pack()

        # Widget for library
        formation_library_frame = tk.Frame(self)
        formation_library_frame.grid(row=1, column=0, sticky='NS')
        tk.Label(formation_library_frame, text='Formations').pack()
        self.delete_selected_btn = tk.Button(formation_library_frame, text='Delete Selected Formation', command=self.delete_selected_formation)
        self.delete_selected_btn.pack()
        library_scrollbar = tk.Scrollbar(formation_library_frame, orient=tk.VERTICAL)
        self.library_lb = tk.Listbox(formation_library_frame, yscrollcommand=library_scrollbar.set)
        library_scrollbar.config(command=self.library_lb.yview)
        library_scrollbar.pack(side=tk.RIGHT, fill=tk.Y, expand=True)
        self.library_lb.pack(side=tk.LEFT, fill=tk.Y, expand=True)
        self.library_lb.bind('<<ListboxSelect>>', lambda e:self.library_on_select(e))

        # Frame for formation editor
        self.formation_editor = FormationEditor(self, self.library, self.current_formation)
        self.formation_editor.grid(row=0, column=1, rowspan=2, sticky='NSEW')

        self.refresh_library_listbox()
コード例 #9
0
    def __init__(self, root, library, defense):
        super(DefensiveEditor, self).__init__(root)
        self.library = library
        self.current_defense = defense
        self.current_defender = self.current_defense.defenders['c']
        self.current_formation_variation = get_default_variation('mof')

        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(3, weight=1)

        # Widgets to display and load a composite offensive formation or composite defense
        load_composite_frame = tk.Frame(self)
        load_composite_frame.grid(row=0, column=0, sticky='W')
        tk.Label(load_composite_frame, text='Offensive Formation:').pack()
        self.offensive_formation_entry = tk.Entry(load_composite_frame)
        self.offensive_formation_entry.pack()
        self.get_offensive_formation_btn = tk.Button(
            load_composite_frame,
            text='Get Offensive Formation',
            command=self.get_offensive_formation)
        self.get_offensive_formation_btn.pack()
        self.offensive_formation_entry.bind('<Return>',
                                            self.get_offensive_formation)

        tk.Label(load_composite_frame, text='Hash:').pack()
        self.offense_ball_placement_value = tk.StringVar()
        self.offense_ball_placement_value.set('m')
        tk.Radiobutton(load_composite_frame,
                       text='M',
                       value='m',
                       variable=self.offense_ball_placement_value).pack()
        tk.Radiobutton(load_composite_frame,
                       text='L',
                       value='l',
                       variable=self.offense_ball_placement_value).pack()
        tk.Radiobutton(load_composite_frame,
                       text='R',
                       value='r',
                       variable=self.offense_ball_placement_value).pack()

        tk.Label(load_composite_frame, text='Composite Defense:').pack()
        self.composite_defense_entry = tk.Entry(load_composite_frame)
        self.composite_defense_entry.pack()
        self.get_composite_defense_btn = tk.Button(
            load_composite_frame,
            text='Get Composite Defense',
            command=self.get_composite_defense)
        self.get_composite_defense_btn.pack()
        self.composite_defense_entry.bind('<Return>',
                                          self.get_composite_defense)

        # Widgets for modifying affected defenders
        affected_defenders_frame = tk.Frame(self)
        affected_defenders_frame.grid(row=0, column=1, sticky='W')
        tk.Label(affected_defenders_frame,
                 text='Affected Defenders').grid(row=0, column=0, columnspan=3)
        self.affected_defender_cb_values = {}
        for i, defender_tag in zip(
                list(range(11)),
            ['t', 'n', 'a', 'p', 'w', 'm', 'b', 's', 'c', 'f', 'q']):
            self.affected_defender_cb_values[defender_tag] = tk.BooleanVar()
            tk.Checkbutton(
                affected_defenders_frame,
                text=defender_tag.upper(),
                variable=self.affected_defender_cb_values[defender_tag],
                command=self.checked_affected_defenders_box).grid(
                    row=(i % 5) + 1, column=i // 5)

        self.set_affected_defender_checkboxes()

        defender_select_frame = tk.Frame(self)
        defender_select_frame.grid(row=0, column=2, sticky='E')

        # Widgets for selecting defender
        tk.Label(defender_select_frame,
                 text='Current Defender: ').grid(row=0, column=0, sticky='E')
        defender_names = [
            'T', 'N', 'A', 'P', 'W', 'M', 'B', 'S', 'C', 'F', 'Q'
        ]
        self.current_defender_value = tk.StringVar()
        self.current_defender_value.set(self.current_defender.label)
        self.current_defender_om = tk.OptionMenu(defender_select_frame,
                                                 self.current_defender_value,
                                                 *defender_names,
                                                 command=self.change_defender)
        self.current_defender_om.grid(row=0, column=1, sticky='WE')

        # Widgets to visualize the defense and formation
        formation = Formation()
        self.visualizer = AlignmentVisualizer(
            self, formation_to_visualizer(formation, 'mof'), None)
        self.visualizer.grid(row=1, column=0, columnspan=4, sticky='NSEW')

        # Widgets for condition placements
        self.condition_placement_frame = None
        self.change_placement_rule_gui()
コード例 #10
0
 def __init__(self):
     self.current_formation = Formation()
     self.formation_library = FormationLibrary()
     self.editor = None