Browse Source

(Sep 2021) Add team randomisation + name-specifics

This is for Worms Armageddon, we're making up random teams for that

Special case handling for "missgingeramy" treated as "amy"
sep-2021
bertieb 3 years ago
parent
commit
70b89273f6
1 changed files with 44 additions and 16 deletions
  1. +44
    -16
      teampicker.py

+ 44
- 16
teampicker.py View File

@@ -138,7 +138,23 @@ class Highlighter(object):
if self.iterations >= self.max: if self.iterations >= self.max:
# Choosing time # Choosing time
self.lastchoice = -1 self.lastchoice = -1
TEAMS[-1].choose()
# # ** Name-specific choices! ** # #
for tsub in SUBS:
if tsub.team == "":
choosing_sub = tsub
break
for j in range(len(TEAMS)):
if "amy" not in choosing_sub.sub:
if TEAMS[j].team.lower(
).startswith(choosing_sub.sub[0].lower()):
TEAMS[j].choose()
break
else:
if TEAMS[j].team.lower().startswith("a"):
TEAMS[j].choose()
break
# # End Name-specific stuff # #
# TEAMS[-1].choose()
pygame.time.set_timer(HIGHLIGHTEVENT, 0) # Disable highlight pygame.time.set_timer(HIGHLIGHTEVENT, 0) # Disable highlight
pygame.time.set_timer(CHOOSEEVENT, 5000, True) # make choice pygame.time.set_timer(CHOOSEEVENT, 5000, True) # make choice
self.iterations = 0 self.iterations = 0
@@ -152,21 +168,27 @@ def draw_text(text, font, text_col, x, y):
screen.blit(img, (x, y)) screen.blit(img, (x, y))




def setup_team_board():
def setup_team_board(randomise_teams=False):
"""Grab teams from text file and set their positions""" """Grab teams from text file and set their positions"""
teamlist = []

with open(TEAMSFILE, "r") as fh: with open(TEAMSFILE, "r") as fh:
for row in range(TEAMNUMROWS):
for col in range(TEAMNUMCOLS):
name = fh.readline().strip()
if name == "":
continue
if "donkey" in name:
name = name.split(' ', 1)[1]
print("Adding {} at {},{}".format(name,
TEAMCOLS[col],
TEAMROWS[row]))
TEAMS.append(Team(name,
TEAMROWS[row], TEAMCOLS[col]))
teams = fh.readlines()
teamlist = [team.rstrip() for team in teams if team != ""]

if randomise_teams:
random.shuffle(teamlist)

for row in range(TEAMNUMROWS):
for col in range(TEAMNUMCOLS):
if len(teamlist) == 0:
continue
name = teamlist.pop(0)
print("Adding {} at {},{}".format(name,
TEAMCOLS[col],
TEAMROWS[row]))
TEAMS.append(Team(name,
TEAMROWS[row], TEAMCOLS[col]))




def setup_subs(): def setup_subs():
@@ -184,7 +206,7 @@ for line in open(SUBSFILE, "r"):
print(SUBS) print(SUBS)


random.shuffle(SUBS) random.shuffle(SUBS)
setup_team_board()
setup_team_board(randomise_teams=True)
random.shuffle(TEAMS) random.shuffle(TEAMS)
setup_subs() setup_subs()


@@ -223,7 +245,13 @@ while True:
elif event.type == CHOOSEEVENT: elif event.type == CHOOSEEVENT:
for sub in SUBS: for sub in SUBS:
if sub.team == "": if sub.team == "":
sub.team = TEAMS.pop().team
# # Name-specific again # #
for k in range(len(TEAMS)):
if TEAMS[k].colour == RED:
sub.team = TEAMS.pop(k).team
break
# # End name-specific # #
# sub.team = TEAMS.pop().team
pygame.time.set_timer(CLEAREVENT, 100, True) pygame.time.set_timer(CLEAREVENT, 100, True)
break break




Loading…
Cancel
Save