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


Python models.Player类代码示例

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


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

示例1: newplayer

def newplayer(request):
  success = 0
  playerid = 0
  playername = ''
  if request.method == 'POST':
    form = NewPlayerForm(request.POST)
    if form.is_valid():
      cd = form.cleaned_data
      player = Player(name=cd['name'])
      player.save()
      squares = Square.objects.all().order_by('pk')
      if len(squares)-1 >= 24:
        squarei = random.sample(range(1,len(squares)),24)
      elif len(squares)-1 > 0:
        squarei = []
        for i in range(24):
          squarei.append(random.randint(1,len(squares)-1))
      else:
        squarei = []
        for i in range(24):
          squarei.append(0)
      for i in range(25):
        if i < 12:
          spot = Boardsquare(player=player,square=squares[squarei[i]],checked=False,order=i)
        elif i == 12:
          spot = Boardsquare(player=player,square=squares[0],checked=True,order=i)
        else:
          spot = Boardsquare(player=player,square=squares[squarei[i-1]],checked=False,order=i)
        spot.save()
      playerid = player.pk
      playername = player.name
      success = 1
  else:
    form = NewPlayerForm()
  return render(request, 'bingo/newplayer.html', {'form': form, 'success': success, 'id': playerid, 'name': playername})
开发者ID:bonventre,项目名称:djingo,代码行数:35,代码来源:views.py

示例2: player_put

def player_put(pid, name):
    """ Insert player via DotA2 ID """
    if not player_check(pid):
        query = Player(player_id=pid, name=name)
        query.save()
        return True
    return False
开发者ID:UltimatePancake,项目名称:pqn_dota,代码行数:7,代码来源:factory.py

示例3: add

    def add(self, pid):
        player = Player(
            Pid=pid
        )
        player.save()

        return player.id
开发者ID:rejahrehim,项目名称:jukebox,代码行数:7,代码来源:api.py

示例4: player_data

def player_data():
    if not request.json or 'player' not in request.json:
        print(request, request.json)
        abort(400)

    db = get_db()

    player_data = request.json['player']
    friends = player_data['friends']
    puzzle_data = player_data['puzzle_data']
    del player_data['friends']
    del player_data['puzzle_data']

    player = Player.get_or_create(player_data)
    db.session.query(Player).filter(
        Player.social_id == player.social_id).update(player_data)

    for friend_social_id in friends:
        friend = Player.get_or_create({"social_id": friend_social_id})
        player.add_friendship(friend)

    for index, puzzle_id in enumerate(puzzle_data['puzzles']):
        Score.maybe_update_score({
            'player_social_id': player.social_id,
            'puzzle_id': puzzle_id,
            'score': puzzle_data['scores'][index],
            'stars': puzzle_data['stars'][index]})

    db.session.commit()

    return jsonify(
        _assemble_response(player))
开发者ID:zachdonovan,项目名称:muddragon,代码行数:32,代码来源:app.py

示例5: get_player

def get_player(nick_name='', steam_id=''):
    """
    gets player by given params.
    If player changed nickname - replaces old one in db
    If no such player - creates new
    :param nick_name:
    :param steam_id:
    :param may_be_new:
    :return:Player object
    """
    print nick_name, steam_id
    if nick_name and not steam_id:
        try:  # FIXME: temporary crutch while checking old players steam_id is impossible (asker required)
            return Player.get(nick_name=nick_name)
        except:
            player = Player.create(steam_id=0, nick_name=nick_name)
            return player
    elif steam_id and not nick_name:
        return Player.get(steam_id=steam_id)
    elif steam_id and nick_name:
        try:
            player = Player.get(steam_id=steam_id)
        except:
            player = Player.create(steam_id=steam_id, nick_name=nick_name)
        if nick_name != player.nick_name:
            player.nick_name = nick_name  # TODO: test for it
            player.save()
        return player
开发者ID:Glucksistemi,项目名称:EGS-DSM,代码行数:28,代码来源:utils.py

示例6: new_player

def new_player(user):
    player = Player(
        user=user, level=1, points=10)
    player.save()
    player.add_sentence
    player.add_sentence
    player.add_sentence
开发者ID:Crimolt,项目名称:PlayEnglish,代码行数:7,代码来源:views.py

