Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. def MakePlayerTorpedoMove(Board,Ships):
  2. Row,Column=GetRowColumn()
  3. while Row >= 0 and(Board[Row][Column]=="m" or Board[Row][Column] =="-"):
  4. Board[Row][Column]="m"
  5. Row -=1
  6. if Board[Row][Column]!= 0 and Board[Row][Column]!= "m":
  7. print ("Torpedo hits at ("+str(Column)+","+str(Row)+").")
  8. Board[Row][Column] ="h"
  9. else:
  10. print ("Torpedo failed to hit a ship")
  11. def PlayGame(Board, Ships):
  12. Torpedoes = 20
  13. GameWon = False
  14. TorpedoUsed =False
  15. while not GameWon or Torpedoes>0:
  16. PrintBoard(Board)
  17. if not TorpedoUsed:
  18. TorpedoChosen = input("Fire a torpedo? (Y/N)")
  19. if TorpedoChosen =="Y":
  20. MakePlayerTorpedoMove(Board,Ships)
  21. TorpedoChosen ="N"
  22. TorpedoUSed = True
  23. else:
  24. MakePlayerMove(Board, Ships)
  25. GameWon = CheckWin(Board)
  26. Torpedoes =Torpedoes-1
  27. save= input("Do you want to save the game? ").title()
  28. if save == ("Y"):
  29. Filename = input("Enter a file name: ")
  30. SaveGame(Board, Filename)
  31. print("You have",Torpedoes,"Torpedoes")
  32. if Torpedoes ==0:
  33. print("GAME OVER! You ran out of ammo")
  34. break
  35. if GameWon:
  36. print("All ships sunk!")
  37. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement