Browse Source

Remove the while loop

master
Alireza Savand 1 year ago
parent
commit
b96c7ee702
2 changed files with 7 additions and 11 deletions
  1. 2
    6
      battleship/game.py
  2. 5
    5
      tests/test_battleship_game.py

+ 2
- 6
battleship/game.py View File

@@ -106,11 +106,7 @@ class BattleshipGame:
self.last_column = None
self.player_turn = opponent

def battle(self) -> None:
"""Start the battle."""
logger.debug("Battle started")

while not self.winner:
if not self.winner:
self.continue_game()

@staticmethod
@@ -133,7 +129,7 @@ class BattleshipGame:
player_names.append(player_2_name)

battleship = BattleshipGame(player_names, MessengerInput)
battleship.battle()
battleship.continue_game()


def main(): # pragma: no cover

+ 5
- 5
tests/test_battleship_game.py View File

@@ -67,7 +67,7 @@ class TestBattleshipGame(TestCase):
game.messenger_answer("1")
game.messenger_answer("1")

self.assertEqual(game.messenger.last_echo_messages, ['The hit was a miss!'])
self.assertEqual(game.messenger.last_echo_messages[0:1], ['The hit was a miss!'])
self.assertEqual(game.player_turn, player_amir)
game.messenger.last_echo_messages = []

@@ -90,7 +90,7 @@ class TestBattleshipGame(TestCase):
game.messenger_answer("4")
game.messenger_answer("4")

self.assertEqual(game.messenger.last_echo_messages, ['Battleship sunk at (3, 3)!', ])
self.assertEqual(game.messenger.last_echo_messages[0:1], ['Battleship sunk at (3, 3)!', ])

game.messenger.last_echo_messages = []

@@ -113,7 +113,7 @@ class TestBattleshipGame(TestCase):
game.messenger_answer("4")
game.messenger_answer("4")

self.assertEqual(game.messenger.last_echo_messages, ['Battleship sunk at (3, 3)!', ])
self.assertEqual(game.messenger.last_echo_messages[0:1], ['Battleship sunk at (3, 3)!', ])

game.messenger.last_echo_messages = []
game.continue_game()
@@ -136,7 +136,7 @@ class TestBattleshipGame(TestCase):
game.messenger_answer("4")
game.messenger_answer("4")

self.assertEqual(game.messenger.last_echo_messages, ['The position has been already hit.', ])
self.assertEqual(game.messenger.last_echo_messages[0:1], ['The position has been already hit.', ])

game.messenger.last_echo_messages = []
game.continue_game()
@@ -159,5 +159,5 @@ class TestBattleshipGame(TestCase):
game.messenger_answer("3")
game.messenger_answer("3")

self.assertEqual(game.messenger.last_echo_messages, ['Congratulations! All battleships are sunk!', ])
self.assertEqual(game.messenger.last_echo_messages[0:1], ['Congratulations! All battleships are sunk!', ])
self.assertEqual(game.winner, player_alireza)

Loading…
Cancel
Save