Пример #1
0
def loadgame(request):
    context = RequestContext(request)

    mygame = Game()

    loaded_data = mygame.unpickleData()

    context_dict = {"moves":loaded_data["moves"],"food":loaded_data["food"],"ammo":loaded_data["ammo"],"survivors":loaded_data["survivors"],"atHouse":loaded_data["atHouse"],"dayno":loaded_data["dayno"], "maxfood":loaded_data["maxfood"], "maxsurvivors":loaded_data["maxsurvivors"]}



    return render_to_response('game/gamescreen.html', context_dict, context)
Пример #2
0
def gamescreen(request):
    context = RequestContext(request)

    mygame = Game()
    context_dict = {'test': "test"}
    if 'House1' in request.POST:
        mygame.selectHouse(0)
    if 'House2' in request.POST:
        mygame.selectHouse(1)
    if 'House3' in request.POST:
        mygame.selectHouse(2)
    if 'House4' in request.POST:
        mygame.selectHouse(3)
    if 'House5' in request.POST:
        mygame.selectHouse(4)
    prevMoves = int(request.POST.get("prevMoves") or 8)
    prevAmmo = int(request.POST.get("prevAmmo") or 0)
    prevSurvivors = int(request.POST.get("prevSurvivors") or 3)
    prevFood = int(request.POST.get("prevFood") or 0)
    currentHouse = int(request.POST.get("curHouse") or -1)
    currentDay = int(request.POST.get("dayno") or 0)
    maxSurvivors = int(request.POST.get("maxSurvivors") or -1)
    maxFood = int(request.POST.get("maxFood") or 0)
    mygame.updateData(prevMoves, prevFood, prevAmmo, prevSurvivors, currentHouse,currentDay, maxFood, maxSurvivors)
    mygame.inspectHouse()
    gameData = mygame.report()
    context_dict['survivors'] = gameData[0]
    context_dict['food'] = gameData[1]
    context_dict['ammo'] = gameData[2]
    context_dict['moves'] = gameData[3]
    context_dict['curHouse'] = gameData[4]
    context_dict['dayno'] = gameData[5]
    context_dict['maxFood'] = gameData[6]
    context_dict['maxSurvivors'] = gameData[7]
    if gameData[0] <= 0:
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'go_scavenge_project.settings')

        profile = request.user.get_profile()

        if Stat.objects.filter(user=profile.user).count()==0:
            Stat.objects.get_or_create(user=profile.user, longest_session=gameData[5], max_survivors=gameData[7], supplies=gameData[6])
        else:
            s = Stat.objects.get(user=profile.user)
            if gameData[5] > s.longest_session:
                s.longest_session = gameData[5]
                s.max_survivors = gameData[7]
                s.supplies = gameData[6]
                s.save()



        return render_to_response('game/gameover.html', context_dict, context)
    return render_to_response('game/gamescreen.html',context_dict, context)