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


Python Terrain.addBlock方法代码示例

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


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

示例1: testTerrain

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import addBlock [as 别名]
class testTerrain(unittest.TestCase):
    def setUp(self):
        pygame.init()
        pygame.display.set_mode([Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT])
        
        self.terrain = Terrain()
    def testAddTerrainBlock(self):
        self.terrain.addBlock(100, 150)
        self.assertEqual(len(self.terrain.sprites()), 1)
        self.assertEqual(self.terrain.sprites()[0].rect.x, 100)
        self.assertEqual(self.terrain.sprites()[0].rect.y, 150)
        
    def testCreateTerrain(self):
        self.terrain.createEastBorder(5)
        self.terrain.createNorthBorder(5)
        self.terrain.createSouthBorder(5)
        self.terrain.createWestBorder(5)
        self.assertEqual(len(self.terrain.sprites()), 5 * 4) 
开发者ID:ryuken,项目名称:gravity-snails,代码行数:20,代码来源:unittest_terrain.py

示例2: testSnail

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import addBlock [as 别名]
class testSnail(unittest.TestCase):
    """
    A test class for the Snail module.
    """

    def setUp(self):

        """
        set up data used in the tests.

        setUp is called before each test function execution.
        """

        pygame.init()
        pygame.display.set_mode([Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT])

        self.input = Input()
        self.terrain = Terrain()
     
        self.teamName = "EJteam"
        self.team = Team(self.teamName)
        self.team.setGravity(Direction.DOWN)
        self.team.hasTurn = True
        
        TurnManager().status = TurnStatus.CURRENTTURN
        TurnManager().teams = [] 
        TurnManager().teams.append(self.team)
        self.snail = Snail(self.team)
        self.snail.hasTurn = True

    def testInitialized(self):
        self.assertEqual(self.snail.team.name, self.teamName)
        # self.assertEqual(self.snail.hasTurn, False)

    def testFollowMouse(self):
        self.input.mouse_x = 100
        self.input.mouse_y = 100
        self.snail.update(self.input, self.terrain)
        self.assertEqual(self.snail.rect.centerx, 100)
        self.assertEqual(self.snail.rect.centery, 100)
        
        self.input.mouse_x = 150
        self.input.mouse_y = 150
        self.terrain.addBlock(150, 150)
        self.snail.update(self.input, self.terrain)
        
        self.assertNotEqual(self.snail.rect.centerx, 150)
        self.assertNotEqual(self.snail.rect.centery, 150)
        
    def testSnailPlaceSnailCorrect(self):
        self.input.mouse_x = 100
        self.input.mouse_y = 100
        self.input.mouse_left = True
        self.input.mouse_left_click = True
        self.snail.update(self.input, self.terrain)
        self.assertTrue(self.snail.isPlaced)
        
    def testSnailPlaceSnailWrong(self):
        self.input.mouse_x = 150
        self.input.mouse_y = 150
        self.terrain.addBlock(150, 150)
        self.input.mouse_left = True
        self.snail.update(self.input, self.terrain)
        self.assertFalse(self.snail.isPlaced)
        
    def testGravityDown(self):
        self.testSnailPlaceSnailCorrect()
        self.team.setGravity(Direction.DOWN)
        old_y = self.snail.rect.centery
        for i in range(0,10):
            self.snail.update(self.input, self.terrain)
            
        self.assertTrue(self.snail.rect.centery > old_y)
    
    def testGravityDownSpeed(self):
        self.testSnailPlaceSnailCorrect()
        self.assertEqual(self.snail.direction['jump'], 0)
        self.snail.updateGravity()
        self.assertEqual(self.snail.direction['jump'], self.snail.speed['fall'])
        
        waitTurns = 5 / self.snail.speed['fall']
        for i in range(0, waitTurns + 5):
            self.snail.updateGravity()
            
        self.assertEqual(self.snail.direction['jump'], 5)
        
    def testGravityUp(self):
        self.testSnailPlaceSnailCorrect()
        self.snail.gravity_direction = Direction.UP
        old_y = self.snail.rect.centery
        for i in range(0,10):
            self.snail.update(self.input, self.terrain)
            
        self.assertTrue(self.snail.rect.centery < old_y)
        
    def testGravityRight(self):
        self.testSnailPlaceSnailCorrect()
        self.snail.gravity_direction = Direction.RIGHT
        old_x = self.snail.rect.centerx
        for i in range(0,10):
#.........这里部分代码省略.........
开发者ID:ryuken,项目名称:gravity-snails,代码行数:103,代码来源:unittest_snail.py


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