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


Python models.Game类代码示例

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


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

示例1: test_play_auto_computer_to_computer

 def test_play_auto_computer_to_computer(self):
     "Two computers playing against themselves."
     random.seed(0)
     game = Game(player_o="game.players.RandomPlayer", player_x="game.players.RandomPlayer")
     game.play_auto()
     self.assertEqual(game.board, "X XOOOXOX" if six.PY3 else "OOXOX OXX")
     self.assertEqual(game.is_game_over, "O")
开发者ID:M-V-Mounica,项目名称:django-tictactoe,代码行数:7,代码来源:test_models.py

示例2: test_play_second

    def test_play_second(self):
        "The second play is O"

        game = Game(board="X        ")
        game.play(1)
        self.assertEqual(game.board, "XO       ")
        self.assertEqual(game.next_player, "X")
开发者ID:dgdavis00,项目名称:django-tictactoe,代码行数:7,代码来源:test_models.py

示例3: test_is_game_over_tie

 def test_is_game_over_tie(self):
     "A game board that is a tie is a game over."
     g = Game()
     g.board_state = [['X', 'O', 'X'],
                      ['X', 'O', 'X'],
                      ['O', 'X', 'O']]
     self.assertTrue(g.is_game_over())
开发者ID:mirhampt,项目名称:Tic-Tac-Toe,代码行数:7,代码来源:tests.py

示例4: test_play_auto_computer_to_computer

 def test_play_auto_computer_to_computer(self):
     "Two computers playing against themselves."
     random.seed(0)
     game = Game(player_o='game.players.RandomPlayer', player_x='game.players.RandomPlayer')
     game.play_auto()
     self.assertEqual(game.board, "OOXOX OXX")
     self.assertEqual(game.is_game_over, 'O')
开发者ID:dgdavis00,项目名称:django-tictactoe,代码行数:7,代码来源:test_models.py

示例5: test_play_auto_computer_human

 def test_play_auto_computer_human(self):
     "At the start of the game, computer starts."
     random.seed(0)
     game = Game(player_o="human", player_x="game.players.RandomPlayer")
     game.play_auto()
     self.assertEqual(game.board, "      X  " if six.PY3 else "       X ")
     self.assertEqual(game.next_player, "O")
开发者ID:M-V-Mounica,项目名称:django-tictactoe,代码行数:7,代码来源:test_models.py

示例6: test_play_first

    def test_play_first(self):
        "X always goes first"

        game = Game()
        game.play(0)
        self.assertEqual(game.board, "X        ")
        self.assertEqual(game.next_player, "O")
开发者ID:dgdavis00,项目名称:django-tictactoe,代码行数:7,代码来源:test_models.py

示例7: new_game

def new_game(request,pk):
    if request.method=='GET':
        player = Player.objects.get(pk=pk)
        players = Player.objects.all()
        genres  = Genre.objects.all()
        return render(request,'player/new_game.html',{'players':players,'genres':genres,'player':player})
    else:
        print '## Adding New Game ##'
        game = Game(name = request.POST['name'],date = timezone.now(),active=False)
        genres = request.POST.getlist('genres')
        game.save()
        for genre in genres:
            game.genres.add(Genre.objects.get(pk=genre))
        game.save()
        print '## Saved Game ID: %s with name %s ##' % (game.id,game.name)
        player = Player.objects.get(pk=pk)
        PG = Player_Game(game = game, player = player, score = 0,accepted = True, declined = False)
        print '## The first player in the game is %s with ID %s ##' % (player.name, player.id)
        PG.save()
        players = request.POST.getlist('players')
        for p in players:
            player = Player.objects.get(pk = int(p))
            PG = Player_Game(game = game, player = player, score = 0, accepted = False, declined = False)
            PG.save()
            print '## Player %s with ID %s was invited to this game ##' % (player.name,player.id)
        return HttpResponseRedirect("/player/%s/"%pk)
