Python 2.6:包含层次结构问题:相同的值:S

发布于 2024-09-09 07:05:25 字数 2642 浏览 4 评论 0原文

大家好,如果您看过我之前的文章,您就会知道我正在使用 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 类中的 launch 方法下方。

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 (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 = []):

正如你所看到的,它有 Flight 类,它只使用这 3 个参数(持续时间需要使用飞机的速度和飞行距离)

所以我猜测问题出在发射方法内部,但我不知道它到底从哪里开始...然后对我来说又看起来很好:S

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对不⑦ 2024-09-16 07:05:25

您的 __init__ 代码默认为对象提供一个参数:

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

默认参数仅在定义类时计算一次,因此每个 Airplane 对象都将获得相同的 Flight,除非在构造函数参数中指定。我无法理解您所问的所有内容,但这可能会导致您的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文