예제 #1
0
def answer():
    if request.method == 'GET':
        return render_template('game.j2')
    if 'game_id' not in session and 'user_name' in session:
        filde = {'user_name': session['user_name']}
        game_play = Games(**filde)
        game_play.save()
        game_id = Games.select().order_by(Games.game_id.desc()).get()
        game_id = model_to_dict(game_id)['game_id']
        session['game_id'] = game_id
    answer = str(request.form['answer'])
    if 'riddle' in session:
        if answer.lower() == session['riddle']['answer'].lower():
            fields = {
                'game_result': True,
                'riddle': session['riddle']['id'],
                'game': session['game_id']
            }
            GameResulte(**fields).save()
            session.pop('riddle', None)
            return redirect(url_for('game'))
        else:
            resulte = 0
            resulte = GameResulte.select().where(
                GameResulte.game == session['game_id']).count()
            if not resulte:
                resulte = 'game over'
            session.pop('game_id', None)
            session.pop('riddle', None)
            session['resulte'] = resulte
            return redirect(url_for('index'))
    return render_template('game.j2')
예제 #2
0
파일: utils.py 프로젝트: le087/naval-battle
def add_new_game(new_field):
    """add new game in database
    
    - `new_field`: object field
    """
    new_game = Games(fields=[new_field])
    new_game.save()
    return new_game
예제 #3
0
def add_title(request):
    newtitle = request.GET['title']
    if newtitle != '':
        try:
            existingGame = Games.objects.get(title=newtitle)
            return render_to_response('gameexist.html')
        except:
            newgame = Games()
            newgame.title = newtitle
            newgame.save()
            us = User.objects.get(username__exact=request.user.username)
            us.employee.lastVoted = datetime.date.today()
            us.employee.save()
            us.save()
            gv = GameVote()
            gv.game_id = newgame
            gv.save()
    return HttpResponseRedirect('/home/')
예제 #4
0
def add_title(request):
	newtitle = request.GET['title']
	if newtitle != '':
		try:
			existingGame = Games.objects.get(title=newtitle)
			return render_to_response('gameexist.html')
		except:
			newgame = Games()
			newgame.title = newtitle
			newgame.save()
			us =  User.objects.get(username__exact=request.user.username)
			us.employee.lastVoted = datetime.date.today()
			us.employee.save()
			us.save()
			gv = GameVote()
			gv.game_id = newgame
			gv.save()
	return HttpResponseRedirect('/home/')
예제 #5
0
파일: utils.py 프로젝트: le087/naval-battle
def get_wait_users():
    """return list of users who are waiting game
    """
    now = datetime.datetime.now()
    time_old = now + datetime.timedelta(minutes = -2)
    users_wait = Users.objects(status=0, last_time__gte=time_old)
    for user in users_wait:
        try:
            field = Fields.objects.get(id=user.field_battle.id)
        except:
            field = Fields()
            field.save()
        try:
            game = Games.objects.get(id=user.game.id)
            game.fields = [field]
            game.save()
        except:
            game = Games(fields=[field])
            game.save()
        user.field_battle = field
        user.game = game
        user.save()
    return users_wait