大家好,如果你看过我以前的帖子,你就会知道我正在使用 Python 开发一个航空公司程序。
弹出的另一个问题是,在我启动一个航班后,它会计算航班的持续时间并替换用于启动航班的按钮。但是当我购买另一架飞机时,它会将两个航班状态更改为同一时间(状态为持续时间 - 到达时间离开时间,直到它再次降落)。
我的程序在这一点上相当大,所以我试着筛选所有其他的****:
这是您单击“启动航班”的页面
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 基本上刷新窗口并进入计算所有时间和现金的启动(如下)。和 Self 是 Player 类,它将位于 player 类中的启动方法下方。
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
这是 Player 类
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):
...
然后在 Player.Airplane_list 里面是一个包含 Flight Class 的 Airplane Classes 列表:
这是飞机类:
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 = []):
如您所见,它具有仅使用这 3 个参数的 Flight 类(持续时间需要使用飞机的速度和飞行距离)
所以我猜测问题出在启动方法中,但我不知道它到底从哪里开始......然后它看起来对我来说很好:S