-
Notifications
You must be signed in to change notification settings - Fork 0
/
Battleships.py
33 lines (29 loc) · 957 Bytes
/
Battleships.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from FiringResult import FiringResult
from GameBoard import GameBoard
def main():
board = GameBoard()
board.set_up()
while True:
board.print()
cell_reference = input(
"Enter cell to fire at (e.g. A1, B1, ...) or q to quit: ")
if cell_reference == "q" or cell_reference == "Q":
print("Bye!")
return
(row, column) = GameBoard.translate_cell_reference(cell_reference)
if row == -1:
print("'", cell_reference, "' is not a valid cell.", sep="")
continue
result = board.fire_missile(row, column)
if result == FiringResult.HIT:
print("Hit!")
elif result == FiringResult.MISSED:
print("Missed!")
else:
print("You've already been there!")
if board.game_is_won:
break
board.print()
print("Congratulations, you Won!")
if __name__ == '__main__':
main()