Пример #1
0
def choose_opponent(request):
    roach = Roach.for_user(request.user)
    if roach.power < (roach.level.max_power / 2):
        error = u"Ты ещё не отошел от предыдущей гонки."
        return render(request, 'roaches/main.html', {
            'error': error,
            'roach': roach
        })
    elif roach.status == 0:
        roaches = Roach.objects.available().exclude(pk=roach)
        opponent = roaches[random.randint(0, len(roaches) - 1)]
        return render(request, 'roaches/race_manager.html', {
            'opponent': opponent,
            'roach': roach
        })
    else:
        temp = what_are_doing(roach)
        return render(
            request, 'roaches/main.html', {
                'error': temp[1]['mes'],
                'roach': roach,
                temp[1]['val']: True,
                'hours': temp[0]['hours'],
                'minutes': temp[0]['minutes'],
                'seconds': temp[0]['seconds']
            })
Пример #2
0
def create_race(request):
    if request.method == 'POST':
        roach_1 = Roach.for_user(request.user)
        roach_2 = Roach.objects.get(pk=request.POST['id'])
        race_id = clars(roach_1, roach_2)
        return view_race(request, race_id, roach_1.pk)
    return HttpResponseRedirect('index_game')
Пример #3
0
def view_stats(request, roach_id):
    roach = Roach.for_user(request.user)
    roaches = Roach.objects.order_by('-exp_all')[:5]
    return render(request, 'roaches/stat.html', {
        'roach': roach,
        'roaches': roaches
    })
Пример #4
0
def train(request, roach_id):
    roach = Roach.for_user(request.user)
    form = TrainingForm(request.POST or None)
    if roach.status == 0:
        if form.is_valid():
            hours = int(form.cleaned_data['hours'])
            if hours > 0:
                roach.status = 2
                roach.end_time_status = datetime.datetime.now(
                ) + datetime.timedelta(hours=hours)
                roach.temp_money = roach.level.price_for_work * hours
                roach.money_2 -= hours * roach.level.price_for_work / 2
                roach.save()
            return HttpResponseRedirect('index_game')
    else:
        temp = what_are_doing(roach)
        return render(
            request, 'main/main.html', {
                'error': temp[1]['mes'],
                'roach': roach,
                temp[1]['val']: True,
                'hours': temp[0]['hours'],
                'minutes': temp[0]['minutes'],
                'seconds': temp[0]['seconds']
            })
    return render(request, 'main/train.html', {'roach': roach, 'form': form})
Пример #5
0
def train(request, roach_id):
    roach = Roach.for_user(request.user)
    form = TrainingForm(request.POST or None)
    if roach.status == 0:
        if form.is_valid():
            hours = int(form.cleaned_data["hours"])
            if hours > 0:
                roach.status = 2
                roach.end_time_status = datetime.datetime.now() + datetime.timedelta(hours=hours)
                roach.temp_money = roach.level.price_for_work * hours
                roach.money_2 -= hours * roach.level.price_for_work / 2
                roach.save()
            return HttpResponseRedirect("index_game")
    else:
        temp = what_are_doing(roach)
        return render(
            request,
            "main/main.html",
            {
                "error": temp[1]["mes"],
                "roach": roach,
                temp[1]["val"]: True,
                "hours": temp[0]["hours"],
                "minutes": temp[0]["minutes"],
                "seconds": temp[0]["seconds"],
            },
        )
    return render(request, "main/train.html", {"roach": roach, "form": form})
Пример #6
0
def create_race(request):
    if request.method == "POST":
        roach_1 = Roach.for_user(request.user)
        roach_2 = Roach.objects.get(pk=request.POST["id"])
        race_id = clars(roach_1, roach_2)
        return view_race(request, race_id, roach_1.pk)
    return HttpResponseRedirect("index_game")
Пример #7
0
def train_abort(request, roach_id):
    """
    Отменяем тренеровку таракана, при этом
    начисляем таракану опыта в соответствии
    с проведенным на тренеровке вемени
    """
    roach = Roach.for_user(request.user)
    roach.status = 0
    time = roach.end_time_status
    d = time - datetime.datetime.now()
    hours = d.seconds / 3600 + 1
    koef = roach.temp_money / roach.level.price_for_work
    roach.exp_now += (koef - hours) * roach.level.price_for_work
    roach.temp_money = 0
    roach.save()
    return render(request, 'roaches/main.html', {'roach': roach})
