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


Python Ship.placeShip方法代码示例

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


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

示例1: TestPlaceShip

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import placeShip [as 别名]
class TestPlaceShip(unittest.TestCase):
    def setUp(self):
        self.testShip = Ship('testShip1', 3)

    def test_placeShipUp(self):
        self.testShip.placeShip((0, 0), UP)
        self.assertEquals(self.testShip.locations, set([(0, 0),
                                                        (0, 1),
                                                        (0, 2),
                                                        ]))

    def test_placeShipDown(self):
        self.testShip.placeShip((5, 5), DOWN)
        self.assertEquals(self.testShip.locations, set([(5, 5),
                                                        (5, 4),
                                                        (5, 3),
                                                        ]))

    def test_placeShipRight(self):
        self.testShip.placeShip((5, 2), RIGHT)
        self.assertEquals(self.testShip.locations, set([(5, 2),
                                                        (6, 2),
                                                        (7, 2),
                                                        ]))

    def test_placeShipLeft(self):
        self.testShip.placeShip((5, 2), LEFT)
        self.assertEquals(self.testShip.locations, set([(5, 2),
                                                        (4, 2),
                                                        (3, 2),
                                                        ]))
开发者ID:kevintandean,项目名称:BattlePy,代码行数:33,代码来源:test_ship.py

示例2: TestIsSunk

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import placeShip [as 别名]
class TestIsSunk(unittest.TestCase):
    def setUp(self):
        self.testShip = Ship('testShip1', 3)
        self.testShip.placeShip((5, 5), UP)

    def test_notSunk(self):
        self.testShip.hits = set([(5, 5),
                                  (5, 6),
                                  ])
        self.assertFalse(self.testShip.isSunk())

    def test_sunk(self):
        self.testShip.hits = set([(5, 5),
                                  (5, 6),
                                  (5, 7),
                                  ])
        self.assertTrue(self.testShip.isSunk())
开发者ID:kevintandean,项目名称:BattlePy,代码行数:19,代码来源:test_ship.py

示例3: TestAddHit

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import placeShip [as 别名]
class TestAddHit(unittest.TestCase):
    def setUp(self):
        self.testShip = Ship('testShip1', 3)

    def test_notAHit(self):
        self.testShip.placeShip((5, 5), UP)
        shot = (0, 0)
        self.testShip.addHit(shot)

        self.assertEquals(self.testShip.hits, set())

    def test_hit(self):
        self.testShip.placeShip((5, 5), UP)
        shot = (5, 7)
        self.testShip.addHit(shot)

        self.assertEquals(self.testShip.hits, set([(5, 7)]))
开发者ID:kevintandean,项目名称:BattlePy,代码行数:19,代码来源:test_ship.py

示例4: TestCheckAllShipsSunk

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import placeShip [as 别名]
class TestCheckAllShipsSunk(unittest.TestCase):
    def setUp(self):
        self.testPlayer = Player()
        self.ship1 = Ship('ship1', 3)
        self.ship2 = Ship('ship2', 4)
        self.ship3 = Ship('ship3', 2)
        self.testPlayer._setShips([self.ship1,
                                   self.ship2,
                                   self.ship3,
                                   ])
        self.ship1.placeShip((5, 5), DOWN)
        self.ship2.placeShip((0, 6), RIGHT)
        self.ship3.placeShip((6, 5), RIGHT)

    def test_noShipsSunk(self):
        self.assertFalse(self.testPlayer._checkAllShipsSunk())

    def test_oneShipSunk(self):
        self.ship1.hits = self.ship1.locations
        self.assertFalse(self.testPlayer._checkAllShipsSunk())

    def test_allShipsSunk(self):
        self.ship1.hits = self.ship1.locations
        self.ship2.hits = self.ship2.locations
        self.ship3.hits = self.ship3.locations

        self.assertTrue(self.testPlayer._checkAllShipsSunk())
开发者ID:kevintandean,项目名称:BattlePy,代码行数:29,代码来源:test_player.py