示例7: post

    def post(self):
        request_data = json.loads(self.request.body)
        logging.info(request_data)
        user = users.get_current_user()

        # VALIDATION
        if not validate_request_data(self.response, request_data, ['nick', 'player_class']):
            return
        if not validate_logged_inn(self.response):
            return
        if not self._validate_has_not_player_already(user):
            return
        if Player.query(Player.nick_lower == request_data['nick'].lower()).count() > 0:
            error_400(self.response, "ERROR_NICK_TAKEN", "The nickname %s is already taken" % request_data['nick'])
            return
        if not is_valid_player_class_name(request_data['player_class']):
            error_400(self.response, "ERROR_BAD_PLAYER_CLASS", "Player class ' %s ' is not valid." % request_data['player_class'])
            return

        # REGISTER PLAYER
        new_player = Player(
            id=user.user_id(),
            nick=request_data['nick']
        )

        for player_class in player_class_metrics:
            if player_class['name'] == request_data['player_class']:
                logging.info(player_class['stat_modifiers'])
                for stat_name, stat_value in player_class['stat_modifiers'].iteritems():
                    current_stat_value = getattr(new_player, stat_name)
                    new_stat_value = current_stat_value + stat_value
                    setattr(new_player, stat_name, new_stat_value)

        new_player.put().get()
        set_json_response(self.response, new_player.get_data("full"))
开发者ID:Andrioden,项目名称:dotacareer,代码行数:35,代码来源:players.py

示例8: test_undo_match

def test_undo_match(g):
    p = Player("test player")
    p2 = Player("test player 2")
    player_dao.create(p)
    p.id = 1
    player_dao.create(p2)
    p2.id = 2
    t = Tournament(0,'','T1','type',0)
    tournament_dao.create(t)
    t.id = 1
    match_dao.create([p.id, p2.id], t.id)
    match_id = 1
    match = Match(player1=p,player2=p2,id=match_id)
    match.score1 = 19
    match.score2 = 21
    match_dao.update(match)

    match_dao.undo(match)
    retrieved_match = match_dao.find(match_id)
    matches = match_dao.find_by_tournament(t.id)

    assert retrieved_match.score1 == 0
    assert retrieved_match.score2 == 0
    assert retrieved_match.player1.fname == p.fname
    assert retrieved_match.player2.fname == p2.fname
    assert retrieved_match.player1.id == p.id
    assert retrieved_match.player2.id == p2.id
    assert not matches[0].entered_time
开发者ID:ewilson,项目名称:tournament,代码行数:28,代码来源:match_dao_test.py

示例9: testSaveOkCheckEmail

 def testSaveOkCheckEmail(self):
     player = Player(self.collection, self.name, self.email, self.fbid, self.artist)
     expected = self.email
     player.save()
     q = {'e': self.email}
     actual = self.collection.find_one(q)['e']
     assert_equal(expected, actual)
开发者ID:nleite,项目名称:teamr,代码行数:7,代码来源:tests.py

示例10: get

    def get(self):

        isPlayer = login.isPlayer()
        isAdmin = login.isAdmin()

        if not isAdmin and not isPlayer:
            self.response.set_status(500, message='You must log in')
            self.response.out.write('You must log in')
            return

        logging.info(self.request)

        if self.request.get('currentUser'):
            user = users.get_current_user()
            player = Player.all()
            player = player.filter('email =', user.email()).get()
            if player:
                self.response.out.write(playerToJSON(player, isAdmin))
            else:
                self.response.set_status(500, message='You\'re not a player')
                self.response.out.write('You\'re not a player')
                return

        else:
            players = Player.all()
            self.response.out.write(playersToJSON(players, isAdmin))
开发者ID:zi,项目名称:calcetto_apps,代码行数:26,代码来源:rpc.py

