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


Python Player.create方法代码示例

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


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

示例1: get_player

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
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,代码行数:30,代码来源:utils.py

示例2: join_random

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def join_random(user):
    """Finds and joins the optimal random game."""
    if user.num_random > 4:
        return jsonify(), 418

    game = Game.find_random(user)

    if not game:
        return jsonify(), 418

    player = Player.create(user, game)
    player.set_status_joined()
    user.num_random += 1

    joined = [p for p in game.players
                if p.status == Player.JOINED]

    if len(joined) == game.max_players:
        game.start()

    try:
        db.session.commit()
    except:
        db.session.rollback()
        raise

    return jsonify()
开发者ID:25cf,项目名称:politically-incorrect,代码行数:29,代码来源:game.py

示例3: initialize_player_position

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def initialize_player_position(args):
    player_id = get_player_id(args)
    start_position = get_pos_by_name(args.location)

    if len(Player.select().where(Player.player_id == player_id)) == 0:
        Player.create(
            player_id=player_id,
            name=args.username,
            enabled=True,
            last_modified=datetime.now(),
            start_latitude=start_position[0],
            start_longitude=start_position[1]
        )
    else:
        Player.update(
            last_modified=datetime.now(),
            start_latitude=start_position[0],
            start_longitude=start_position[1]
        ).where(Player.player_id == player_id).execute()
开发者ID:gsabran,项目名称:PokemonGo-Map,代码行数:21,代码来源:search.py

示例4: sign_up

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
    def sign_up(self, message):
        if self.is_bot(message['user']):
            self.talk('Nice try, <@' + message['user'] + '>: ' + 'No bots allowed!')
            return

        try:
            player = Player.create(slack_id=message['user'])
            self.talk('<@' + message['user'] + '>: ' + 'You\'re all signed up. Good luck!')
        except IntegrityError:
            self.talk('<@' + message['user'] + '>: ' + 'You\'re already signed up!')
开发者ID:mburst,项目名称:slack-elobot,代码行数:12,代码来源:elobot.py

示例5: create_room

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def create_room():
    """
    Route creates new room and redirects to the lobby.
    It adds a new player to the room and sets session cookie if not present
    """
    username = request.forms.get("username")
    if len(username) == 0:
        return HTTPError(403, "Username too short")

    sessid = request.cookies.get("sessid", generate_sessid())
    room = Room.create(code=generate_room_code())
    player = Player.create(sessid=sessid, name=username, room=room)
    room.owner = player
    room.save()

    response.set_cookie("sessid", sessid, path="/")
    return redirect("/game/%s/lobby" % room.code)
开发者ID:warownia1,项目名称:TheResistance,代码行数:19,代码来源:views.py

示例6: register

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def register():
    group_name = request.form['group'].strip()
    player_name = request.form['player'].strip()

    try:
        # Perform case-insensitive search.
        group = Group.get(fn.Lower(Group.name) == group_name.lower())
    except:
        group = Group.create(name=group_name)

    try:
        # Perform case-insensitive search.
        player = Player.get(fn.lower(Player.name) == player_name.lower(), group=group)
    except Player.DoesNotExist:
        player = Player.create(
            group=group, name=player_name, order=group.players.count())

    return str(player.id)
开发者ID:ChickTech,项目名称:puzzle-hunt,代码行数:20,代码来源:flask_app.py

示例7: add_player

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def add_player():
    name = request.form.get('name')
    surname = request.form.get('surname')
    Player.create({'name': name, 'surname': surname})
    return redirect(url_for('index'))
开发者ID:jeanmichelem,项目名称:foosball,代码行数:7,代码来源:main.py

示例8: get_user

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
def get_user(content):
    """
    Find and return the user's info, or
    create the user if he doesn't exist.
    If the user doesn't exist, enter
    the user into 3 random games and
    add 5 random friends.
    """

    token  = content['token']
    device = content['device']
    now    = datetime.now()
    user   = User.auth(token)

    if not user:
        user = User.create(token)

        if not user:
            return jsonify(), 418

        else:  # give the new user 3 random games and 5 random friends
            games   = Game.find_n_random(3, user)
            players = [Player.create(user, game) for game in games]
            [player.set_status_joined() for player in players]

            for game in games:
                joined = [p for p in game.players
                            if p.status == Player.JOINED]
                if len(joined) == game.max_players:
                    game.start()

            friends = User.find_n_random(5, user)
            [f.add(user) for f in friends]
            [user.add(f) for f in friends]

    user.device = device

    try:
        db.session.commit()
    except:
        db.session.rollback()
        raise

    friendships = user.get_friendships()
    friends     = []

    for friendship in friendships:
        friend = \
            friendship.sender if friendship.sender != user else \
            friendship.receiver

        friend_json = {
            'name'   : friend.name,
            'email'  : friend.email,
            'picture': friend.picture
        }

        if friendship.valid:
            friend_json['status'] = Friendship.VALID
        elif friend == friendship.sender:
            friend_json['status'] = Friendship.REQUEST
        else:
            friend_json['status'] = Friendship.PENDING

        friends.append(friend_json)

    return jsonify(**{
        'name'   : user.name,
        'email'  : user.email,
        'picture': user.picture,
        'token'  : user.token,
        'friends': friends,
        'games'  : [
            {
                'id'           : p.game.id,
                'name'         : p.game.name,
                'status'       : p.game.status,
                'player_status': p.status,
                'seen'         : p.seen,
                'random'       : p.game.random,
                'players'      : [
                    {
                        'name'   : _p.user.name,
                        'email'  : _p.user.email,
                        'picture': _p.user.picture,
                        'status' : _p.status,
                        'points' : _p.score
                    }
                    for _p in p.game.players
                ]
            }
            for p in user.players
            if not p.game.end_time or p.game.end_time + timedelta(weeks=1) > now
        ]
    })
开发者ID:25cf,项目名称:politically-incorrect,代码行数:97,代码来源:user.py

示例9: test_find

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create [as 别名]
 def test_find(self):
     Player.create({"name": "test", "surname": "test"})
     players = Player.find()
     self.assertGreater(len(players), 0, "Players array should be greater than zero")
开发者ID:jeanmichelem,项目名称:foosball,代码行数:6,代码来源:test_db.py


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