• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Player类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: fetch_and_save_tenhou_records

def fetch_and_save_tenhou_records(player_name):
    session = get_global_session()
    records_text = fetch_tenhou_records(player_name)
    records_lines = [line.strip() for line in records_text.split("<br>") if line.strip()]

    # check query target player
    player = session.query(Player).filter(Player.name == player_name).first()
    if not player:
        player = Player(player_name)
        session.add(player)
        session.commit()

    # check frequency
    now = datetime.datetime.now()
    check_point = now + datetime.timedelta(days=1)
    if not player.last_check_records_time or player.last_check_records_time > check_point:
        player.last_check_records_time = now
        session.commit()
    else:
        return "player was checked in %s, please wait for 1 day" % player.last_check_records_time

    # create all game_record
    game_record_list = []
    player_id_name_dict = dict()
    for line in records_lines:
        hash_string = GameRecord.get_record_line_hash(line)
        if session.query(GameRecord).filter(GameRecord.hash == hash_string).count() > 0:
            continue
        try:
            game_record = GameRecord(line)
        except IndexError, _ex:
            print _ex
            continue
        game_record_list.append(game_record)
开发者ID:SakuraSa,项目名称:TenhouLogger,代码行数:34,代码来源:tasks.py


示例17: reset

def reset(response):
    for player in Player.all().filter('isStarred', False):
        player.delete()
    for player in Player.all().filter('isStarred', True):
        response.out.write('full')
        player.status = 'waiting'
        player.put()
开发者ID:zi,项目名称:calcetto_apps,代码行数:7,代码来源:playerList.py


示例18: update_player_position

def update_player_position(args, latitude, longitude):
    player_id = get_player_id(args)
    Player.update(
        latitude=latitude,
        longitude=longitude,
        last_modified=datetime.now()
    ).where(Player.player_id == player_id).execute()
开发者ID:gsabran,项目名称:PokemonGo-Map,代码行数:7,代码来源:search.py


示例19: create_player

    def create_player(self, request):
        """Creates a new player.

        This function creates a new player. It will also make sure
        that the chosen username is not yet taken.
        (NB: Currently this function does not implement any validity checks
        on the email address, such as a regex etc.)

        Returns:
            StringMessage -- confirmation of player creation

        Raises:
            ConflictException -- if username or email address is taken already
        """
        # Check username and email address for conflicts
        if Player.query(Player.email_address == request.email_address).get():
            raise endpoints.ConflictException(
                    'A Player with that email address already exists.')
        if Player.query(Player.user_name == request.user_name).get():
            raise endpoints.ConflictException(
                    'A Player with that name already exists.')

        # Create player
        player = Player(user_name=request.user_name,
                        email_address=request.email_address)
        player.put()

        # Return confirmation of player creation
        return StringMessage(message='Player successfully created.')
开发者ID:zebralove79,项目名称:fsd_p4g,代码行数:29,代码来源:api.py


示例20: create_player

def create_player(first, last):

    person = Person(first_name=first, last_name=last)
    person.save()
    player = Player(person=person)
    player.save()

    return player
开发者ID:tammolaube,项目名称:soccer-island,代码行数:8,代码来源:test_models.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Playlist类代码示例发布时间:2022-05-27
下一篇:
Python models.Platform类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap