我需要比较每个平面(x,y)点。如果美国飞机的x或y接近1,则turn()
将适用并改为飞机路线。
有关如何比较每个平面并检查它是否靠近的任何想法?
import random
class CrazyPlane:
def __init__(self,x,y):
self.__x = x
self.__y = y
def update_position(self):
self.__x += random.randint(-1,1)
self.__y += random.randint(-1,1)
def get_position(self):
return self.__x,self.__y
def count_down(self):
for i in range(10,0,-1):
print i
def __eq__(self, other):
return self.value == other
def crash_check(planes):
x = 0
y = 1
flag = True
while (flag):
if (__eq__(planes[x], planes[y])):
print " BOOM!"
else:
y = y + 1
if y == 3:
x = x + 1
y = x + 1
if x == 3:
flag = false
return False
###AND!!!!!!!!!!!!!!!!!!!####
def main():
elal = CrazyPlane.CrazyPlane(1,2)
american = CrazyPlane.CrazyPlane(3,4)
british = CrazyPlane.CrazyPlane(5,6)
lufthansa = CrazyPlane.CrazyPlane(7,8)
planes = [elal,american,british,lufthansa]
flag = True
while (flag):
for plane in planes:
plane.update_position()
if crash_check(planes):
flag = False
print 'Crash'
main()