views:

33

answers:

1

Hey Everyone, If you've seen my previous post you'll know im working on an airline program using Python.

Another issue that poped up was that after I launch one flight, it calculates the duration of the flight and replaces the button which is used to launch the flight. But when I buy another aircraft, it changes both flight statuses to the same time (status being duration - arrival time leaving time left until it lands again).

My program is pretty big at this point so ill try and sift through all the other ** that's there:

Here is the page where you click 'Launch Flight'

def Flights (GUI, Player):
...
    for AP in Player.Airplane_list:
        GUI.la(text = AP.aircraft)
        GUI.la(text = 'Flight Pax')
        if AP.status == 0:
            GUI.gr(2)
            GUI.bu(text = 'Launch Flight', command = Callable(Launch_refresh, count, GUI, Player))
            GUI.bu(text = 'Edit Flight', command = Callable(flight_edit, GUI, count, Player))

Launch_refresh basically refreshes the window and goes to launch (below) which calculates all the times and cash. and Self being the Player class which will be below the launch method which is found inside the player class.

def launch (self, Airplane_No): #Method used to calculate flight-time specific-data and set aircraft into flight
    if self.fuel >= (self.Airplane_list[Airplane_No].duration*self.Airplane_list[Airplane_No].fuel_consump):
        self.Airplane_list[Airplane_No].Flight.departure_time = datetime.now()#sets Departure Time to Now
        self.Airplane_list[Airplane_No].Flight.arrival_time = self.Airplane_list[Airplane_No].Flight.departure_time+timedelta(self.Airplane_list[Airplane_No].duration)#Sets arrival Time
        self.Airplane_list[Airplane_No].status = self.Airplane_list[Airplane_No].Flight.arrival_time-datetime.now()#Status to Arrival time minus now
        self.fuel -= (self.Airplane_list[Airplane_No].duration*self.Airplane_list[Airplane_No].fuel_consump)#Subtracts Fuel Used
        self.bank += self.Airplane_list[Airplane_No].Flight.income#Adds Flight Income to Bank

And here is the Player class

class Player (object):#Player Class to define variables
    '''Player class to define variables'''

    def __init__ (self, stock = 0, bank = 1, fuel = 0, total_flights = 0, total_pax = 0, Airplane_list = Airplane([]), APValue_Total = 1):
        ...

Then inside Player.Airplane_list is a list of Airplane Classes which have the Flight Class inside them:

Here is the Airplane Class:

class Airplane (object):    
'''Airplane Class'''

    def __init__ (self, company = '', aircraft = '', base_price = 0, flight_range = 0, pax = 0,
                  fuel_consump = 1, speed = 10, crew_pilots = 0, crew_cabin = 0,
                  crew_mechanics = 0, crew_cleaning = 0, staff_trg = 0, Total_price = 0, status = 0, Flight = Flight(departure_time = datetime(1,1,1),
                  distance = 2000, arrival_time = datetime(1,1,1)),duration = 1, airplane_details = []):

and as you can see it has the Flight class which uses just those 3 arguments (duration needs to use the Airplane's speed along with the Flight distance)

So im guessing that the issue lies inside the launch method, but I dont know exactly where it starts... Then again it looks fine to me :S

+1  A: 

Your __init__ code is defaulting an argument to an object:

class Airplane (object):    
'''Airplane Class'''
    def __init__(self, ..., Flight = Flight(departure_time = datetime(1,1,1), ...):

Default arguments are only evaluated once, when the class is defined, so every Airplane object will get the same Flight, unless it is specified in the constructor arguments. I can't follow all of what you are asking about, but that could contribute to your problem.

Ned Batchelder