开发者ID:rlmeyers,项目名称:FiveWordsOrLess,代码行数:26,代码来源:views.py

示例8: test_play_error_square_taken

    def test_play_error_square_taken(self):
        "You can't play a square that is taken."

        game = Game(board="XOX      ")
        with self.assertRaises(ValueError):
            game.play(1)
            game.play(2)
开发者ID:dgdavis00,项目名称:django-tictactoe,代码行数:7,代码来源:test_models.py

示例9: test_play_auto_computer_human

 def test_play_auto_computer_human(self):
     "At the start of the game, computer starts."
     random.seed(0)
     game = Game(player_o='human', player_x='game.players.RandomPlayer')
     game.play_auto()
     self.assertEqual(game.board, "       X ")
     self.assertEqual(game.next_player, "O")
开发者ID:dgdavis00,项目名称:django-tictactoe,代码行数:7,代码来源:test_models.py

示例10: test_random

    def test_random(self):
        "Basic testing."

        random.seed(0)  # For testing
        game = Game()
        p1 = RandomPlayer()

        game.play(p1.play(game))
        self.assertEqual(game.board, "      X  " if six.PY3 else "       X ")
开发者ID:M-V-Mounica,项目名称:django-tictactoe,代码行数:9,代码来源:test_players.py

示例11: test_add_user_to_game

    def test_add_user_to_game(self):
        game, _ = Game.create_new_game(self.aMap.id, self.user)

        # Perform the join logic
        _, players_json, player_id = Game.add_user_to_game(game.id, self.joiner)

        # Check a bunch of conditions
        self.assertEqual(len(players_json), 3)
        self.assertEqual(players_json[0], "hosting_player")
        self.assertEqual(players_json[1], "joining_player")
开发者ID:hellochar,项目名称:the_game_bazaar,代码行数:10,代码来源:tests.py

示例12: accept

    def accept(self, accepted):
        wait = GameRequest.check_last_time(self.requester)
        if wait:
            return wait

        self.accepted = accepted
        self.accept_time = timezone.now()
        if accepted:
            Game.create([self.requestee, self.requester], game_conf=self.game_config)
        self.save()
开发者ID:SharifAIChallenge,项目名称:AIC_game_runner,代码行数:10,代码来源:models.py

示例13: test_get_winner_column

    def test_get_winner_column(self):
        "Three in a column is a winner."
        for i in xrange(0, 3):
            g = Game()
            g.board_state[0][i] = g.board_state[1][i] = g.board_state[2][i] = 'X'
            self.assertEquals(g.get_winner(), 'X')

            g = Game()
            g.board_state[0][i] = g.board_state[1][i] = g.board_state[2][i] = 'O'
            self.assertEquals(g.get_winner(), 'O')
开发者ID:mirhampt,项目名称:Tic-Tac-Toe,代码行数:10,代码来源:tests.py

示例14: test_get_winner_rows

    def test_get_winner_rows(self):
        "Three in a row is a winner."
        for i in xrange(0, 3):
            g = Game()
            g.board_state[i][0] = g.board_state[i][1] = g.board_state[i][2] = 'X'
            self.assertEquals(g.get_winner(), 'X')

            g = Game()
            g.board_state[i][0] = g.board_state[i][1] = g.board_state[i][2] = 'O'
            self.assertEquals(g.get_winner(), 'O')
开发者ID:mirhampt,项目名称:Tic-Tac-Toe,代码行数:10,代码来源:tests.py

示例15: validate_rolls

    def validate_rolls(self, rolls):
        """Make sure incoming rolls arrays are good"""
        # create a game object which won't be saved to the database
        # so we can check that our rolls list is valid
        test_game = Game(name="test_game", _rolls='[]')
        try:
            for roll in rolls:
                test_game.add_roll(roll)
        except:
            raise serializers.ValidationError("Rolls list was invald")

        return rolls
开发者ID:jamescleary,项目名称:bowling-score-v2,代码行数:12,代码来源:serializers.py


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