Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. import random, platform, os
  2.  
  3. def clear():
  4. operating_system = platform.system()
  5.  
  6. if operating_system == "Windows":
  7. os.system('cls')
  8.  
  9. elif operating_system == "Linux":
  10. os.system('clear')
  11.  
  12. else:
  13. ## Something something Idk what to do with OSx
  14. print("\n" * 100)
  15.  
  16. class ship:
  17. def __init__(self, rank, controlled):
  18.  
  19. ## Set the ship type by randomizing one of the ships of that rank
  20. rank = int(rank)
  21. if rank == 0:
  22. rank = random.randint(1, 5)
  23. if rank == 1:
  24. ships = ["Sloop", "Schooner", "Pinnace"]
  25. elif rank == 2:
  26. ships = ["Brig", "Brigantine", "Bargue"]
  27. elif rank == 3:
  28. ships = ["East Indiaman", "Merchantman", "Trade Galleon"]
  29. elif rank == 4:
  30. ships = ["War Galleon", "Frigate"]
  31. else:
  32. ships = ["Man o War", "Ship of the Line"]
  33.  
  34. self.type = ships[random.randint(0, len(ships)-1)]
  35.  
  36.  
  37. ## Stats
  38. ## Cannons, health, manuverability.
  39. ## Cannons deal 2 points of damage per cannonball
  40. ## Manouverability shows the chance to dodge a cannonball.
  41. if rank == 1:
  42. self.cannons = random.randint(10, 20)
  43. self.cannons_max = 20
  44. self.health = random.randint(10, 20) + 15*3
  45. self.health_top = 20 + 15*3
  46. self.cargo_max = random.randint(30, 50)
  47.  
  48. elif rank == 2:
  49. self.cannons = random.randint(14, 24)
  50. self.cannons_max = 24
  51. self.health = random.randint(14, 24) + 19*3
  52. self.health_top = 24 + 19*3
  53. self.cargo_max = random.randint(55, 75)
  54.  
  55. elif rank == 3:
  56. self.cannons = random.randint(20, 30)
  57. self.cannons_max = 30
  58. self.health = random.randint(20, 30) + 25*3
  59. self.health_top = 30 + 25*3
  60. self.cargo_max = random.randint(110, 130)
  61.  
  62. elif rank == 4:
  63. self.cannons = random.randint(27, 37)
  64. self.cannons_max = 37
  65. self.health = random.randint(27, 37) + 32*3
  66. self.health_top = 37 + 32*3
  67. self.cargo_max = random.randint(75, 95)
  68.  
  69. elif rank == 5:
  70. self.cannons = random.randint(38, 48)
  71. self.cannons_max = 48
  72. self.health = random.randint(38, 48) + 43*3
  73. self.health_top = 48 + 43*3
  74. self.cargo_max = random.randint(80, 100)
  75.  
  76. self.health_max = self.health
  77. self.manuv = random.randint(20, 35)
  78. self.manuv_max = 50
  79. self.rank = rank
  80.  
  81.  
  82. ## controllability - if controlled, randomize country and cargo
  83. ## otherwise leave empty
  84. self.rum = 0
  85. self.food = 0
  86. self.money = 0
  87. self.sugar = 0
  88. self.goods = 0
  89.  
  90. if controlled:
  91. empires = ["Dutch", "English", "Spanish", "French", "Pirate"]
  92. self.country = empires[random.randint(0, 4)]
  93. self.food = random.randint(5, 10)
  94. resource_list = [int(round(self.cargo_max*(1/4))), int(round(self.cargo_max*(1/8))), int(round(self.cargo_max*(1/16))), int(round(self.cargo_max*(1/6))), 0, 0]
  95. self.rum = resource_list.pop(random.randint(0,len(resource_list)-1))
  96. self.sugar = resource_list.pop(random.randint(0, len(resource_list)-1))
  97. self.goods = resource_list.pop(random.randint(0, len(resource_list)-1))
  98. self.money = rank * 100 + (random.randint(0, 50)*rank)
  99.  
  100. else:
  101. self.food = 20
  102. self.country = "Pirate"
  103.  
  104. self.cargo = self.rum + self.food + self.sugar + self.goods
  105.  
  106.  
  107.  
  108.  
  109. ## This bit is here to print out the info of the ship whenever required.
  110.  
  111. def info(self, incombat):
  112. print(self.country + " " + self.type + " - Rank " + str(self.rank))
  113. print("Cannons: " + str(self.cannons))
  114. print("Health: [{:20}] {:3}/{:3}".format("=" * int(round((self.health / self.health_max)*20)), str(self.health), str(self.health_max)))
  115. print("Manouvering: " + str(self.manuv) + "%")
  116. if not incombat:
  117. print("\nCargo : " + str(self.cargo) + "/" + str(self.cargo_max))
  118. print("Food : " + str(self.food))
  119. print("Rum : " + str(self.rum))
  120. print("Sugar : " + str(self.sugar))
  121. print("Goods : " + str(self.goods))
  122.  
  123. def info_short(self):
  124. return self.country + " " + self.type
  125.  
  126. ship_group = [ship(0, True), ship(0, True), ship(0, True), ship(0, True), ship(0, True)]
  127. while True:
  128. clear()
  129. for i in range(0, len(ship_group)):
  130. print(str(i+1) + ") " + ship_group[i].info_short())
  131. print()
  132. choice = input("Which ship to inspect>> ")
  133. try:
  134. clear()
  135. ship_group[int(choice)-1].info(False)
  136. input()
  137. except:
  138. input("Invalid input.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement