示例#1
0
def load_game(state_data):
    g = Game()

    g.player_state = pickle.loads(state_data.player_state)
    g.update_state = pickle.loads(state_data.update_state)
    g.street = pickle.loads(state_data.street_state)
    g.game_state = state_data.game_state
    g.update_time_left(100-(int(state_data.time_left)))

    return g
示例#2
0
def game(request):
    g=Game()
    t=''
    player = request.user.userprofile
    #Can initialise these using player state !!??
    pps = pickle.dumps(g.player_state)
    kills = 0
    days = 0
    food = 3
    ammo = 2
    people = 1
    g.player_state = pickle.loads(pps)


    context_dict = {'player':player, 'game_over':False, 'new_day':False, 'kills':kills, 'food':food, 'days':days, 'ammo': ammo, 'party': people,
                    'player_state': g.player_state }

    if g.is_game_over():
        context_dict['game_over'] = True
    else:
        g.start_new_day()

    if g.is_day_over():
        g.end_day()
        g.start_new_day()

    if context_dict['game_over'] == False and context_dict['new_day'] == False:
        if t == 'MOVE':
            g.take_turn('MOVE')
        elif t == ('ENTER'):
            g.take_turn('ENTER')
        elif t == ('WAIT'):
            g.take_turn('WAIT')
        elif t == ('FIGHT'):
            g.take_turn('FIGHT')
        elif t == ('SEARCH'):
            g.take_turn('SEARCH')
        elif t == ('EXIT'):
            g.take_turn('EXIT')
        elif t ==('RUN'):
            g.take_turn('RUN')

        context_dict = fill_dict(g)
        context_dict['state'] = str(g.player_state)
        context_dict['gstate'] = g.game_state
        context_dict['time'] = g.time_left

    if g.is_game_over():
        context_dict={'game_over':True}
    elif g.is_day_over():
        context_dict={'new_day':True}
        if g.update_state.party<0:
            print "You lost: {0} people".format(abs(g.update_state.party))

        elif g.update_state.party>0:
            print "{0} more people have joined your party".format(g.update_state.party)

        elif g.update_state.ammo > 0:
            print "You found: {0} units of ammo".format(g.update_state.ammo)

        elif g.update_state.ammo < 0:
            print "You used: {0} units of ammo".format(abs(g.update_state.ammo))

        elif g.update_state.food > 0:
            print "You found: {0} units of food".format(g.update_state.food)

        elif g.update_state.food < 0:
            print "You used: {0} units of food".format(abs(g.update_state.food))

        elif g.update_state.kills > 0:
            print "You killed: {0} zombies".format(g.update_state.kills)

        elif g.update_state.days > 0:
            print "New Day: You survived another day!"
    #Put these updates into a dictionary Q pickle ?

    return render(request, 'zombieGame/game.html', context_dict)