Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # purpose: draft_menu creates an instance of the standard draft menu. It
- # contains internal functions to create and modify pokemon lists.
- def draft_menu():
- # create the popup menu
- d_m = Toplevel()
- d_m.resizable(False, False)
- # initialize the state of each pool pokemon (True = unpicked)
- draft_menu.pokemon_state = [True for i in range(15)]
- # initialize the state of drafting (False = unfinished)
- draft_menu.donebool = False
- # purpose: undo_action will remove the most recent pokemon added. The var x
- # contains the position of the most recent pokemon to undo and the
- # var y identifies which team it is on.
- def undo_action(x, y):
- # remove pokemon info from lists (y is team 1 or team 2)
- for i in range(15):
- generate_draft.pokemon_list[y][i].pop()
- # revert icon from picked unpicked
- reverted_img = PhotoImage(file=poke_icon(generate_draft.pokemon_list[2][1], generate_draft.pokemon_list[2][2], x))
- current_img = PhotoImage(file='img\\current_mystery_pokemon_icon.gif')
- mystery_img = PhotoImage(file='img\\mystery_pokemon_icon.gif')
- pool_pokemon[x].config(image=reverted_img)
- pool_pokemon[x].image = reverted_img
- # allow the pokemon to be picked again in the pool
- draft_menu.pokemon_state[x] = True
- # loop through pokemon 1 ~ 6 on each team
- for i in range(1, 13):
- # find the current pokemon
- if generate_draft.most_recent_pokemon2 == i:
- # i is odd = remove from team 1
- if i % 2 == 1:
- # revert the pokemon icon and current team icon
- team_pokemon[y][i/2].config(image=current_img)
- team_pokemon[y][i/2].image = current_img
- team_pokemon[y+1][i/2].config(image=mystery_img)
- team_pokemon[y+1][i/2].image = mystery_img
- # i is even = remove from team 2
- else:
- # revert the pokemon icon and current team icon
- team_pokemon[y][(i-1)/2].config(image=current_img)
- team_pokemon[y][(i-1)/2].image = current_img
- if i < 12:
- # apply only to pokemon 1 ~ 5 (i/2 = 6 out of bounds)
- team_pokemon[y-1][i/2].config(image=mystery_img)
- team_pokemon[y-1][i/2].image = mystery_img
- else:
- # revert drafting and showdown button states
- draft_menu.donebool = False
- showdown2_img = PhotoImage(file='img\\showdown_unavailable.gif')
- showdown_button.config(image=showdown2_img, command=lambda: None)
- showdown_button.image = showdown2_img
- main.draft_session_counter -= 1
- # remove pokemon from recent lists
- generate_draft.most_recent_pokemon2 -= 1
- generate_draft.most_recent_pokemon.pop()
- # check if there are no more actions to undo
- if (generate_draft.most_recent_pokemon2) == 0:
- # revert undo button state
- undo_img = PhotoImage(file='img\\undo_button_unavailable.gif')
- undo_button.config(image=undo_img, command=lambda: None)
- undo_button.image = undo_img
- else:
- # change undo button to remove the next pokemon in most recent list
- undo_button.config(command=lambda: undo_action(generate_draft.most_recent_pokemon[-1], ((y+1)%2)))
- # purpose: update_pool_pokemon handles the selection process of the draft.
- # The var x is the position of the pool pokemon.
- def update_pool_pokemon(x):
- # check if the selected pokemon is unpicked
- if draft_menu.pokemon_state[x]:
- # make the pokemon at position x picked
- draft_menu.pokemon_state[x] = False
- print draft_menu.pokemon_state
- # retrieve the corresponding pokemon icon
- new_img = PhotoImage(file=poke_icon(generate_draft.pokemon_list[2][1], generate_draft.pokemon_list[2][2], x))
- next_img = PhotoImage(file='img\\current_mystery_pokemon_icon.gif')
- # check if drafting is not finished, otherwise do nothing
- if draft_menu.donebool == False:
- # change the pokemon icon in the pool from unpicked to picked
- picked_img = PhotoImage(file=poke_icon_picked(generate_draft.pokemon_list[2][1], generate_draft.pokemon_list[2][2], x))
- pool_pokemon[x].config(image=picked_img)
- pool_pokemon[x].image = picked_img
- # check if current pokemon is not final pokemon
- y = generate_draft.most_recent_pokemon2
- if 0 <= y <= 10:
- # loop through pokemon 1 ~ 11
- for i in range(0, 11):
- # find the current pokemon
- if y == i:
- # check if currently adding to team 1
- if y % 2 == 0:
- print "adding to team 1..."
- print "CURRENT: [y%2][i/2] = [" + str(y%2) + "][" + str(i/2) + "]"
- print "NEXT: [(y+1)%2][i/2] = [" + str((y+1)%2) + "][" + str(i/2) + "]"
- # modify team 1 pokemon icons
- team_pokemon[y%2][i/2].config(image=new_img)
- team_pokemon[y%2][i/2].image = new_img
- team_pokemon[(y+1)%2][i/2].config(image=next_img)
- team_pokemon[(y+1)%2][i/2].image = next_img
- # check if currently the first pokemon
- if y == 0:
- # activate the undo button
- undo_button_img2 = PhotoImage(file='img\\undo_button.gif')
- undo_button.config(image=undo_button_img2, command=lambda: undo_action(generate_draft.most_recent_pokemon[0], 0))
- undo_button.image = undo_button_img2
- else:
- # modify the undo button
- undo_button.config(command=lambda: undo_action(generate_draft.most_recent_pokemon[-1], 0))
- # check if currently adding to team 2
- else:
- print "adding to team 2..."
- print "CURRENT: [y%2][i/2] = [" + str((y-1)%2) + "][" + str(i/2) + "]"
- print "NEXT: [(y+1)%2][(i+1)/2] = [" + str(y%2) + "][" + str((i+1)/2) + "]"
- # modify team 2 pokemon icons and the undo button
- team_pokemon[y%2][i/2].config(image=new_img)
- team_pokemon[y%2][i/2].image = new_img
- team_pokemon[(y+1)%2][(i+1)/2].config(image=next_img)
- team_pokemon[(y+1)%2][(i+1)/2].image = next_img
- undo_button.config(command=lambda: undo_action(generate_draft.most_recent_pokemon[-1], 1))
- else:
- # modify team 2 pokemon 6 icon and the undo button
- team_pokemon[1][5].config(image=new_img)
- team_pokemon[1][5].image = new_img
- # modify the undo button and change draft state to finished
- undo_button.config(command=lambda: undo_action(generate_draft.most_recent_pokemon[-1], 1))
- draft_menu.donebool = True
- # activate the showdown button
- showdown2_img = PhotoImage(file='img\\showdown.gif')
- showdown_button.config(image=showdown2_img, command=draft_showdown)
- showdown_button.image = showdown2_img
- main.draft_session_counter += 1
- # add selected pokemon to list of actions and respective team
- generate_draft.most_recent_pokemon2 +=1
- # add the pokemon information to each list
- for i in range(15):
- generate_draft.pokemon_list[generate_draft.most_recent_pokemon2%2][i].append(generate_draft.pokemon_list[2][i][x])
- # keep track of the pokemon just added
- generate_draft.most_recent_pokemon.append(x)
- # purpose: generate_draft will generate a new pool of pokemon and start
- # the draft. Calling this function again will reset the draft.
- def generate_draft():
- # initialize 3 sets of lists of pokemon
- generate_draft.pokemon_list = [[[] for i in range(15)] for j in range(3)]
- # initialize a list and counter that will keep track of the picks
- generate_draft.most_recent_pokemon = []
- generate_draft.most_recent_pokemon2 = 0
- # initialize a counter that will keep track of the generated pokemon
- generate_counter = 0
- # open the csv file and read the database information
- with open('database\\main_database.csv', 'r') as fileName:
- reader = csv.reader(fileName)
- # generate at least 15 pokemon
- while (generate_counter < 15):
- # pick a random ID
- newID = randint(2,dblen)
- # check if ID is already picked, otherwise do nothing
- if newID not in generate_draft.pokemon_list[2][0]:
- # add new ID to list of picked IDs
- generate_draft.pokemon_list[2][0].append(newID)
- # loop through each row in the database
- for row in reader:
- # check if the current row's ID matches the random ID
- if int(row[0]) == newID:
- # check if the current species is already picked
- if row[2] in generate_draft.pokemon_list[2][2]:
- # remove the duplicate species
- generate_draft.pokemon_list[2][0].remove(newID)
- else:
- # add the new pokemon to the pool (list 3)
- for i in range (1,15):
- generate_draft.pokemon_list[2][i].append(row[i])
- generate_counter += 1
- # return to the beginning of the file
- fileName.seek(0)
- # reset the icons for the pool of pokemon
- pool_pokemon_img = [None for i in range(15)]
- for i in range(15):
- pool_pokemon_img[i] = PhotoImage(file=poke_icon(generate_draft.pokemon_list[2][1], generate_draft.pokemon_list[2][2], i))
- pool_pokemon[i].config(image=pool_pokemon_img[i], command=lambda i=i: update_pool_pokemon(i))
- pool_pokemon[i].image = pool_pokemon_img[i]
- # reset the icons for both teams
- reset_teams_img = PhotoImage(file='img\\mystery_pokemon_icon.gif')
- current_pokemon_img = PhotoImage(file='img\\current_mystery_pokemon_icon.gif')
- for i in range(2):
- for j in range(6):
- if i == 0 and j == 0:
- team_pokemon[i][j].config(image=current_pokemon_img)
- team_pokemon[i][j].image = current_pokemon_img
- else:
- team_pokemon[i][j].config(image=reset_teams_img)
- team_pokemon[i][j].image = reset_teams_img
- # reset the pool pokemon pick states
- for i in range(15):
- draft_menu.pokemon_state[i] = True
- # reset state of drafting and deactivate showdown button
- draft_menu.donebool = False
- showdown_img = PhotoImage(file='img\\showdown_unavailable.gif')
- showdown_button.config(image=showdown_img, command=lambda: None)
- showdown_button.image = showdown_img
- # purpose: showdown will copy the showdown information for both teams to
- # the clipboard and create a log file of the current session.
- def draft_showdown():
- cboard = showdown("draft", main.draft_session_counter, 15, generate_draft.pokemon_list, 6)
- # copy team 1 and team 2 information to the clipboard
- d_m.clipboard_clear()
- d_m.clipboard_append(cboard)
- # initialize the draft type image at the top of the menu
- bar_img = PhotoImage(file='img\\draft_menu_bar.gif')
- mbar = Label(d_m, image=bar_img)
- mbar.image = bar_img
- mbar.pack()
- # initialize the 3-frame-layered (top-down) frame for the pool
- pool_frame = [None for i in range(3)]
- for i in range(3):
- pool_frame[i] = Frame(d_m)
- pool_frame[i].pack()
- # initialize the mystery icon for each pool pokemon (5 per row)
- mystery_img = PhotoImage(file='img\\mystery_pokemon_icon.gif')
- pool_pokemon = [None for i in range(15)]
- for i in range(15):
- if 0 <= i <= 4:
- pool_pokemon[i] = Button(pool_frame[0], image=mystery_img, bd=0.1)
- elif 5 <= i <= 9:
- pool_pokemon[i] = Button(pool_frame[1], image=mystery_img, bd=0.1)
- else:
- pool_pokemon[i] = Button(pool_frame[2], image=mystery_img, bd=0.1)
- pool_pokemon[i].image = mystery_img
- pool_pokemon[i].pack(side=LEFT, padx=5, pady=5)
- # initialize the team frames below the pool frame
- team_frame = [None for i in range(2)]
- for i in range(2):
- team_frame[i] = LabelFrame(d_m, text="TEAM " + str(i+1))
- team_frame[i].pack(padx=5, pady=10)
- # initialize the mystery icon for each pokemon (6 per team)
- team_pokemon = [[None for i in range(6)] for j in range(2)]
- for i in range(2):
- for j in range(6):
- team_pokemon[i][j] = Label(team_frame[i], image=mystery_img, bd=0.1)
- team_pokemon[i][j].image = mystery_img
- team_pokemon[i][j].pack(side=LEFT, padx=3, pady=5)
- # initialize the frame for the drafting buttons below the team frames
- buttonsframe = Frame(d_m)
- buttonsframe.pack(pady=10)
- # initialize the start button on the left side
- generate_img = PhotoImage(file='img\\generate.gif')
- generate_button = Button(buttonsframe, image=generate_img, bd=0.1, command=generate_draft)
- generate_button.image = generate_img
- generate_button.pack(side=LEFT, padx=7)
- # initialize the undo button in the middle
- undo_img = PhotoImage(file='img\\undo_button_unavailable.gif')
- undo_button = Button(buttonsframe, image=undo_img, bd=0.1, command=lambda: None)
- undo_button.image = undo_img
- undo_button.pack(side=LEFT)
- # initialize the showdown button on the right side
- showdown_img = PhotoImage(file='img\\showdown_unavailable.gif')
- showdown_button = Button(buttonsframe, image=showdown_img, bd=0.1, command=lambda: None)
- showdown_button.image = showdown_img
- showdown_button.pack(side=LEFT, padx=7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement