Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def MakePlayerTorpedoMove(Board,Ships):
- Row,Column=GetRowColumn()
- while Row >= 0 and(Board[Row][Column]=="m" or Board[Row][Column] =="-"):
- Board[Row][Column]="m"
- Row -=1
- if Board[Row][Column]!= 0 and Board[Row][Column]!= "m":
- print ("Torpedo hits at ("+str(Column)+","+str(Row)+").")
- Board[Row][Column] ="h"
- else:
- print ("Torpedo failed to hit a ship")
- def PlayGame(Board, Ships):
- Torpedoes = 20
- GameWon = False
- TorpedoUsed =False
- while not GameWon or Torpedoes>0:
- PrintBoard(Board)
- if not TorpedoUsed:
- TorpedoChosen = input("Fire a torpedo? (Y/N)")
- if TorpedoChosen =="Y":
- MakePlayerTorpedoMove(Board,Ships)
- TorpedoChosen ="N"
- TorpedoUSed = True
- else:
- MakePlayerMove(Board, Ships)
- GameWon = CheckWin(Board)
- Torpedoes =Torpedoes-1
- save= input("Do you want to save the game? ").title()
- if save == ("Y"):
- Filename = input("Enter a file name: ")
- SaveGame(Board, Filename)
- print("You have",Torpedoes,"Torpedoes")
- if Torpedoes ==0:
- print("GAME OVER! You ran out of ammo")
- break
- if GameWon:
- print("All ships sunk!")
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement