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


Python models.Game类代码示例

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


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

示例1: invite

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,代码行数:7,代码来源:views.py

示例2: test_ship_creation

    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,代码行数:27,代码来源:test_models.py

示例3: TeamPresenterTestCase

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,代码行数:30,代码来源:test_presentation.py

示例4: setUp

    def setUp(self):
        self.game1 = Game()
        self.game2 = Game()
        self.game1.save()
        self.game2.save()

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

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

        self.team_game1 = Team(
            player=self.player1,
            game=self.game1
        )
        self.team_game2 = Team(
            player=self.player1,
            game=self.game2,
            alive=False
        )
        self.team_game1.save()
        self.team_game2.save()
开发者ID:RuairiD,项目名称:django-battleships,代码行数:25,代码来源:test_views.py

示例5: game_edit

def game_edit(request, game_id):
    if request.method == 'POST':
        Game.update(game_id,
            title=request.POST['game_title'],
            genre_id=request.POST['genre_id'],
        )
        return redirect('games:index')
    else: # request.method == 'GET'
        context = {'game': Game.select(game_id), 'genres': Genre.select_all()}
        return render(request, 'games/edit.html', context)
开发者ID:SSheldon,项目名称:game-atlas,代码行数:10,代码来源:views.py

示例6: new_game

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,代码行数:10,代码来源:viewsOLDII.py

示例7: game_add

def game_add(request):
    if request.method == 'POST':
        Game.insert(
            title=request.POST['game_title'],
            genre_id=request.POST['genre_id'],
        )
        return redirect('games:index')
    else: # request.method == 'GET'
        context = {'genres': Genre.select_all()}
        return render(request, 'games/edit.html', context)
开发者ID:SSheldon,项目名称:game-atlas,代码行数:10,代码来源:views.py

示例8: test_create_game_already_in_game

 def test_create_game_already_in_game(self):
     first_game = Game._create_game(self.alice)
     second_game = Game._create_game(self.alice)
     self.assertEquals(first_game.turn, None)
     self.assertEquals(first_game.player1, self.alice)
     self.assertEquals(first_game.player2, None)
     self.assertEquals(first_game.winner, None)
     self.assertEquals(Game.current_game(self.alice), second_game)
     self.assertEquals(second_game.turn, None)
     self.assertEquals(second_game.player1, self.alice)
     self.assertEquals(second_game.player2, None)
     self.assertEquals(second_game.winner, None)
开发者ID:SeMorgana,项目名称:ConnectWithFriends,代码行数:12,代码来源:tests.py

示例9: post

    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,代码行数:51,代码来源:views.py

示例10: test_team_creation

    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,代码行数:14,代码来源:test_models.py

示例11: map

    def map(self, row):
        # Ensure that we have a game object to map to
        try:
            game = Game.objects.get(external_id=row['id'])
        except Game.DoesNotExist:
            game = Game()

        # Do the mapping...
        game.name = row['name']
        game.external_id = row['id']
        game.description = row['deck'] or ''
        game.release_date = row['original_release_date'][:10]

        return game
开发者ID:pjot,项目名称:gblist,代码行数:14,代码来源:runimport.py

示例12: create_game

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,代码行数:15,代码来源:utility.py

示例13: test_winning_move_diagonal_upper_right

 def test_winning_move_diagonal_upper_right(self):
     """
     000A000
     000BA00
     000AAA0
     000BBBA
     000AAAB
     B00BBBA
     """
     game = Game._create_game(self.alice)
     game.join(self.bob)
     game.move(self.alice, 6)
     game.move(self.bob, 6)
     game.move(self.alice, 6)
     game.move(self.bob, 5)
     game.move(self.alice, 5)
     game.move(self.bob, 5)
     game.move(self.alice, 5)
     game.move(self.bob, 4)
     game.move(self.alice, 4)
     game.move(self.bob, 4)
     game.move(self.alice, 4)
     game.move(self.bob, 0)
     game.move(self.alice, 4)
     game.move(self.bob, 3)
     game.move(self.alice, 3)
     game.move(self.bob, 3)
     game.move(self.alice, 3)
     game.move(self.bob, 3)
     self.assertEqual(game.winner, None)
     game.move(self.alice, 3)
     self.assertEqual(game.winner, self.alice)
开发者ID:SeMorgana,项目名称:ConnectWithFriends,代码行数:32,代码来源:tests.py

示例14: test_stalemate

 def test_stalemate(self):
     """
     BBBABBB
     AAABAAA
     BBBABBB
     AAABAAA
     BBBABBB
     AAABAAA
     """
     game = Game._create_game(self.alice)
     game.join(self.bob)
     for _ in range(3):
         game.move(self.alice, 0)
         game.move(self.bob, 0)
         game.move(self.alice, 1)
         game.move(self.bob, 1)
         game.move(self.alice, 2)
         game.move(self.bob, 2)
         game.move(self.alice, 4)
         game.move(self.bob, 3)
         game.move(self.alice, 3)
         game.move(self.bob, 4)
         game.move(self.alice, 5)
         game.move(self.bob, 5)
         game.move(self.alice, 6)
         game.move(self.bob, 6)
     self.assertEqual(game.stalemate, True)
     self.assertEqual(game.winner, None)
开发者ID:SeMorgana,项目名称:ConnectWithFriends,代码行数:28,代码来源:tests.py

示例15: test_winning_move_diagonal_upper_left

 def test_winning_move_diagonal_upper_left(self):
     """
     000A000
     00AB000
     0AAA000
     ABBB000
     BAAA000
     ABBB00B
     """
     game = Game._create_game(self.alice)
     game.join(self.bob)
     game.move(self.alice, 0)
     game.move(self.bob, 0)
     game.move(self.alice, 0)
     game.move(self.bob, 1)
     game.move(self.alice, 1)
     game.move(self.bob, 1)
     game.move(self.alice, 1)
     game.move(self.bob, 2)
     game.move(self.alice, 2)
     game.move(self.bob, 2)
     game.move(self.alice, 2)
     game.move(self.bob, 6)
     game.move(self.alice, 2)
     game.move(self.bob, 3)
     game.move(self.alice, 3)
     game.move(self.bob, 3)
     game.move(self.alice, 3)
     game.move(self.bob, 3)
     self.assertEqual(game.winner, None)
     game.move(self.alice, 3)
     self.assertEqual(game.winner, self.alice)
开发者ID:SeMorgana,项目名称:ConnectWithFriends,代码行数:32,代码来源:tests.py


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