示例11: player

    def player(self, message, first, last):
        ''' format sms: player first last
        
        la fonction repond une phrase au hasard a un player '''
        # creation d'un player 
        player = Player(first_name=first, \
                                last_name=last, \
                                
                                number=message.peer)
                                
        # ma liste de reponse 
        list= ["vous etes un as", 
                "vous etes formidable",
                "reesayez vous pouvez le faire", 
                'vive le SENEGAL',
                u"vous n'etes pas trop doué",
                "vous êtes un pythonier"]
        # je melange ma liste et je tire une phrase au hasard
        ran = random.choice(list)
        
        # renvoie d'une reponse        
        message.respond(u"%(att)s, %(att1)s." % {'att': player, 'att1':ran})
        # sauvegarde le player
        player.save()

        return True
开发者ID:rgaudin,项目名称:souktelws,代码行数:26,代码来源:app.py

示例12: test_blackjack_player_wins

 def test_blackjack_player_wins(self):
     player = Player('cory','password')
     game = Game('Blackjack')
     hand = Hand()
     player.bank = 100
     player.hands.append(hand)
     game.hands.append(hand)
     game.players.append(player)
     bank_before_bet = player.bank
     # cards_app.session.commit()
     cards_app.session.flush()
     bet(hand, 50)
     cards = [Card(sequence=1), Card(sequence=10)]
     hand.cards.extend(cards)
     count_blackjack(hand)
     evaluate_hit(hand)
     # player wins with nautral evaluate_hit
     assert player.bank == bank_before_bet - 50
     # player stands on 18, dealer stands on 17
     hand.cards = [Card(sequence=10), Card(sequence=8)]
     bet(hand, 50)
     game.dealer = Player('cory','password')
     dealer = game.dealer
     dealer.cards = [Card(sequence=10), Card(sequence=17)]
     dealer_hand = Hand()
     dealer_hand.cards = dealer.cards
开发者ID:maddencs,项目名称:cards,代码行数:26,代码来源:tests.py

示例13: post

    def post(self):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url("/"))
            return

        game_name = self.request.get("game_name")
        if not game_name:
            self.response.write("No game name specified")
            return

        game_key = db.Key.from_path("Game", game_name)
        game = db.get(game_key)

        if not game:
            game = Game(key_name=game_name)
            game.put()

        logging.info("Game: {0}".format(game))

        player = Player(user=user, parent=game)
        player.put()

        token = channel.create_channel("{0}:{1}".format(game_name, user.user_id()))

        logging.info("/game?gamename={0}&token={1}".format(game.key().id_or_name(), token))
        self.redirect("/game?gamename={0}&token={1}".format(game.key().id_or_name(), token))
开发者ID:dillonbly,项目名称:oh-the-humanity,代码行数:27,代码来源:join_game_handler.py

示例14: twitter_callback

def twitter_callback(request):
    """ This method deals with the callback needed by twitter, and creating the their user.

    """
    if 'denied' in request.GET:
        return HttpResponseRedirect('/')

    twitter_conn = twitter(
        twitter_token = keys.CONSUMER_KEY,
        twitter_secret = keys.CONSUMER_SECRET,
        oauth_token = request.session['request_token']['oauth_token'],
        oauth_token_secret = request.session['request_token']['oauth_token_secret']
    )

    auth_tokens = twitter_conn.get_authorized_tokens()

    try:
        user = User.objects.get(username = auth_tokens['screen_name'])
    except User.DoesNotExist:
        user = create_django_user(auth_tokens['screen_name'], auth_tokens['oauth_token_secret'])
        player = Player()
        player.user = user
        player.twitter_oauth_token = auth_tokens['oauth_token']
        player.twitter_oauth_secret = auth_tokens['oauth_token_secret']
        request.session['twitter'] = player
        form = PlayerForm(initial={'username': player.user.username})
        return render(request, 'register.html', {'form': form})
    player = Player.objects.get(user=user)
    user = authenticate(username=player.user.username, password=player.twitter_oauth_secret)
    login(request, user)
    return HttpResponseRedirect('/')
开发者ID:fyelles,项目名称:courtside,代码行数:31,代码来源:views.py

示例15: get

 def get(self, request, player_id=None):
     if player_id==None:
         data = [model_to_dict(i) for i in Player.get_all()]
         return HttpResponse(json.dumps(data))
     player = Player.get_by_id(player_id)
     player = model_to_dict(player)
     return HttpResponse(json.dumps({"player": player}))
开发者ID:lhalam,项目名称:itaplay,代码行数:7,代码来源:views.py


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