def populate_orcs(team): positions = { 'Lineman': 2, 'Thrower': 1, 'Black Orc Blocker': 4, 'Blitzer': 4, } number = 1 for position_title, quantity in positions.items(): for _ in range(quantity): create_player( team, position_title, 'Orc player ' + str(number), number).save() number += 1 team.rerolls = 3 team.cash = 10 team.save()
def populate_humans(team): positions = { 'Lineman': 5, 'Thrower': 1, 'Blitzer': 2, 'Catcher': 2, 'Ogre': 1, } number = 1 for position_title, quantity in positions.items(): for _ in range(quantity): create_player( team, position_title, 'Human player ' + str(number), number).save() number += 1 team.rerolls = 4 team.cash = 20 team.save()
def create_team_view(request): if request.method == 'POST': team_dict = { 'players': [], 'name': request.POST['team_name'], 'race': request.POST['race'], 'rerolls': int(request.POST['rerolls']), 'color_home_primary': request.POST['colorHomePrimary'], 'color_home_secondary': request.POST['colorHomeSecondary'], 'color_away_primary': request.POST['colorAwayPrimary'], 'color_away_secondary': request.POST['colorAwaySecondary'], } for i in range(1, 17): name = request.POST['name'+str(i)] position = request.POST['position'+str(i)] if name and position: team_dict['players'].append({ 'number': i, 'name': name, 'position': position }) race = Race.objects.get(singular=team_dict['race']) team = create_team( team_dict['name'], race, request.user, rerolls=team_dict['rerolls'], color_home_primary=team_dict['color_home_primary'], color_home_secondary=team_dict['color_home_secondary'], color_away_primary=team_dict['color_away_primary'], color_away_secondary=team_dict['color_away_secondary'], ) team.save() for player in team_dict['players']: create_player( team, player['position'], player['name'], player['number'] ).save() team.update_value() team.cash = 1000 - team.value team.update_value() if team.valid_starting_team(): team.save() url = reverse('game:team_view', kwargs={'team_slug': team.slug}) return HttpResponseRedirect(url) else: for player in team.player_set.all(): player.delete() team.delete() colors = [ '31,120,180', '51,160,44', '227,26,28', '255,127,0', '106,61,154', '177,89,40' ] data = { 'number_range': range(1, 17), 'race_list': Race.objects.all(), 'username': request.user.username, 'colors': colors, } return render(request, 'game/create-team.html', data)