Пример #8
0
def train_abort(request, roach_id):
    """
    Отменяем тренеровку таракана, при этом
    начисляем таракану опыта в соответствии
    с проведенным на тренеровке вемени
    """
    roach = Roach.for_user(request.user)
    roach.status = 0
    time = roach.end_time_status
    d = time - datetime.datetime.now()
    hours = d.seconds / 3600 + 1
    koef = roach.temp_money / roach.level.price_for_work
    roach.exp_now += (koef - hours) * roach.level.price_for_work
    roach.temp_money = 0
    roach.save()
    return render(request, "roaches/main.html", {"roach": roach})
Пример #9
0
def game(request):
    roach = Roach.for_user(request.user)
    roach.regenerate_roach()
    if roach.status == 1:
        time = roach.end_time_status
        if time < datetime.datetime.now():
            roach.status = 0
            roach.money_2 += roach.temp_money
            roach.temp_money = 0
            roach.save()
            return render(request, 'roaches/main.html', {'roach': roach})
        d = time - datetime.datetime.now()
        hours = d.seconds / 3600
        minutes = (d.seconds % 3600) / 60
        seconds = d.seconds - minutes * 60 - hours * 3600
        return render(
            request, 'roaches/main.html', {
                'roach': roach,
                'work': True,
                'hours': hours,
                'minutes': minutes,
                'seconds': seconds
            })

    elif roach.status == 2:
        time = roach.end_time_status
        if time < datetime.datetime.now():
            roach.status = 0
            roach.exp_now += roach.temp_money
            roach.temp_money = 0
            roach.save()
            return render(request, 'roaches/main.html', {'roach': roach})
        d = time - datetime.datetime.now()
        hours = d.seconds / 3600
        minutes = (d.seconds % 3600) / 60
        seconds = d.seconds - minutes * 60 - hours * 3600
        return render(
            request, 'roaches/main.html', {
                'roach': roach,
                'train': True,
                'hours': hours,
                'minutes': minutes,
                'seconds': seconds
            })
    return render(request, 'roaches/main.html', {'roach': roach})
Пример #10
0
def game(request):
    roach = Roach.for_user(request.user)
    roach.regenerate_roach()
    if roach.status == 1:
        time = roach.end_time_status
        if time < datetime.datetime.now():
            roach.status = 0
            roach.money_2 += roach.temp_money
            roach.temp_money = 0
            roach.save()
            return render(request, "roaches/main.html", {"roach": roach})
        d = time - datetime.datetime.now()
        hours = d.seconds / 3600
        minutes = (d.seconds % 3600) / 60
        seconds = d.seconds - minutes * 60 - hours * 3600
        return render(
            request,
            "roaches/main.html",
            {"roach": roach, "work": True, "hours": hours, "minutes": minutes, "seconds": seconds},
        )

    elif roach.status == 2:
        time = roach.end_time_status
        if time < datetime.datetime.now():
            roach.status = 0
            roach.exp_now += roach.temp_money
            roach.temp_money = 0
            roach.save()
            return render(request, "roaches/main.html", {"roach": roach})
        d = time - datetime.datetime.now()
        hours = d.seconds / 3600
        minutes = (d.seconds % 3600) / 60
        seconds = d.seconds - minutes * 60 - hours * 3600
        return render(
            request,
            "roaches/main.html",
            {"roach": roach, "train": True, "hours": hours, "minutes": minutes, "seconds": seconds},
        )
    return render(request, "roaches/main.html", {"roach": roach})
Пример #11
0
def choose_opponent(request):
    roach = Roach.for_user(request.user)
    if roach.power < (roach.level.max_power / 2):
        error = u"Ты ещё не отошел от предыдущей гонки."
        return render(request, "roaches/main.html", {"error": error, "roach": roach})
    elif roach.status == 0:
        roaches = Roach.objects.available().exclude(pk=roach)
        opponent = roaches[random.randint(0, len(roaches) - 1)]
        return render(request, "roaches/race_manager.html", {"opponent": opponent, "roach": roach})
    else:
        temp = what_are_doing(roach)
        return render(
            request,
            "roaches/main.html",
            {
                "error": temp[1]["mes"],
                "roach": roach,
                temp[1]["val"]: True,
                "hours": temp[0]["hours"],
                "minutes": temp[0]["minutes"],
                "seconds": temp[0]["seconds"],
            },
        )
Пример #12
0
def evolution(request, roach_id):
    roach = Roach.for_user(request.user)
    return render(request, 'roaches/evolution.html', {'roach': roach})
Пример #13
0
def evolution(request, roach_id):
    roach = Roach.for_user(request.user)
    return render(request, "roaches/evolution.html", {"roach": roach})
Пример #14
0
def view_stats(request, roach_id):
    roach = Roach.for_user(request.user)
    roaches = Roach.objects.order_by("-exp_all")[:5]
    return render(request, "roaches/stat.html", {"roach": roach, "roaches": roaches})