示例5: TestCheckIsHit

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import placeShip [as 别名]
class TestCheckIsHit(unittest.TestCase):
    def setUp(self):
        self.testPlayer = Player()
        self.ship1 = Ship('ship1', 3)
        self.ship2 = Ship('ship2', 4)
        self.ship3 = Ship('ship3', 2)
        self.testPlayer._setShips([self.ship1,
                                   self.ship2,
                                   self.ship3,
                                   ])
        self.ship1.placeShip((5, 5), DOWN)
        self.ship2.placeShip((0, 6), RIGHT)
        self.ship3.placeShip((6, 5), RIGHT)

    def test_checkIsMiss(self):
        shot = (1, 1)
        hit, hitShip = self.testPlayer._checkIsHit(shot)

        self.assertFalse(hit)
        self.assertEqual(hitShip, None)

    def test_checkIsHit(self):
        shot = (5, 3)
        hit, hitShip = self.testPlayer._checkIsHit(shot)

        self.assertTrue(hit)
        self.assertEqual(hitShip, self.ship1)
开发者ID:kevintandean,项目名称:BattlePy,代码行数:29,代码来源:test_player.py

示例6: TestShipsPlacedLegally

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import placeShip [as 别名]
class TestShipsPlacedLegally(unittest.TestCase):
    def setUp(self):
        self.testPlayer = Player()
        self.ship1 = Ship('ship1', 3)
        self.ship2 = Ship('ship2', 4)
        self.ship3 = Ship('ship3', 2)
        self.testPlayer._setShips([self.ship1,
                                   self.ship2,
                                   self.ship3,
                                   ])

    def test_shipPlacedOffBoard(self):
        self.ship1.placeShip((0, 0), DOWN)
        result = self.testPlayer.isShipPlacedLegally(self.ship1)

        self.assertFalse(result)
        self.assertFalse(self.testPlayer._allShipsPlacedLegally())

    def test_shipsOverlapping(self):
        self.ship1.placeShip((5, 5), DOWN)
        self.ship2.placeShip((0, 6), RIGHT)
        self.ship3.placeShip((5, 5), RIGHT)

        result = self.testPlayer.isShipPlacedLegally(self.ship1)
        self.assertFalse(result)

        result = self.testPlayer.isShipPlacedLegally(self.ship2)
        self.assertTrue(result)

        result = self.testPlayer.isShipPlacedLegally(self.ship3)
        self.assertFalse(result)
        self.assertFalse(self.testPlayer._allShipsPlacedLegally())

    def test_shipsAreValid(self):
        self.ship1.placeShip((5, 5), DOWN)
        self.ship2.placeShip((0, 6), RIGHT)
        self.ship3.placeShip((6, 5), RIGHT)

        result = self.testPlayer.isShipPlacedLegally(self.ship1)
        self.assertTrue(result)

        result = self.testPlayer.isShipPlacedLegally(self.ship2)
        self.assertTrue(result)

        result = self.testPlayer.isShipPlacedLegally(self.ship3)
        self.assertTrue(result)
        self.assertTrue(self.testPlayer._allShipsPlacedLegally())
开发者ID:kevintandean,项目名称:BattlePy,代码行数:49,代码来源:test_player.py

示例7: TestIsPlacementValid

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import placeShip [as 别名]
class TestIsPlacementValid(unittest.TestCase):
    def setUp(self):
        self.testShip = Ship('testShip1', 3)

    def test_isPlacementValid(self):
        self.testShip.placeShip((0, 1), DOWN)
        self.assertFalse(self.testShip.isPlacementValid())

        self.testShip.placeShip((0, 2), LEFT)
        self.assertFalse(self.testShip.isPlacementValid())

        self.testShip.placeShip((10, 2), RIGHT)
        self.assertFalse(self.testShip.isPlacementValid())

        self.testShip.placeShip((5, 5), UP)
        self.assertTrue(self.testShip.isPlacementValid())

        self.testShip.placeShip((0, 0), UP)
        self.assertTrue(self.testShip.isPlacementValid())

        self.testShip.placeShip((9, 0), UP)
        self.assertTrue(self.testShip.isPlacementValid())
开发者ID:kevintandean,项目名称:BattlePy,代码行数:24,代码来源:test_ship.py


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