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


Python Game.getPlayers方法代码示例

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


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

示例1: Test

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import getPlayers [as 别名]
class Test(unittest.TestCase):

    def setUp(self):
        self.game = Game()
        self.redPlayer = Player(PlayerColor.Red, Strategy())
        self.bluePlayer = Player(PlayerColor.Blue, Strategy())
        self.yellowPlayer = Player(PlayerColor.Yellow, Strategy())
        self.greenPlayer = Player(PlayerColor.Green, Strategy())
        for p in [self.redPlayer, self.bluePlayer, self.yellowPlayer, self.greenPlayer]:                
            self.game.addPlayer(p)
    
    def testAddingPlayer(self):
        self.game = Game()  
        self.assertEqual(self.game.playerCount(), 0, "no player at start")
          
        self.game.addPlayer(self.redPlayer)
        self.assertEqual(self.game.playerCount(), 1, "one player added")
  
        self.game.addPlayer(self.bluePlayer)
        self.assertEqual(self.game.playerCount(), 2, "two players added")
  
    def testGameFinished(self):
        self.assertFalse(self.game.finished(), "game should not be finished at start")
          
    def testPlayerOrderAtStart(self):
        self.assertEqual(self.game.playerCount(), 4, "all four players added")
        self.assertListEqual([self.redPlayer, self.bluePlayer, self.yellowPlayer, self.greenPlayer], 
                             self.game.getPlayers())
 
    def testPlayerOrderScore(self):
        self.redPlayer.addScore(3)
        self.bluePlayer.addScore(2)
        self.yellowPlayer.addScore(4)
        self.greenPlayer.addScore(2)
        self.assertListEqual([self.yellowPlayer, self.redPlayer, self.bluePlayer, self.greenPlayer], 
                             self.game.getPlayers())
         
    def testPlayerOrderSecondCriteria(self):
        self.bluePlayer.addResources([3])
        self.assertEqual(self.game.playerCount(), 4, "all four players added")
        self.assertListEqual([self.bluePlayer, self.redPlayer, self.yellowPlayer, self.greenPlayer], 
                             self.game.getPlayers())
        
    def testMixedScores(self):
        self.redPlayer.addResources([3,3,3,3,4,5,5])
        self.redPlayer.buyHut(SimpleHut(4,5,5),[4,5,5])
        
        self.yellowPlayer.addResources([3,3,4,4,4,4,6,6,8,9])
        
        self.bluePlayer.addResources([3,3,4,4,4,4,6,6,9])
      
        self.greenPlayer.addResources([3,3,4,4,4,4,6,6,9])
        self.assertListEqual([self.redPlayer, self.yellowPlayer, self.bluePlayer, self.greenPlayer], 
                             self.game.getPlayers())
开发者ID:dennisdjensen,项目名称:python-proj,代码行数:56,代码来源:GameTest.py

示例2: Main

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import getPlayers [as 别名]
def Main():
    game = Game()
    game.startGame()
    game.getPlayers()
    game.getName()
    
    shot = Shots()
    shot.turnNumberToName()
    shot.turnNameToNumber()
    shot.playRPSLS(player1, player2)
    shot.decideWinner(2, 0)
开发者ID:kchipp,项目名称:RPSLSversion2,代码行数:13,代码来源:Main.py

示例3: TestGame

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import getPlayers [as 别名]
class TestGame(TestCase):

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

  def tearDown(self):
    ships = self.game.getShips()
    if ships != None:
      for ship in ships:
        # TODO: Find out why removeNode does not work here 
        #ship.visualNode.removeNode()
        ship.visualNode.detachNode()
        ship = None

  def testInit(self):
    self.failUnless(self.game)
    self.failUnlessEqual(self.game.state, Game.STATE_INITIALIZING)
    self.failUnless( self.game.windowExists() )
    self.failIf( self.game.getShips() )
    self.failUnless(self.game.physWorld)
    self.failUnless(self.game.physSpace)

  def testStart(self):
    self.game.start()
    self.failUnlessEqual(self.game.state, Game.STATE_RUNNING)
    ships = self.game.getShips()
    shipOne = ships[0]
    shipTwo = ships[1]
    self.failUnless( isinstance(ships, list) )
    self.failUnlessEqual( shipOne.name, Game.NAME_SHIP_ONE )
    self.failUnlessEqual( shipTwo.name, Game.NAME_SHIP_TWO )
    self.failUnless(shipOne.getVisualNode)
    self.failUnless(shipTwo.getVisualNode)
    self.failUnless( shipOne.isVisible() )
    self.failUnless( shipTwo.isVisible() )
    players = self.game.getPlayers()
    self.failUnless( isinstance(players, list) )
    playerOne = players[0]
    playerTwo = players[1]
    self.failUnlessEqual( playerOne.name, Game.NAME_PLAYER_ONE )
    self.failUnlessEqual( playerTwo.name, Game.NAME_PLAYER_TWO )

    # Test that the player can move the ship forward
    pos1 = shipOne.getPos()
    vel1 = shipOne.getVel()
    acc1 = shipOne.getAcc()
    playerOne.moveForwardOn()
    # Step Panda3D's task manager one tick forward
    taskMgr.step()
    pos2 = shipOne.getPos()
    vel2 = shipOne.getVel()
    acc2 = shipOne.getAcc()
    self.failIf(pos1 == pos2)
    self.failIf(vel1 == vel2)
    self.failIf(acc1 == acc2)

    # Make sure the game is listening to events
    self.failUnless(self.game.isListening)

  def testResetCamera(self):
    self.game.resetCamera()
    # Check that the camera has been moved to the correct position
    cameraPos = self.game.getCameraPos()
    defaultCameraPos = Game.CAMERA_POS_DEFAULT
    self.failUnless(cameraPos == defaultCameraPos)

  def testSetCameraPos(self):
    pos = (0, 0, 50)
    self.game.setCameraPos( pos )
    self.failUnless( self.game.getCameraPos() == pos )

  def testGetCameraPos(self):
    pos = self.game.getCameraPos()
    self.failUnless(pos)
    self.failUnless( isinstance(pos, tuple) )

  def testSetCameraHpr(self):
    self.game.setCameraHpr(Game.CAMERA_HPR_DEFAULT)
    hpr = self.game.getCameraHpr()
    self.failUnless(hpr == Game.CAMERA_HPR_DEFAULT)

  def testGetCameraHpr(self):
    hpr = self.game.getCameraHpr()
    self.failUnless(hpr)
    self.failUnless( isinstance(hpr, tuple) )

  def testRegisterListeners(self):
    self.game.start()
    players = self.game.getPlayers()
    playerOne = players[0]
    self.game.registerListeners()
    playerOneMoveForwardOnEvent = createNamedEvent(
      playerOne.name, Event.PLAYER_MOVE_FORWARD_ON
    )
    ships = self.game.getShips()
    shipOne = ships[0]
    shipTwo = ships[1]

    # Test that the player can move the ship forward
    pos1 = shipOne.getPos()
#.........这里部分代码省略.........
开发者ID:vesanieminen,项目名称:tsaap,代码行数:103,代码来源:TestGame.py


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