hey there :) got stuck in exercise
made a class of CrazyPlane
now i need to make a infinite loop to get random coordinates for the planes
but if one of the planes is 2 or less coordinates between
i need to make the same plane a turn function to get it away by 1 point
in short i need the planes to not crash :S like a tower control :)
but my problem is i how do i compare between each plane?
do i make a loop?
another function?
any ideas will do
btw my main problem is how do i check if x of american is close to x of every other plane and same for y
if the are close by one than a call for a turn function will come
Thanks
[Image: Ra16HcN.jpg]
made a class of CrazyPlane
now i need to make a infinite loop to get random coordinates for the planes
but if one of the planes is 2 or less coordinates between
i need to make the same plane a turn function to get it away by 1 point
in short i need the planes to not crash :S like a tower control :)
but my problem is i how do i compare between each plane?
do i make a loop?
another function?
any ideas will do
btw my main problem is how do i check if x of american is close to x of every other plane and same for y
if the are close by one than a call for a turn function will come
Thanks
[Image: Ra16HcN.jpg]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
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() |