コード例 #1
0
ファイル: boardstate.py プロジェクト: joncard1/battleship
 def test_shoot_bs_horizontal_miss(self):
     state = boardstate.BoardState()
     self.assertTrue(
         state.place_ship(boardstate.PLAYER_1, boardstate.SHIP_BS, 1, 1,
                          boardstate.OR_RIGHT))
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 5, 1))
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 0, 1))
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 1, 0))
コード例 #2
0
ファイル: boardstate.py プロジェクト: joncard1/battleship
 def test_shoot_twice(self):
     '''
     It should not allow multiple hits to the same spot, but it should not remove the ship until all parts are shot.
     '''
     state = boardstate.BoardState()
     self.assertTrue(
         state.place_ship(boardstate.PLAYER_1, boardstate.SHIP_BS, 1, 1,
                          boardstate.OR_RIGHT))
     self.assertTrue(state.shoot(boardstate.PLAYER_2, 1, 1), "Did not hit")
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 1, 1),
                      "Should not hit twice")
     self.assertTrue(state.shoot(boardstate.PLAYER_2, 2, 1),
                     "Shold have hit the second time")
コード例 #3
0
ファイル: boardstate.py プロジェクト: joncard1/battleship
 def test_shoot_fr(self):
     state = boardstate.BoardState()
     self.assertTrue(
         state.place_ship(boardstate.PLAYER_1, boardstate.SHIP_FR, 1, 1,
                          boardstate.OR_RIGHT))
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 0, 1),
                      "Did not miss left")
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 1, 0),
                      "Did not miss high")
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 1, 2),
                      "Did not miss right")
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 2, 1),
                      "Did not miss low")
     self.assertTrue(state.shoot(boardstate.PLAYER_2, 1, 1), "Did not hit")
     self.assertFalse(state.shoot(boardstate.PLAYER_2, 1, 1),
                      "Did not remove ship")
コード例 #4
0
ファイル: boardstate.py プロジェクト: joncard1/battleship
 def test_add_ship(self):
     state = boardstate.BoardState()
     state.place_ship(boardstate.PLAYER_1, boardstate.SHIP_BS, 1, 1,
                      boardstate.OR_RIGHT)
コード例 #5
0
ファイル: boardstate.py プロジェクト: joncard1/battleship
 def test_shoot_bs_horizontal_rev_hit(self):
     state = boardstate.BoardState()
     self.assertTrue(
         state.place_ship(boardstate.PLAYER_1, boardstate.SHIP_BS, 4, 1,
                          boardstate.OR_LEFT))
     self.assertTrue(state.shoot(boardstate.PLAYER_2, 3, 1))
コード例 #6
0
ファイル: boardstate.py プロジェクト: joncard1/battleship
 def test_shoot_bs_vertical_rev_hit(self):
     state = boardstate.BoardState()
     self.assertTrue(
         state.place_ship(boardstate.PLAYER_1, boardstate.SHIP_BS, 1, 4,
                          boardstate.OR_UP))
     self.assertTrue(state.shoot(boardstate.PLAYER_2, 1, 3))
コード例 #7
0
ファイル: boardstate.py プロジェクト: joncard1/battleship
 def test_shoot_bs_horizontal_hit_2(self):
     state = boardstate.BoardState()
     self.assertTrue(
         state.place_ship(boardstate.PLAYER_1, boardstate.SHIP_BS, 1, 1,
                          boardstate.OR_RIGHT))
     self.assertTrue(state.shoot(boardstate.PLAYER_2, 4, 1))