Advertisement
Guest User

ships.py

a guest
Jul 26th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. #!/usr/bin/python
  2. # for code details: bsdgames.sourcearchive.com
  3.  
  4. import math
  5.  
  6. class Ship:
  7.     def __init__(self, pos):
  8.         self.pos = [float(i) for i in pos]
  9.  
  10. class Klingon(Ship):
  11.     def __init__(self, pos, hp):
  12.         Ship.__init__(self, pos)
  13.         self.hp = hp
  14.  
  15.     def isalive(self):
  16.         return self.hp > 0
  17.  
  18.     def hit(self, damage):
  19.         self.hp -= damage
  20.  
  21. class Enterprise(Ship):
  22.     max_energy = 5000
  23.  
  24.     def __init__(self, pos):
  25.         self.energy = self.max_energy
  26.         Ship.__init__(self, pos)
  27.  
  28.     def move(self, angle, distance):
  29.         rad = math.radians(angle)
  30.         delta = [math.sin(rad), -math.cos(rad)]
  31.         delta = [round(i*distance, 1) for i in delta]
  32.         self.pos = [self.pos[i] + delta[i] for i in xrange(len(self.pos))]
  33.  
  34.     def refill_energy(self):
  35.         self.energy = self.max_energy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement