示例#1
0
def create_match():
    # Make the users, if necessary
    for username in ('alice', 'bob'):
        try:
            User.objects.get(username=username)
        except User.DoesNotExist:
            User.objects.create_user(
                username=username,
                email='*****@*****.**',
                password=getpass('Password for '+username+': '))
    # Make teams
    human = Race.objects.get(singular='human')
    alice = User.objects.get(username='******')
    reavers = create_team(
        'Reikland Reavers', human, alice,
        color_home_primary='31,120,180', color_home_secondary='51,160,44',
        color_away_primary='227,26,28', color_away_secondary='51,160,44',
    )
    reavers.save()
    populate_humans(reavers)
    orc = Race.objects.get(singular='orc')
    bob = User.objects.get(username='******')
    raiders = create_team(
        'Orcland Raiders', orc, bob,
        color_home_primary='31,120,180', color_home_secondary='51,160,44',
        color_away_primary='227,26,28', color_away_secondary='51,160,44',
    )
    raiders.save()
    populate_orcs(raiders)
    match = start_match(reavers, raiders)
    return match
示例#2
0
文件: views.py 项目: james-allen/bowl
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)