Beispiel #1
0
def save_f(request):
    s = game.slot()
    d = game.data_game()
    d.load_state()

    if request.method == "POST":
        if 'up' in request.POST:
            s.minus()
        elif 'down' in request.POST:
            s.plus()
        return HttpResponseRedirect(request.path)
    if request.method == "GET":
        if 'slot' in request.GET:
            d.save_game(s.slot_place)

    slots = some_func.get_slots(settings.SAVE_FILES)

    return render(
        request, "save.html", {
            "slot_place":
            s.slot_place,
            "slotA":
            slots['a'],
            "slotB":
            slots['b'],
            "slotC":
            slots['c'],
            "save_link":
            "http://127.0.0.1:8000/options/save_game/?slot={}".format(
                s.slot_place),
            "options_link":
            "http://127.0.0.1:8000/options"
        })
Beispiel #2
0
def load_f(request):
    s = game.slot()
    d = game.data_game()
    a_link = "http://127.0.0.1:8000/options/load_game/?slot={}".format(
        s.slot_place)
    slots = some_func.get_slots(settings.SAVE_FILES)
    slots_name = some_func.get_val_slots(settings.SAVE_FILES)
    a_text = "A - Load"
    if slots_name[list(['a', 'b', 'c'])[s.slot_place]] == None:
        a_link = '#'
    if request.method == "POST":
        if 'up' in request.POST:
            s.minus()
        elif 'down' in request.POST:
            s.plus()
        return HttpResponseRedirect(request.path)
    if request.method == "GET":
        if 'slot' in request.GET and not slots_name[list(
            ['a', 'b', 'c'])[s.slot_place]] == None:
            d.load_game(slots_name[list(['a', 'b', 'c'])[s.slot_place]])
            a_link = "http://127.0.0.1:8000/worldmap"
            a_text = "A - START GAME"

    return render(
        request, "load.html", {
            "slot_place": s.slot_place,
            "slotA": slots['a'],
            "slotB": slots['b'],
            "slotC": slots['c'],
            "load_link": a_link,
            "worldmap_link": "http://127.0.0.1:8000/",
            'a_text': a_text
        })
Beispiel #3
0
def moviedex_f(request):
    d = game.data_game()
    d.load_state()

    selector = game.Selector()
    if len(d.data['moviedex']):

        if request.method == "POST":
            if 'left' in request.POST:
                selector.minus(d.data)
            elif 'right' in request.POST:
                selector.plus(d.data)
        else:
            selector.reset(d.data)
        detail_link = 'http://127.0.0.1:8000/moviedex/' + selector.slot_place + '/'
    else:
        selector.slot_place = ""
        detail_link = '#'
    return render(
        request, "moviedex.html", {
            'movie_list': d.data['list_moviemon'],
            'moviedex': d.data['moviedex'],
            'selector_pos': selector.slot_place,
            'detail_link': detail_link,
            'len_moviedex': len(d.data['moviedex']),
            'worldmap_link': 'http://127.0.0.1:8000/worldmap/'
        })
Beispiel #4
0
def details_f(request, moviemon_id):
    d = game.data_game()
    d.load_state()
    #search for the moviemon in the total list.
    movie = d.get_movie(moviemon_id)
    if movie is not None:
        return render(request, "details.html", {'movie': movie})
    #If the moviemon is not found, raise 404.
    raise Http404()
Beispiel #5
0
def wordmap_f(request):
    d = game.data_game()
    events = ['', '', '#']

    if request.method == "POST":
        d.load_state()
        if 'up' in request.POST:
            d.data['position'][1] -= 1
        elif 'down' in request.POST:
            d.data['position'][1] += 1
        elif 'left' in request.POST:
            d.data['position'][0] -= 1
        elif 'right' in request.POST:
            d.data['position'][0] += 1
        else:
            raise Http404()
        if d.checkpos():
            events = d.try_random_events()
            d.save_state()
            return HttpResponseRedirect(
                request.path + "?events={}+{}".format(events[0], events[1]))
        d.save_state()
        return HttpResponseRedirect(request.path)
    else:
        if 'start' in request.GET:
            d.load_default_settings()
        elif 'events' in request.GET:
            d.load_state()
            movieball = request.GET['events'].split(' ')[0]
            moviemon = request.GET['events'].split(' ')[1]
            events = d.transform_events(movieball, moviemon)
        else:
            d.load_state()
    d.save_state()
    return render(
        request, "worldmap.html", {
            'mapx': range(settings.GRID_SIZE),
            'mapy': range(settings.GRID_SIZE),
            'persox': d.data['position'][0],
            'persoy': d.data['position'][1],
            'balls_number': d.data['nbr_movieball'],
            'ballfindstring': events[0],
            'moviefindstring': events[1],
            'battle_link': events[2],
            'options': 'http://127.0.0.1:8000/options/',
            'moviedex_link': 'http://127.0.0.1:8000/moviedex/'
        })
Beispiel #6
0
def battle_f(request, moviemon_id):
    d = game.data_game()
    d.load_state()
    movie = d.get_movie(moviemon_id)
    player_strength = d.get_strength()
    movieball_link = 'http://127.0.0.1:8000/battle/{}?try_capture=True'.format(
        moviemon_id)
    success_proba = 50 - (float(movie['rating']) * 10) + (player_strength * 5)
    if success_proba < 1:
        success_proba = 1
    elif success_proba > 90:
        success_proba = 90
    # mettre un get ici pour avoir les parametres du combat
    captured = False
    missed = False
    if request.method == "GET":
        if 'try_capture' in request.GET:
            if d.data['nbr_movieball'] > 0:
                d.data['nbr_movieball'] -= 1
                jet = random.randint(1, 100)
                if int(success_proba) >= jet:
                    captured = True
                    movieball_link = '#'
                    d.data['moviedex'].append(moviemon_id)
                else:
                    missed = True
            d.save_state()
    if d.capturable == moviemon_id:
        return render(
            request, "battle.html", {
                'poster': movie['poster'],
                'balls_number': d.data['nbr_movieball'],
                'player_strength': player_strength,
                'success_proba': success_proba,
                'captured': captured,
                'missed': missed,
                'movieball_toss_link': movieball_link,
                'worldmap_link': 'http://127.0.0.1:8000/worldmap',
                'moviemon_strength': movie['rating']
            })
    else:
        raise Http404()