Skip to content

Instantly share code, notes, and snippets.

@HariSan1
Created October 31, 2018 02:45
Show Gist options
  • Save HariSan1/ee95dd323920952f358f214028bf6f4a to your computer and use it in GitHub Desktop.
Save HariSan1/ee95dd323920952f358f214028bf6f4a to your computer and use it in GitHub Desktop.
#TSB
#simple module to calculate rocket class and move it up, down, left, right on demand
#also calculate distance from this rocket to other rocket
from math import sqrt
class Rocket():
#create and init the class
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def move_rocket(self, dir, x_increment=0, y_increment=0):
if dir == 'up':
self.y += y_increment
elif dir == 'down':
self.y -= y_increment
elif dir == 'left':
self.x -= x_increment
elif dir == 'right':
self.x += x_increment
else:
print("no change")
def get_distance(self, other_rocket):
distance = sqrt((self.x-other_rocket.x)**2+(self.y-other_rocket.y)**2)
return distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment