當前位置: 首頁>>代碼示例>>Python>>正文


Python Game.save方法代碼示例

本文整理匯總了Python中games.models.Game.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Game.save方法的具體用法?Python Game.save怎麽用?Python Game.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在games.models.Game的用法示例。


在下文中一共展示了Game.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ship_creation

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
    def test_ship_creation(self):
        """Test that Ship instances are created correctly."""
        game = Game()
        game.save()

        user = User(username='user', password='password')
        user.save()

        player = Player(user=user)
        player.save()

        team = Team(player=player, game=game)
        team.save()

        ship = Ship(
            team=team,
            x=0,
            y=0,
            length=3,
            direction=Ship.CARDINAL_DIRECTIONS['WEST']
        )

        self.assertTrue(isinstance(ship, Ship))
        self.assertEqual(
            str(ship),
            'Game 1 - user\'s 3L at (0, 0) facing West'
        )
開發者ID:RuairiD,項目名稱:django-battleships,代碼行數:29,代碼來源:test_models.py

示例2: invite

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
def invite(hometeam,awayteam): 
	
	game=Game(player_1=hometeam, player_2=awayteam)
	game.save()

	message = client.messages.create(to=hometeam, from_="+16502156107",
		body="Your game has started. Make your first move...")
開發者ID:soums,項目名稱:TicTacTwilio,代碼行數:9,代碼來源:views.py

示例3: create

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
    def create(self, request):
        serializer = GameSerializer(data=request.data)
        if serializer.is_valid():

            user = request.user
            player = user.player

            player.hosted_count += 1
            player.game_count += 1
            if request.data['nickname'] != "":
                player.nickname = request.data['nickname']
            elif  player.nickname == "":
                player.nickname = player.user.username

            player.save()

            new_game = Game()
            new_game.host = player
            new_game.name = request.data['name']
            new_game.motto = request.data['motto']
            new_game.passcode = request.data['passcode']
            new_game.save()

            new_game_player_detail = GamePlayerDetail()
            new_game_player_detail.game = new_game
            new_game_player_detail.player = player
            new_game_player_detail.save()

            return Response({'status': 'game set', 'game_id': new_game.id})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:peasnrice,項目名稱:pamplesneak,代碼行數:33,代碼來源:views.py

示例4: TeamPresenterTestCase

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
class TeamPresenterTestCase(TestCase):

    def setUp(self):
        self.game = Game()
        self.game.save()

        self.user = User.objects.create_user('user', '', 'password')

        self.player = Player(user=self.user)
        self.player.save()

        self.team = Team(player=self.player, game=self.game)
        self.team.save()

    def test_from_team(self):
        presenter = TeamPresenter.from_team(team=self.team, game=self.game)

        self.assertEqual(presenter.player.username, self.user.username)
        self.assertTrue(presenter.is_next)
        self.assertEqual(presenter.winner, self.team.winner)
        self.assertEqual(presenter.alive, self.team.alive)
        self.assertEqual(len(presenter.tiles), GAME_SIZE)
        self.assertEqual(len(presenter.tiles[0]), GAME_SIZE)

    def test_make_tiles(self):
        tiles = TeamPresenter.make_tiles(team=self.team, game=self.game)

        self.assertEqual(len(tiles), GAME_SIZE)
        for i in range(0, GAME_SIZE):
            self.assertEqual(len(tiles[i]), GAME_SIZE)
開發者ID:RuairiD,項目名稱:django-battleships,代碼行數:32,代碼來源:test_presentation.py

示例5: new_game

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
def new_game(request):
	game = Game(
		title = 'New Game',
		description = 'Write a description here',
		author = request.user,
		pubDate = datetime.datetime.now(),
		lastEditDate = datetime.datetime.now())
	game.save()

	return render_to_response('build.html',{'game_id':game.id}, context_instance=RequestContext(request))
開發者ID:chrismcmath,項目名稱:Lucura,代碼行數:12,代碼來源:viewsOLDII.py

示例6: save_game

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
def save_game(request):
	if request.method == 'POST':
		info = json.loads(request.body);
		newGame = Game(title=info.get('title'), description=info.get('description'))
		newGame.pubDate = datetime.datetime.now()
		newGame.author = User.objects.get(username='chrismcmath')
		newGame.numberQuestions = 0
		newGame.save()
		pdb.set_trace()
	return HttpResponse(request.body, mimetype="application/json")
開發者ID:chrismcmath,項目名稱:Lucura,代碼行數:12,代碼來源:viewsOLD.py

示例7: create

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
def create(request):
    if request.method == "POST":
        game = Game()
        game.name = request.POST['name']
        game.player_one = request.user.get_profile()
        couch = couchdb.Server(settings.COUCHDB_HOST)
        db = couch[settings.COUCHDB_NAME]
        game.couch_id = db.create({'game': db['game_start']['game']})
        game.save()
        return HttpResponseRedirect(game.get_absolute_url())
    else:
        raise Http404
開發者ID:Apreche,項目名稱:Turnflict,代碼行數:14,代碼來源:views.py

示例8: post

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            form = CreateGameForm(request.POST, max_players=MAX_PLAYERS)
            if form.is_valid():
                opponent_usernames = []
                for i in range(0, MAX_PLAYERS):
                    field_name = "opponent_username_{}".format(i)
                    opponent_usernames.append(form.cleaned_data[field_name])

                try:
                    opponent_users = []
                    for opponent_username in opponent_usernames:
                        if len(opponent_username) > 0:
                            opponent_users.append(User.objects.get(username=opponent_username))
                except User.DoesNotExist:
                    error_message = "User does not exist! " "Are you sure the username is correct?"
                    messages.error(request, error_message)
                    context = {"form": form}
                    return render(request, self.template_name, context)

                user_player = Player.objects.get(user=request.user)
                opponent_players = [Player.objects.get(user=opponent_user) for opponent_user in opponent_users]

                # Create a game plus teams and ships for both players
                # Creation in Game -> Team -> Ships order is important
                # to satisfy ForeignKey dependencies.
                game = Game()
                game.save()
                user_team = Team(player=user_player, game=game, last_turn=-2)
                opponent_teams = [
                    Team(player=opponent_player, game=game, last_turn=-1) for opponent_player in opponent_players
                ]
                user_team.save()
                for opponent_team in opponent_teams:
                    opponent_team.save()

                user_ships = make_ships(user_team, Ship.LENGTHS)
                for opponent_team in opponent_teams:
                    opponent_ships = make_ships(opponent_team, Ship.LENGTHS)
                    for user_ship in user_ships:
                        user_ship.save()
                    for opponent_ship in opponent_ships:
                        opponent_ship.save()

                return HttpResponseRedirect(reverse("game", args=[game.id]))
            else:
                messages.error(request, "Invalid form.")
                context = {"form": form}
                return render(request, self.template_name, context)
        else:
            return HttpResponseRedirect("/login")
開發者ID:RuairiD,項目名稱:django-battleships,代碼行數:53,代碼來源:views.py

示例9: test_team_creation

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
    def test_team_creation(self):
        """Test that Team instances are created correctly."""
        game = Game()
        game.save()

        user = User.objects.create_user('user', '', 'password')

        player = Player(user=user)
        player.save()

        team = Team(player=player, game=game)

        self.assertTrue(isinstance(team, Team))
        self.assertEqual(str(team), 'Game 1 - user (last_turn=0)')
開發者ID:RuairiD,項目名稱:django-battleships,代碼行數:16,代碼來源:test_models.py

示例10: import_games

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
def import_games(csv_file):
    with open(csv_file, 'r') as file:
        csv_reader = csv.DictReader(file)
        for row in csv_reader:
            g = Game()
            g.location = row["location"]
            g.name = row["name"]
            hour = row["time"].split(":")[0]
            minute = row["time"].split(":")[1]
            year = row["date"].split("-")[0]
            month = row["date"].split("-")[1]
            day = row["date"].split("-")[2]        
            g.date = date(int(year), int(month), int(day))
            g.time = time(int(hour), int(minute))
            g.save()
開發者ID:curtmerrill,項目名稱:atlgameday,代碼行數:17,代碼來源:import.py

示例11: create_game

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
def create_game(game_num, roster_soup):

    # pull team name data from txt - first two instances of class teamHeading
    teams = roster_soup.find_all("td", class_="teamHeading")
    away_name = teams[0].text.encode("utf-8")
    home_name = teams[1].text.encode("utf-8")

    # Creates TeamGame objects home, away
    away = TeamGame.objects.create(team=Team.objects.get(name=away_name))
    home = TeamGame.objects.create(team=Team.objects.get(name=home_name))

    game = Game(game_id=game_num, team_home=home, team_away=away, date=import_date(roster_soup))
    game.save()

    return game
開發者ID:bkenny266,項目名稱:djifts,代碼行數:17,代碼來源:utility.py

示例12: test_game_requires_players

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
    def test_game_requires_players(self):
        arena = make_a_whole_arena()
        course = make_course(arena)[0]
        player = make_players()[0]

        game = Game(
            course=course,
            creator=player,
            created=datetime.now(),
        )
        game.save()
        game.players = [player]

        game.start()

        # Check that game doesn't finish without players
        self.assertRaises(ValidationError, game.finish)
開發者ID:torbjorntorbjorn,項目名稱:golfstats,代碼行數:19,代碼來源:tests.py

示例13: _create_games

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
    def _create_games(self, n=1):
        if Color.objects.count() < Game.AVAILABLE_COLORS:
            print "Impossible to create games. No enough colors."
            print "ESCAPING..."
            return

        print "Populating Games"
        for i in range(n):
            available_colors = Color.objects.all().order_by('?')[:Game.AVAILABLE_COLORS]

            game = Game()
            game.initial_amount = random.randint(0, 100)
            game.percentage = random.randint(0, 100)
            game.payment = random.uniform(0, 5)
            game.start_date = timezone.now()
            game.end_date = game.start_date + datetime.timedelta(days=random.randint(3, 30))
            game.save()
            game.available_colors.add(*available_colors)
        print "SUCCESS"
開發者ID:cfoch,項目名稱:circles_project,代碼行數:21,代碼來源:populate_db.py

示例14: create_game

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
def create_game(game):
    """ Create game object from Steam API call """
    from games.models import Game
    slug = slugify(game['name'])[:50]
    LOGGER.info("Adding %s to library" % game['name'])
    steam_game = Game(
        name=game['name'],
        steamid=game['appid'],
        slug=slug,
    )
    if game['img_logo_url']:
        steam_game.get_steam_logo(game['img_logo_url'])
    steam_game.get_steam_icon(game['img_icon_url'])
    try:
        steam_game.save()
    except Exception as ex:
        LOGGER.error("Error while saving game %s: %s", game, ex)
        raise
    return steam_game
開發者ID:Freso,項目名稱:website,代碼行數:21,代碼來源:steam.py

示例15: test_game_creation

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import save [as 別名]
    def test_game_creation(self):
        """Test that Game instances are created correctly."""
        game = Game()
        game.save()

        user1 = User.objects.create_user('user1', '', 'password')
        user2 = User.objects.create_user('user2', '', 'password')

        player1 = Player(user=user1)
        player2 = Player(user=user2)
        player1.save()
        player2.save()

        team1 = Team(player=player1, game=game)
        team2 = Team(player=player2, game=game)
        team1.save()
        team2.save()

        self.assertTrue(isinstance(game, Game))
        self.assertEqual(str(game), '1 - user1 user2')
開發者ID:RuairiD,項目名稱:django-battleships,代碼行數:22,代碼來源:test_models.py


注:本文中的games.models.Game.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。