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


Python Cell.torpedo_hit方法代码示例

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


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

示例1: TestCell

# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import torpedo_hit [as 别名]
class TestCell(unittest.TestCase):

    def setUp(self):
        self.cell_empty = Cell()
        self.cell_string = Cell("something")
        self.cell_ship = Cell(ShipPart(MockShip("Andromeda")))
        self.cell_ship2 = Cell(ShipPart(MockShip("Millenium Falcon")))
        self.cell_torpedo_net = Cell(TorpedoNet())

    def tearDown(self):
        self.cell_empty, self.cell_string = None, None
        self.cell_ship, self.torpedo_net = None, None

    def test_is_empty(self):
        must_be_true(self.cell_empty.is_empty())
        must_be_false(self.cell_string.is_empty())

    def test_is_full(self):
        must_be_false(self.cell_empty.is_full())
        must_be_true(self.cell_string.is_full())

    def test_empty(self):
        self.assertNotEqual(None, self.cell_string.contents)
        self.assertNotEqual(None, self.cell_ship.contents)
        self.cell_string.empty()
        self.cell_ship.empty()
        must_be_equal(None, self.cell_string.contents)
        must_be_equal(None, self.cell_ship.contents)

    def test_contains(self):
        must_be_true(Cell().contains(type(None)))
        must_be_true(Cell("something").contains(type("something")))

    def test_check_for_ship(self):
        must_be_true(self.cell_ship.check_for_ship())
        must_be_false(self.cell_empty.check_for_ship())
        must_be_false(self.cell_torpedo_net.check_for_ship())

    def test_hit(self):
        must_be_equal("miss", self.cell_empty.hit())
        must_be_equal("miss", self.cell_torpedo_net.hit())
        must_be_equal("hit Andromeda", self.cell_ship.hit())

    def test_deploy_anti(self):
        self.cell_empty.deploy_anti("air")
        self.cell_ship.deploy_anti("radar")
        must_be_true(self.cell_empty.defence["air"])
        must_be_false(self.cell_empty.defence["radar"])
        must_be_false(self.cell_ship.defence["air"])
        must_be_true(self.cell_ship.defence["radar"])

    def test_radar_scan(self):
        self.cell_empty.deploy_anti("radar")
        self.cell_ship.deploy_anti("radar")
        must_be_equal("jammed", self.cell_empty.radar_scan())
        must_be_equal("empty", Cell().radar_scan())
        must_be_equal("jammed", self.cell_ship.radar_scan())
        must_be_equal("ship", self.cell_ship2.radar_scan())

    def test_air_strike(self):
        self.cell_empty.deploy_anti("air")
        self.cell_ship.deploy_anti("air")
        must_be_equal("aircraft destroyed", self.cell_empty.air_strike())
        must_be_equal("miss", Cell().air_strike())
        must_be_equal("aircraft destroyed", self.cell_ship.air_strike())
        must_be_equal("hit Millenium Falcon", self.cell_ship2.air_strike())

    def test_torpedo_hit(self):
        must_be_equal("torpedo caught", self.cell_torpedo_net.torpedo_hit())
        must_be_equal("miss", Cell().torpedo_hit())
        must_be_equal("hit Millenium Falcon", self.cell_ship2.torpedo_hit())

    def test_set_torpedo_net(self):
        self.cell_empty.set_torpedo_net()
        must_be_true(self.cell_empty.contains(type(TorpedoNet())))
开发者ID:IliaSky,项目名称:python-battleships,代码行数:77,代码来源:test_cell.py


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