当前位置: 首页>>代码示例>>Python>>正文


Python Player.game方法代码示例

本文整理汇总了Python中models.Player.game方法的典型用法代码示例。如果您正苦于以下问题:Python Player.game方法的具体用法?Python Player.game怎么用?Python Player.game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Player的用法示例。


在下文中一共展示了Player.game方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makerobogame

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import game [as 别名]
def makerobogame(request):
  
    fb_id = ROBOT1
    request.session['fb_id'] = fb_id
 
    # make robot player 1
    try:
        m_from = Member.objects.get( fb_id=ROBOT1 )
    except Member.DoesNotExist:
        m_from   = Member(fb_id=ROBOT1)
        m_from.user_name     =  'Robo1'
        m_from.fb_first_name =  'Robo1'
        m_from.fb_last_name  =  'Robo1'
        m_from.save()
    # make robot player 2
    try:
        m_to = Member.objects.get( fb_id=ROBOT2 )
    except Member.DoesNotExist:
        m_to   = Member(fb_id=ROBOT2)
        m_to.user_name     =  'Robo2'
        m_to.fb_first_name =  'Robo2'
        m_to.fb_last_name  =  'Robo2'
        m_to.save()

    # name is set
    request_from = 'Robo1'
    request_to   = 'Robo2'
    gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) ) 
    r = Room(name=gamename)
    r.fb_request_id = ROBOREQUEST
    r.save()

    g = Game(room=r)
    # game name and room name duplicated 
    g.name = gamename
    g.save()

    p = Player(member=m_from)  # player in game, link to member 
    p.game=g		       # game 
    p.turn=0                   # static order of player in game
    p.save()

    request.session['player_id'] = p.turn

    # TODO assumes two player game - generalize
    p = Player( member = m_to )
    p.game=g
    p.turn=1
    p.save()

    return HttpResponse( simplejson.dumps( { "gamename": gamename } ), mimetype='application/javascript' )
开发者ID:cliffmeyer,项目名称:lupalo,代码行数:53,代码来源:views.py

示例2: new_game

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import game [as 别名]
def new_game(request):
    player = Player.gql("WHERE imei = :1", request.GET['imei']).get()
    if not player:
        player = Player(imei = request.GET['imei'])
    player.game_requested = datetime.now()
    player.put()
    # Because there cant be two inequals in one query
    opponents = Player.gql("WHERE game_requested > :1 ", datetime.now() - timedelta(0, 45)).fetch(2)
    opponents = filter(lambda x: x.imei != request.GET['imei'], opponents)
    if opponents:
        opponent = opponents[0]
        player.game_requested, opponent.game_requested = None, None
        game = CheckersGame.create(player1 = opponent, player2 = player)
        player.game, opponent.game = game, game
        game.setup()
        game.put()
        
        player.put()
        opponent.put()
        return HttpResponseRedirect("/api/action/?imei=%s"%request.GET['imei'])
    return HttpResponse(sj.dumps({'status' : 'waiting'}))
开发者ID:LongMan,项目名称:moubail-checkers,代码行数:23,代码来源:views.py

示例3: handlefbrequestcallback

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import game [as 别名]
def handlefbrequestcallback(request):
    fp = open( 'tmp.3.log', 'w' ) 
    print >> fp, request
    request_str   = ( request.GET.get('request') )
    request_to    = ( request.GET.get('to') )
    request_id    = ( request.GET.get('id') )
    request_from  = request.session['fb_id']

    print >> fp, "request id",     request_id
    print >> fp, "request string", request_str
    print >> fp, "request to",     request_to
    print >> fp, "request from",   request_from
    print >> fp, "request fb id",  request.session['fb_id']

    instance = UserSocialAuth.objects.filter(provider='facebook',user=request.user.id).order_by('-id')[0]
    graph   = facebook.GraphAPI(instance.tokens["access_token"])

    try:
        profile = graph.get_object("me")
    except:
        logout(request)
        return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST

    try:
    	m_to   = Member.objects.get(fb_id=request_to)
    except: 
	# need to make member    	
        m_to   = Member(fb_id=request_to)

        # play against robot
        if request_to == 'auto':
            m_to.fb_first_name = 'auto'
            m_to.fb_last_name  = 'auto'
	else: 
            profile = graph.get_object( str(request_to) )
            m_to.fb_first_name = profile['first_name']
            m_to.fb_last_name  = profile['last_name']
        m_to.save()

    if m_to.fb_first_name == None or m_to.fb_last_name == None:
        profile = graph.get_object( str(request_to) )
        m_to.fb_first_name = profile['first_name']
        m_to.fb_last_name  = profile['last_name']
        m_to.save()
  
    try: 
        m_from = Member.objects.get(fb_id=request_from)
    except:
	# need to make member    	
        m_from = Member(fb_id=request_from)
        profile = graph.get_object( str(request_from) )
        m_from.fb_first_name = profile['first_name']
        m_from.fb_last_name  = profile['last_name']
        m_from.save() 

    if m_from.fb_first_name == None or m_from.fb_last_name == None:
        profile = graph.get_object( str(request_from) )
        m_from.fb_first_name = profile['first_name']
        m_from.fb_last_name  = profile['last_name']
        m_from.save()

    # name is set
    gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) ) 
    print >> fp, "gamename", gamename
    r = Room(name=gamename)
    r.fb_request_id = request_id
    r.save()

    g = Game(room=r)
    # game name and room name duplicated 
    g.name = gamename
    g.save()

    p = Player(member=m_from)
    p.game=g
    p.turn=0
    p.save()

    # TODO assumes two player game - generalize
    p = Player( member = m_to )
    p.game=g
    p.turn=1
    p.save()

    #return HttpResponseRedirect('requestpage.html')
    return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
开发者ID:cliffmeyer,项目名称:lupalo,代码行数:88,代码来源:views.py


注:本文中的models.Player.game方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。